Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
open Shift;; module Nondet (X : sig end) = struct let p = new_prompt () let fail() = shift p (fun _ -> ()) let flip () = shift p (fun c -> c true; c false; fail ()) let rec choice n = if n < 1 then fail () else if flip() then choice (n-1) else n let iterate generate action = reset p (fun () -> action (generate()); ()) end;; module Gen = Nondet (struct end);; Gen.iterate (fun () -> Gen.choice 5) (fun v -> print_int v);; print_newline();; module Gen0 = Nondet (struct end) module Gen1 = Nondet (struct end) let count0 = new_prompt();; let collect1 = new_prompt();; let rec npick n = if n = 0 then [] else (Gen0.choice 2) :: (npick (n-1));; let pal x = List.rev x = x;; let pal_number n = reset count0 (fun () -> Gen0.iterate (fun () -> npick n) (fun r -> shift count0 (fun k -> (if pal r then 1 else 0) + (k 0))); 0) ;; let pal_count m low high = reset collect1 (fun () -> Gen1.iterate (fun () -> Gen1.choice m) (fun n -> shift collect1 (fun k -> let pn = pal_number n in if low <= pn && pn <= high then (n,pn) :: (k []) else k [] )); []);; let l = pal_count 7 5 60 in List.iter (fun (x,v) -> print_int x; print_string ","; print_int v; print_string "; ";) l; print_newline(); ;; let pal_count m low high = reset collect1 (fun () -> Gen1.iterate (fun () -> Gen1.choice m) (fun n -> shift collect1 (fun k -> let pn = pal_number n in if low <= pn && pn <= high then (n,pn) :: (k []) else k [] )); []);; let l = pal_count 7 5 60 in List.iter (fun (x,v) -> print_int x; print_string ","; print_int v; print_string "; ";) l; print_newline(); ;;