Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- functor
- import System Space
- define
- % from CTMCP, p. 773
- fun {Solve Script}
- {SolveStep {Space.new Script} nil} end
- fun {SolveStep S SolTail}
- case {Space.ask S}
- of failed then SolTail
- [] succeeded then {Space.merge S}|SolTail
- [] alternatives(N) then {SolveLoop S 1 N SolTail} end end
- fun lazy {SolveLoop S I N SolTail}
- if I>N then SolTail
- elseif I==N then
- {Space.commit S I}
- {SolveStep S SolTail}
- else
- C={Space.clone S}
- NewTail={SolveLoop S I+1 N SolTail}
- in
- {Space.commit C I}
- {SolveStep C NewTail} end end
- fun {SolveOne F}
- L={Solve F} in
- if L==nil then nil else [L.1] end end
- fun {SolveAll F}
- L={Solve F}
- proc {TouchAll L}
- if L==nil then skip else {TouchAll L.2} end end in
- {TouchAll L}
- L end
- %Exercise starts here:
- fun {Digit}
- choice 0 [] 1 [] 2 [] 3 [] 4 [] 5 [] 6 [] 7 [] 8 [] 9 end
- end
- fun {TwoDigit}
- 10*{Digit}+{Digit}
- end
- {System.show {SolveAll TwoDigit}}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement