Jump to content

Pascal's triangle: Difference between revisions

+ AutoHotkey contributed by Laszlo from ahk forums
(+ AutoHotkey contributed by Laszlo from ahk forums)
Line 76:
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
=={{header|AutoHotkey}}==
ahk forum: [http://www.autohotkey.com/forum/viewtopic.php?p=276617#276617 discussion]
<lang AutoHotkey>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</lang>
 
=={{header|AWK}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.