23dfcca431 2011-02-23 kinaba: (**************************************************************************** 23dfcca431 2011-02-23 kinaba: * Written in 23dfcca431 2011-02-23 kinaba: * Alice 1.4 23dfcca431 2011-02-23 kinaba: * http://www.ps.uni-saarland.de/alice/ 23dfcca431 2011-02-23 kinaba: ****************************************************************************) 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: fun solve (n : int, k : int) : bool = 23dfcca431 2011-02-23 kinaba: let 23dfcca431 2011-02-23 kinaba: open Word 23dfcca431 2011-02-23 kinaba: infix 5 << andb 23dfcca431 2011-02-23 kinaba: val mask = (0wx1 << fromInt n) - 0wx1 23dfcca431 2011-02-23 kinaba: in 23dfcca431 2011-02-23 kinaba: (fromInt k) andb mask = mask 23dfcca431 2011-02-23 kinaba: end 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: fun main () = 23dfcca431 2011-02-23 kinaba: let 23dfcca431 2011-02-23 kinaba: fun readLine () = 23dfcca431 2011-02-23 kinaba: case TextIO.inputLine TextIO.stdIn of 23dfcca431 2011-02-23 kinaba: | NONE => [] 23dfcca431 2011-02-23 kinaba: | SOME(s) => map Int.fromString (String.tokens (fn x => x = #" ") s) 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: fun parseOne c = 23dfcca431 2011-02-23 kinaba: case readLine() of 23dfcca431 2011-02-23 kinaba: | [SOME n, SOME k] => (c, (n, k)) 23dfcca431 2011-02-23 kinaba: | _ => assert false 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: fun spawn solveOne (c, inp) = 23dfcca431 2011-02-23 kinaba: (c, solve inp) 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: fun printOne (c, ans) = 23dfcca431 2011-02-23 kinaba: print ("Case #" ^ Int.toString (c+1) ^ ": " ^ (if ans then "ON" else "OFF") ^ "\n") 23dfcca431 2011-02-23 kinaba: in 23dfcca431 2011-02-23 kinaba: case readLine () of 23dfcca431 2011-02-23 kinaba: | [SOME t] => List.app printOne (List.map solveOne (List.tabulate (t, parseOne))) 23dfcca431 2011-02-23 kinaba: | _ => assert false 23dfcca431 2011-02-23 kinaba: end 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: do main () 23dfcca431 2011-02-23 kinaba: do OS.Process.exit 0