Initial import.
This commit is contained in:
commit
44f48dd8ab
15 changed files with 201 additions and 0 deletions
3
la-descente/Makefile
Normal file
3
la-descente/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
all:
|
||||
|
5
la-descente/_build/_digests
Normal file
5
la-descente/_build/_digests
Normal file
|
@ -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"
|
28
la-descente/_build/_log
Normal file
28
la-descente/_build/_log
Normal file
|
@ -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.
|
BIN
la-descente/_build/code.cmi
Normal file
BIN
la-descente/_build/code.cmi
Normal file
Binary file not shown.
BIN
la-descente/_build/code.cmo
Normal file
BIN
la-descente/_build/code.cmo
Normal file
Binary file not shown.
BIN
la-descente/_build/code.cmt
Normal file
BIN
la-descente/_build/code.cmt
Normal file
Binary file not shown.
BIN
la-descente/_build/code.cmx
Normal file
BIN
la-descente/_build/code.cmx
Normal file
Binary file not shown.
38
la-descente/_build/code.ml
Normal file
38
la-descente/_build/code.ml
Normal file
|
@ -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;
|
||||
|
1
la-descente/_build/code.ml.depends
Normal file
1
la-descente/_build/code.ml.depends
Normal file
|
@ -0,0 +1 @@
|
|||
code.ml: List Pervasives
|
BIN
la-descente/_build/code.native
Executable file
BIN
la-descente/_build/code.native
Executable file
Binary file not shown.
BIN
la-descente/_build/code.o
Normal file
BIN
la-descente/_build/code.o
Normal file
Binary file not shown.
1
la-descente/_build/ocamlc.where
Normal file
1
la-descente/_build/ocamlc.where
Normal file
|
@ -0,0 +1 @@
|
|||
/home/grolland/.opam/4.02.3/lib/ocaml
|
38
la-descente/code.ml
Normal file
38
la-descente/code.ml
Normal file
|
@ -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;
|
||||
|
1
la-descente/code.native
Symbolic link
1
la-descente/code.native
Symbolic link
|
@ -0,0 +1 @@
|
|||
/home/grolland/src/Glenux/codingame/la-descente/_build/code.native
|
86
the-bridge/code.ml
Normal file
86
the-bridge/code.ml
Normal file
|
@ -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;
|
||||
|
Loading…
Reference in a new issue