Guest User

Untitled

a guest
Sep 24th, 2011
1,034
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let visited = Hashtbl.create 200000
  2.  
  3. let rec walk x y =
  4.     let addDigits number =
  5.         let rec sumInner n soFar =
  6.             match n with
  7.             | x when x<10  -> soFar+x
  8.             | x -> sumInner (n/10) (soFar + n mod 10) in
  9.         sumInner number 0 in
  10.     let rec innerWalk x y totalPoints =
  11.         match Hashtbl.mem visited (x,y) with
  12.         | true -> totalPoints
  13.         | _    -> begin
  14.             Printf.printf "%d,%d\n" x y ;
  15.             Hashtbl.add visited (x,y) 1 ;
  16.             let digitSum = (addDigits x) + (addDigits y) in
  17.             match digitSum with
  18.             | n when n>25 ->
  19.                 totalPoints
  20.             | n -> List.fold_left
  21.                     (fun total (dx,dy) -> total + walk (x+dx) (y+dy))
  22.                     (totalPoints+1)
  23.                     [(1,0);(-1,0);(0,1);(0,-1)]
  24.         end in
  25.     innerWalk x y 0
  26.  
  27. let _ =
  28.     Printf.printf "Points: %d\n" (walk 1000 1000)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×