Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Pascals-triangle/AutoHotkey/pascals-triangle-1.ahk
Normal file
22
Task/Pascals-triangle/AutoHotkey/pascals-triangle-1.ahk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
n := 8, p0 := "1" ; 1+n rows of Pascal's triangle
|
||||
Loop %n% {
|
||||
p := "p" A_Index, %p% := v := 1, q := "p" A_Index-1
|
||||
Loop Parse, %q%, %A_Space%
|
||||
If (A_Index > 1)
|
||||
%p% .= " " v+A_LoopField, v := A_LoopField
|
||||
%p% .= " 1"
|
||||
}
|
||||
; Triangular Formatted output
|
||||
VarSetCapacity(tabs,n,Asc("`t"))
|
||||
t .= tabs "`t1"
|
||||
Loop %n% {
|
||||
t .= "`n" SubStr(tabs,A_Index)
|
||||
Loop Parse, p%A_Index%, %A_Space%
|
||||
t .= A_LoopField "`t`t"
|
||||
}
|
||||
Gui Add, Text,, %t% ; Show result in a GUI
|
||||
Gui Show
|
||||
Return
|
||||
|
||||
GuiClose:
|
||||
ExitApp
|
||||
25
Task/Pascals-triangle/AutoHotkey/pascals-triangle-2.ahk
Normal file
25
Task/Pascals-triangle/AutoHotkey/pascals-triangle-2.ahk
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Msgbox % format(pascalstriangle())
|
||||
Return
|
||||
|
||||
format(o) ; converts object to string
|
||||
{
|
||||
For k, v in o
|
||||
s .= IsObject(v) ? format(v) "`n" : v " "
|
||||
Return s
|
||||
}
|
||||
pascalstriangle(n=7) ; n rows of Pascal's triangle
|
||||
{
|
||||
p := Object(), z:=Object()
|
||||
Loop, % n
|
||||
Loop, % row := A_Index
|
||||
col := A_Index
|
||||
, p[row, col] := row = 1 and col = 1
|
||||
? 1
|
||||
: (p[row-1, col-1] = "" ; math operations on blanks return blanks; I want to assume zero
|
||||
? 0
|
||||
: p[row-1, col-1])
|
||||
+ (p[row-1, col] = ""
|
||||
? 0
|
||||
: p[row-1, col])
|
||||
Return p
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue