Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,57 +1,51 @@
Procedure.i deranged(depth,lenn,array d(1),show)
Protected count.l,tmp,i
if (depth = lenn)
if (show)
; for i = 0 to lenn-1:so(chr(d(i) + 'a')):next
for i = 0 to lenn-1:Debug chr(d(i) + 'a'):next
; cw("")
Debug ""
endif
ProcedureReturn 1
endif
Procedure.i deranged(depth, lenn, Array d(1), show)
Protected count, tmp, i
If depth = lenn
If show
For i = 0 To lenn - 1: Print(Chr(d(i) + 'a')): Next
PrintN("")
EndIf
ProcedureReturn 1
EndIf
for i = lenn - 1 to depth step -1
if i = d(depth) :continue:endif
For i = lenn - 1 To depth Step -1
If i = d(depth): Continue: EndIf
tmp = d(i): d(i) = d(depth): d(depth) = tmp
count + deranged(depth + 1, lenn, d(), show)
tmp = d(i): d(i) = d(depth): d(depth) = tmp
next
tmp = d(i): d(i) = d(depth): d(depth) = tmp
count + deranged(depth + 1, lenn, d(), show)
tmp = d(i): d(i) = d(depth): d(depth) = tmp
Next
ProcedureReturn count
ProcedureReturn count
EndProcedure
Procedure.q sub_fact(n)
if n=0:ProcedureReturn 1:endif
if n=1:ProcedureReturn 0:endif
ProcedureReturn (sub_fact(n-1)+sub_fact(n-2))*(n-1)
If n = 0: ProcedureReturn 1: EndIf
If n = 1: ProcedureReturn 0: EndIf
ProcedureReturn (sub_fact(n - 1) + sub_fact(n - 2)) * (n - 1)
EndProcedure
Procedure.i gen_n(n,show)
Protected r.i
global dim a(1024)
for i=0 to n-1:a(i)=i:next
ProcedureReturn deranged(0, n, a(), show)
Procedure.i gen_n(n, show)
Protected r.i
Dim a(1024)
For i = 0 To n - 1: a(i) = i: Next
ProcedureReturn deranged(0, n, a(), show)
EndProcedure
; cw("Deranged Four:")
Debug "Deranged Four:"
gen_n(4, 1)
; cw("")
Debug ""
If OpenConsole()
PrintN("Deranged Four:")
gen_n(4, 1)
; cw("Compare list vs calc:")
Debug "Compare list vs calc:"
for i = 0 to 9
; cw(str(i)+" "+str(gen_n(i, 0))+" "+str(sub_fact(i)))
Debug str(i)+" "+str(gen_n(i, 0))+" "+str(sub_fact(i))
next
; cw("")
Debug ""
PrintN(#CRLF$ + "Compare list vs calc:")
For i = 0 To 9
PrintN(Str(i) + ":" + #TAB$ + Str(gen_n(i, 0)) + #TAB$ + Str(sub_fact(i)))
Next
; cw("further calc:")
Debug "further calc:"
for i = 10 to 20
; cw(str(i)+" "+str(sub_fact(i)))
Debug str(i)+" "+str(sub_fact(i))
next
PrintN(#CRLF$ + "further calc:")
For i = 10 To 20
PrintN(Str(i) + ": " + Str(sub_fact(i)))
Next
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf