Advertisement
xavierm02

Untitled

Oct 20th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.89 KB | None | 0 0
  1. let id = fun x -> x;;
  2.  
  3. let check_item_against_item = fun pin1 pin2 ->
  4.     true (*( List.fold_left2 ( fun prev i1 i2 -> i1 * i2 + prev ) 0 pin1 pin2 ) == 1*)
  5. ;;
  6.  
  7. let rec check_list_against_item = fun pins pin -> match pins with
  8.     | [ ] -> true
  9.     | head :: tail -> check_item_against_item head pin && check_list_against_item tail pin
  10. ;;
  11.  
  12. let rec check_set = fun pins -> match pins with
  13.     | [ ] -> true
  14.     | head :: tail -> check_list_against_item tail head && check_set tail tail
  15. ;;
  16.  
  17. let rec make_list = fun n f -> match n with
  18.     | 0 -> [ ]
  19.     | _ -> [ f( ) ] @ make_list (n-1) f
  20. ;;
  21.  
  22. let _ =
  23.     let n = Scanf.scanf "%d " id in
  24.     let m = Scanf.scanf "%d " id in
  25.     let pins = make_list n (fun _ ->
  26.         make_list m (fun _ ->
  27.             Scanf.scanf "%c" ( function
  28.                 'o' -> 1
  29.                 | _ -> 0
  30.             )
  31.         )
  32.     ) in
  33.     check_set pins
  34. ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement