Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 1.01 KB | None | 0 0
  1. functor
  2. import System Space
  3. define
  4. % from CTMCP,  p. 773
  5.  
  6. fun {Solve Script}
  7.    {SolveStep {Space.new Script} nil} end
  8.  
  9. fun {SolveStep S SolTail}
  10.    case {Space.ask S}
  11.    of failed then SolTail
  12.    [] succeeded then {Space.merge S}|SolTail
  13.    [] alternatives(N) then {SolveLoop S 1 N SolTail} end end
  14.  
  15. fun lazy {SolveLoop S I N SolTail}
  16.    if I>N then SolTail
  17.    elseif I==N then
  18.       {Space.commit S I}
  19.       {SolveStep S SolTail}
  20.    else
  21.       C={Space.clone S}
  22.       NewTail={SolveLoop S I+1 N SolTail}
  23.    in
  24.       {Space.commit C I}
  25.       {SolveStep C NewTail} end end
  26.  
  27. fun {SolveOne F}
  28.    L={Solve F} in
  29.    if L==nil then nil else [L.1] end end
  30.  
  31. fun {SolveAll F}
  32.    L={Solve F}
  33.    proc {TouchAll L}
  34.       if L==nil then skip else {TouchAll L.2} end end in
  35.    {TouchAll L}
  36.    L end
  37. %Exercise starts here:
  38.  
  39. fun {Digit}
  40.         choice 0 [] 1 [] 2 [] 3 [] 4 [] 5 [] 6 [] 7 [] 8 [] 9 end
  41.     end
  42.     fun {TwoDigit}
  43.         10*{Digit}+{Digit}
  44.     end
  45.     {System.show {SolveAll TwoDigit}}
  46.  
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement