tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,57 @@
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
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
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)
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)
EndProcedure
; cw("Deranged Four:")
Debug "Deranged Four:"
gen_n(4, 1)
; cw("")
Debug ""
; 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 ""
; 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