commit 44f48dd8ab85cfaa7e853cbc90fa15068c1f99ca Author: Glenn Y. Rolland Date: Tue Jul 26 14:21:15 2016 +0200 Initial import. diff --git a/la-descente/Makefile b/la-descente/Makefile new file mode 100644 index 0000000..d250d10 --- /dev/null +++ b/la-descente/Makefile @@ -0,0 +1,3 @@ + +all: + diff --git a/la-descente/_build/_digests b/la-descente/_build/_digests new file mode 100644 index 0000000..f7f253c --- /dev/null +++ b/la-descente/_build/_digests @@ -0,0 +1,5 @@ +"Rule: ocaml dependencies ml (%=code )": "x3\031\165M\251\187\254}\187\176)\176\228\247\134" +"Rule: ocaml: ml -> cmo & cmi (%=code )": "\247\232\255\017\170\234qt4\217g\240\024\245\024?" +"Rule: ocaml: cmx* & o* -> native (%=code )": "w\183Z\014\142\t\160\143\219\138\184\203\165\236\000`" +"Rule: ocaml: ml & cmi -> cmx & o (%=code )": "\168d\189>\196!\180\236j\208:u\244\245\224V" +"Resource: /home/grolland/src/Glenux/codingame/la-descente/code.ml": "\\\235\235\156\158\206\141L\211\026\173\\]\240~K" diff --git a/la-descente/_build/_log b/la-descente/_build/_log new file mode 100644 index 0000000..3a7691d --- /dev/null +++ b/la-descente/_build/_log @@ -0,0 +1,28 @@ +### Starting build. +# Target: code.ml.depends, tags: { bin_annot, debug, extension:ml, file:code.ml, ocaml, ocamldep, package(core), ppx(ppx-jane -as-ppx), quiet, short_paths, thread } +ocamlfind ocamldep -package core -ppx 'ppx-jane -as-ppx' -modules code.ml > code.ml.depends +# Target: code.cmo, tags: { bin_annot, byte, compile, debug, extension:cmo, extension:ml, file:code.cmo, file:code.ml, implem, ocaml, package(core), ppx(ppx-jane -as-ppx), quiet, short_paths, thread } +ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o code.cmo code.ml ++ ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o code.cmo code.ml +File "code.ml", line 12, characters 0-16: +Warning 50: unattached documentation comment (ignored) +File "code.ml", line 28, characters 21-26: +Warning 27: unused variable value. +File "code.ml", line 26, characters 35-39: +Warning 27: unused variable idx1. +File "code.ml", line 26, characters 50-54: +Warning 27: unused variable idx2. +# Target: code.cmx, tags: { bin_annot, compile, debug, extension:cmx, extension:ml, file:code.cmx, file:code.ml, implem, native, ocaml, package(core), ppx(ppx-jane -as-ppx), quiet, short_paths, thread } +ocamlfind ocamlopt -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o code.cmx code.ml ++ ocamlfind ocamlopt -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o code.cmx code.ml +File "code.ml", line 12, characters 0-16: +Warning 50: unattached documentation comment (ignored) +File "code.ml", line 28, characters 21-26: +Warning 27: unused variable value. +File "code.ml", line 26, characters 35-39: +Warning 27: unused variable idx1. +File "code.ml", line 26, characters 50-54: +Warning 27: unused variable idx2. +# Target: code.native, tags: { bin_annot, debug, dont_link_with, extension:native, file:code.native, link, native, ocaml, package(core), ppx(ppx-jane -as-ppx), program, quiet, short_paths, thread } +ocamlfind ocamlopt -linkpkg -g -thread -package core code.cmx -o code.native +# Compilation successful. diff --git a/la-descente/_build/code.cmi b/la-descente/_build/code.cmi new file mode 100644 index 0000000..80faf43 Binary files /dev/null and b/la-descente/_build/code.cmi differ diff --git a/la-descente/_build/code.cmo b/la-descente/_build/code.cmo new file mode 100644 index 0000000..229f72f Binary files /dev/null and b/la-descente/_build/code.cmo differ diff --git a/la-descente/_build/code.cmt b/la-descente/_build/code.cmt new file mode 100644 index 0000000..12ba5cc Binary files /dev/null and b/la-descente/_build/code.cmt differ diff --git a/la-descente/_build/code.cmx b/la-descente/_build/code.cmx new file mode 100644 index 0000000..2e463c7 Binary files /dev/null and b/la-descente/_build/code.cmx differ diff --git a/la-descente/_build/code.ml b/la-descente/_build/code.ml new file mode 100644 index 0000000..1577292 --- /dev/null +++ b/la-descente/_build/code.ml @@ -0,0 +1,38 @@ + +let rec read_mountains n = + let mountainh = int_of_string (input_line stdin) in + if n < 1 then [] + else mountainh :: (read_mountains (n-1)) +;; + + +let c = ref 0 in +prerr_endline "Start" ; + +(** game loop *) +while true do + c := !c + 1 ; + + string_of_int !c + |> fun str -> "tour = " ^ str + |> prerr_endline ; + + let mountains = read_mountains 7 + in + + let target = + mountains + |> List.mapi (fun idx value -> (value, idx)) + |> List.sort (fun (value1, idx1) (value2, idx2) -> Pervasives.compare value1 value2 ) + |> List.hd + |> fun (idx, value) -> idx + in + + let target_str = string_of_int target + in + + prerr_endline ("target = " ^ target_str); + print_endline target_str ; + (); +done; + diff --git a/la-descente/_build/code.ml.depends b/la-descente/_build/code.ml.depends new file mode 100644 index 0000000..9207ad2 --- /dev/null +++ b/la-descente/_build/code.ml.depends @@ -0,0 +1 @@ +code.ml: List Pervasives diff --git a/la-descente/_build/code.native b/la-descente/_build/code.native new file mode 100755 index 0000000..a9400c9 Binary files /dev/null and b/la-descente/_build/code.native differ diff --git a/la-descente/_build/code.o b/la-descente/_build/code.o new file mode 100644 index 0000000..ff57461 Binary files /dev/null and b/la-descente/_build/code.o differ diff --git a/la-descente/_build/ocamlc.where b/la-descente/_build/ocamlc.where new file mode 100644 index 0000000..3840cde --- /dev/null +++ b/la-descente/_build/ocamlc.where @@ -0,0 +1 @@ +/home/grolland/.opam/4.02.3/lib/ocaml diff --git a/la-descente/code.ml b/la-descente/code.ml new file mode 100644 index 0000000..1577292 --- /dev/null +++ b/la-descente/code.ml @@ -0,0 +1,38 @@ + +let rec read_mountains n = + let mountainh = int_of_string (input_line stdin) in + if n < 1 then [] + else mountainh :: (read_mountains (n-1)) +;; + + +let c = ref 0 in +prerr_endline "Start" ; + +(** game loop *) +while true do + c := !c + 1 ; + + string_of_int !c + |> fun str -> "tour = " ^ str + |> prerr_endline ; + + let mountains = read_mountains 7 + in + + let target = + mountains + |> List.mapi (fun idx value -> (value, idx)) + |> List.sort (fun (value1, idx1) (value2, idx2) -> Pervasives.compare value1 value2 ) + |> List.hd + |> fun (idx, value) -> idx + in + + let target_str = string_of_int target + in + + prerr_endline ("target = " ^ target_str); + print_endline target_str ; + (); +done; + diff --git a/la-descente/code.native b/la-descente/code.native new file mode 120000 index 0000000..9874004 --- /dev/null +++ b/la-descente/code.native @@ -0,0 +1 @@ +/home/grolland/src/Glenux/codingame/la-descente/_build/code.native \ No newline at end of file diff --git a/the-bridge/code.ml b/the-bridge/code.ml new file mode 100644 index 0000000..3f92ef1 --- /dev/null +++ b/the-bridge/code.ml @@ -0,0 +1,86 @@ +(* Auto-generated code below aims at helping you parse *) +(* the standard input according to the problem statement. *) + +let open Printf in + +let road = int_of_string (input_line stdin) in (* the length of the road before the gap. *) +let gap = int_of_string (input_line stdin) in (* the length of the gap. *) +let platform = int_of_string (input_line stdin) in (* the length of the landing platform. *) + +(* compute minimum speed value to be able to jump *) +(* la distance dont j'ai encore besoin pour accelerer *) +let rec min_jump_distance_fn speed gap = + if speed <= gap then + (* je devrai accelerer *) + speed + (min_jump_distance_fn (speed + 1) gap) + else + (* pas besoin d'accelerer *) + speed +in + +(* compute maximum speed value to be able to land *) +let rec landing_distance_fn speed = + if speed > 0 then + speed + (landing_distance_fn (speed - 1)) + else + 0 +in + +(* we must increase speed to be able to jump *) +(* we must reduce speed to be able to land *) + +(* game loop *) +while true do + let speed = int_of_string (input_line stdin) in (* the motorbike's speed. *) + let coordx = int_of_string (input_line stdin) in (* the position on the road of the motorbike. *) + + let gap_passed = coordx >= (road + gap) in + + let road_remaining = road - coordx in + let min_jump_distance = min_jump_distance_fn speed gap in + let landing_distance = landing_distance_fn speed in + + fprintf stderr "remaining = %d\n%!" road_remaining ; + fprintf stderr "gap = %d\n%!" gap ; + + fprintf stderr "speed, gap_passed = %d, %B\n%!" speed gap_passed ; + fprintf stderr "r <= mjd = %B\n%!" (road_remaining <= min_jump_distance) ; + + + let must_speed = match (speed, gap_passed) with + | (0, false) -> true + | (_, false) -> road_remaining <= min_jump_distance + | (_, true) -> false + in + let must_slow = match (speed, gap_passed) with + | (_, true) -> true + | (0, false) -> false + | (_, false) -> (landing_distance >= platform) + in + let must_jump = match gap_passed with + | false -> (road_remaining > 0) && (road_remaining < speed) + | true -> false + in + + fprintf stderr "min_jump_dist = %d\n%!" min_jump_distance ; + fprintf stderr "must_speed = %B\n%!" must_speed ; + fprintf stderr "must_slow = %B\n%!" must_slow ; + fprintf stderr "must_jump = %B\n%!" must_jump ; + + let action = match (must_speed, must_slow, must_jump) with + (* we jump when we need to *) + | (_, _, true) -> "JUMP" + (* slow down to be able to land *) + | (_, true, _) -> "SLOW" + (* speed up to be able to jump *) + | (true, _, _) -> "SPEED" + (* otherwise *) + | (_, _, _) -> "WAIT" + in + + (* Write an action using print_endline *) + (* To debug: prerr_endline "Debug message"; *) + print_endline action; + (); +done; +