Courses/CS 460/Fall 2005/Homework/Sean Tseng
From CSWiki
Contents |
[edit] Oct 1
[edit] Oct 8
[edit] Nov 5
[edit] Nov 12
[edit] Examples from others
local
proc {Delete X Xs XRest}
Head Tail in
Xs = Head | Tail
choice
Head = X
XRest = Tail
[] NewTail in
XRest = Head | NewTail
{Delete X Tail NewTail}
end
end
in
{Browse {SearchAll
proc {$ Ans} Xs Ys in
Ans = Xs#Ys
{Delete Xs [a b c e f g] Ys} end}}
end
local
proc {Nth Xs N R}
H T in
Xs = H|T
choice
N = 1
R = H
[] M in
{Nth T M R }
N= M + 1
end
end
in
{Browse { SearchAll proc { $ Ans} N Xs = [_ _ _] in
Ans = N#Xs
{Nth Xs N a}
end }}
end
local
proc {PermuteK In K ?Out}
choice
((In == nil) orelse (K == 0)) = true
Out = nil
[] X Xr in
(K > 0) = true
{Delete X In Xr}
Out = X | {PermuteK Xr K-1}
end
end
proc {Delete X In ?Out}
H T in
In = H | T
choice
H = X
Out = T
[] NewT in
Out = H | NewT
{Delete X T NewT}
end
end
in
{Browse {SearchAll fun {$} {PermuteK [a b c d] 4} end} } % 24
{Browse {SearchAll fun {$} {PermuteK [a b c d] 3} end} } % 24
{Browse {SearchAll fun {$} {PermuteK [a b c d] 2} end} } % 12
{Browse {SearchAll fun {$} {PermuteK [a b c d] 1} end} } % 4
end

