From db2686c798378738020a0951a521358586e21aa0 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 9 Feb 2024 11:42:04 +0100 Subject: Add day2 in OCaml --- 2023/ocaml/day2/_build/.db | Bin 0 -> 1073 bytes 2023/ocaml/day2/_build/.digest-db | Bin 0 -> 1954 bytes 2023/ocaml/day2/_build/.filesystem-clock | 1 + 2023/ocaml/day2/_build/.lock | 1 + 2023/ocaml/day2/_build/default/.dune/configurator | 2 ++ .../day2/_build/default/.dune/configurator.v2 | 1 + .../bin/.main.eobjs/byte/dune__exe__Main.cmi | Bin 0 -> 205 bytes .../bin/.main.eobjs/byte/dune__exe__Main.cmti | Bin 0 -> 2368 bytes .../bin/.main.eobjs/native/dune__exe__Main.cmx | Bin 0 -> 552 bytes .../bin/.main.eobjs/native/dune__exe__Main.o | Bin 0 -> 15200 bytes .../day2/_build/default/bin/.merlin-conf/exe-main | Bin 0 -> 620 bytes 2023/ocaml/day2/_build/default/bin/main.exe | Bin 0 -> 2254592 bytes 2023/ocaml/day2/_build/default/bin/main.ml | 39 +++++++++++++++++++++ 2023/ocaml/day2/_build/default/bin/main.mli | 1 + .../_build/default/lib/.day2.objs/byte/day2.cmi | Bin 0 -> 111 bytes .../_build/default/lib/.day2.objs/byte/day2.cmo | Bin 0 -> 1724 bytes .../_build/default/lib/.day2.objs/byte/day2.cmt | Bin 0 -> 2113 bytes .../_build/default/lib/.day2.objs/native/day2.cmx | Bin 0 -> 95 bytes .../_build/default/lib/.day2.objs/native/day2.o | Bin 0 -> 1608 bytes .../day2/_build/default/lib/.merlin-conf/lib-day2 | Bin 0 -> 564 bytes 2023/ocaml/day2/_build/default/lib/day2.a | Bin 0 -> 1910 bytes 2023/ocaml/day2/_build/default/lib/day2.cmxa | Bin 0 -> 102 bytes 2023/ocaml/day2/_build/default/lib/day2.ml-gen | 1 + 2023/ocaml/day2/_build/install/default/bin/day2 | 1 + 2023/ocaml/day2/_build/log | 23 ++++++++++++ 25 files changed, 70 insertions(+) create mode 100644 2023/ocaml/day2/_build/.db create mode 100644 2023/ocaml/day2/_build/.digest-db create mode 100644 2023/ocaml/day2/_build/.filesystem-clock create mode 100644 2023/ocaml/day2/_build/.lock create mode 100644 2023/ocaml/day2/_build/default/.dune/configurator create mode 100644 2023/ocaml/day2/_build/default/.dune/configurator.v2 create mode 100644 2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmi create mode 100644 2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmti create mode 100644 2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.cmx create mode 100644 2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.o create mode 100644 2023/ocaml/day2/_build/default/bin/.merlin-conf/exe-main create mode 100755 2023/ocaml/day2/_build/default/bin/main.exe create mode 100644 2023/ocaml/day2/_build/default/bin/main.ml create mode 100644 2023/ocaml/day2/_build/default/bin/main.mli create mode 100644 2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmi create mode 100644 2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmo create mode 100644 2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmt create mode 100644 2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.cmx create mode 100644 2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.o create mode 100644 2023/ocaml/day2/_build/default/lib/.merlin-conf/lib-day2 create mode 100644 2023/ocaml/day2/_build/default/lib/day2.a create mode 100644 2023/ocaml/day2/_build/default/lib/day2.cmxa create mode 100644 2023/ocaml/day2/_build/default/lib/day2.ml-gen create mode 120000 2023/ocaml/day2/_build/install/default/bin/day2 create mode 100644 2023/ocaml/day2/_build/log (limited to '2023/ocaml/day2/_build') diff --git a/2023/ocaml/day2/_build/.db b/2023/ocaml/day2/_build/.db new file mode 100644 index 0000000..9629230 Binary files /dev/null and b/2023/ocaml/day2/_build/.db differ diff --git a/2023/ocaml/day2/_build/.digest-db b/2023/ocaml/day2/_build/.digest-db new file mode 100644 index 0000000..0c7bdb2 Binary files /dev/null and b/2023/ocaml/day2/_build/.digest-db differ diff --git a/2023/ocaml/day2/_build/.filesystem-clock b/2023/ocaml/day2/_build/.filesystem-clock new file mode 100644 index 0000000..c61f4a7 --- /dev/null +++ b/2023/ocaml/day2/_build/.filesystem-clock @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/2023/ocaml/day2/_build/.lock b/2023/ocaml/day2/_build/.lock new file mode 100644 index 0000000..5f977d9 --- /dev/null +++ b/2023/ocaml/day2/_build/.lock @@ -0,0 +1 @@ +12823 \ No newline at end of file diff --git a/2023/ocaml/day2/_build/default/.dune/configurator b/2023/ocaml/day2/_build/default/.dune/configurator new file mode 100644 index 0000000..2df6f9a --- /dev/null +++ b/2023/ocaml/day2/_build/default/.dune/configurator @@ -0,0 +1,2 @@ +(ocamlc /home/santo/.opam/default/bin/ocamlc.opt) +(ocaml_config_vars (afl_instrument false) (architecture amd64) (asm as) (asm_cfi_supported true) (ast_impl_magic_number Caml1999M033) (ast_intf_magic_number Caml1999N033) (bytecomp_c_compiler "gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 ") (bytecomp_c_libraries " -lm -lpthread") (c_compiler gcc) (ccomp_type cc) (cma_magic_number Caml1999A033) (cmi_magic_number Caml1999I033) (cmo_magic_number Caml1999O033) (cmt_magic_number Caml1999T033) (cmx_magic_number Caml1999Y033) (cmxa_magic_number Caml1999Z033) (cmxs_magic_number Caml1999D033) (compression_supported false) (default_executable_name a.out) (default_safe_string true) (exec_magic_number Caml1999X033) (ext_asm .s) (ext_dll .so) (ext_exe "") (ext_lib .a) (ext_obj .o) (flambda false) (flat_float_array true) (function_sections true) (host x86_64-pc-linux-gnu) (int_size 63) (linear_magic_number Caml1999L033) (model default) (naked_pointers false) (native_c_compiler "gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 ") (native_c_libraries " -lm -lpthread") (native_compiler true) (native_dynlink true) (native_pack_linker "ld -r -o ") (ocamlc_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC ") (ocamlc_cppflags " -D_FILE_OFFSET_BITS=64 ") (ocamlopt_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC ") (ocamlopt_cppflags " -D_FILE_OFFSET_BITS=64 ") (os_type Unix) (safe_string true) (standard_library /home/santo/.opam/default/lib/ocaml) (standard_library_default /home/santo/.opam/default/lib/ocaml) (supports_shared_libraries true) (system linux) (systhread_supported true) (target x86_64-pc-linux-gnu) (version 5.1.0) (windows_unicode false) (with_frame_pointers false) (word_size 64)) diff --git a/2023/ocaml/day2/_build/default/.dune/configurator.v2 b/2023/ocaml/day2/_build/default/.dune/configurator.v2 new file mode 100644 index 0000000..3edd1f2 --- /dev/null +++ b/2023/ocaml/day2/_build/default/.dune/configurator.v2 @@ -0,0 +1 @@ +((6:ocamlc40:/home/santo/.opam/default/bin/ocamlc.opt)(17:ocaml_config_vars((14:afl_instrument5:false)(12:architecture5:amd64)(3:asm2:as)(17:asm_cfi_supported4:true)(21:ast_impl_magic_number12:Caml1999M033)(21:ast_intf_magic_number12:Caml1999N033)(19:bytecomp_c_compiler77:gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 )(20:bytecomp_c_libraries15: -lm -lpthread)(10:c_compiler3:gcc)(10:ccomp_type2:cc)(16:cma_magic_number12:Caml1999A033)(16:cmi_magic_number12:Caml1999I033)(16:cmo_magic_number12:Caml1999O033)(16:cmt_magic_number12:Caml1999T033)(16:cmx_magic_number12:Caml1999Y033)(17:cmxa_magic_number12:Caml1999Z033)(17:cmxs_magic_number12:Caml1999D033)(21:compression_supported5:false)(23:default_executable_name5:a.out)(19:default_safe_string4:true)(17:exec_magic_number12:Caml1999X033)(7:ext_asm2:.s)(7:ext_dll3:.so)(7:ext_exe0:)(7:ext_lib2:.a)(7:ext_obj2:.o)(7:flambda5:false)(16:flat_float_array4:true)(17:function_sections4:true)(4:host19:x86_64-pc-linux-gnu)(8:int_size2:63)(19:linear_magic_number12:Caml1999L033)(5:model7:default)(14:naked_pointers5:false)(17:native_c_compiler77:gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 )(18:native_c_libraries15: -lm -lpthread)(15:native_compiler4:true)(14:native_dynlink4:true)(18:native_pack_linker9:ld -r -o )(13:ocamlc_cflags48:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC )(15:ocamlc_cppflags24: -D_FILE_OFFSET_BITS=64 )(15:ocamlopt_cflags48:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC )(17:ocamlopt_cppflags24: -D_FILE_OFFSET_BITS=64 )(7:os_type4:Unix)(11:safe_string4:true)(16:standard_library35:/home/santo/.opam/default/lib/ocaml)(24:standard_library_default35:/home/santo/.opam/default/lib/ocaml)(25:supports_shared_libraries4:true)(6:system5:linux)(19:systhread_supported4:true)(6:target19:x86_64-pc-linux-gnu)(7:version5:5.1.0)(15:windows_unicode5:false)(19:with_frame_pointers5:false)(9:word_size2:64)))) \ No newline at end of file diff --git a/2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmi b/2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmi new file mode 100644 index 0000000..1886df9 Binary files /dev/null and b/2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmi differ diff --git a/2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmti b/2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmti new file mode 100644 index 0000000..87d60ff Binary files /dev/null and b/2023/ocaml/day2/_build/default/bin/.main.eobjs/byte/dune__exe__Main.cmti differ diff --git a/2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.cmx b/2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.cmx new file mode 100644 index 0000000..fdc4cf6 Binary files /dev/null and b/2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.cmx differ diff --git a/2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.o b/2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.o new file mode 100644 index 0000000..7bbc169 Binary files /dev/null and b/2023/ocaml/day2/_build/default/bin/.main.eobjs/native/dune__exe__Main.o differ diff --git a/2023/ocaml/day2/_build/default/bin/.merlin-conf/exe-main b/2023/ocaml/day2/_build/default/bin/.merlin-conf/exe-main new file mode 100644 index 0000000..647fe64 Binary files /dev/null and b/2023/ocaml/day2/_build/default/bin/.merlin-conf/exe-main differ diff --git a/2023/ocaml/day2/_build/default/bin/main.exe b/2023/ocaml/day2/_build/default/bin/main.exe new file mode 100755 index 0000000..1b3c926 Binary files /dev/null and b/2023/ocaml/day2/_build/default/bin/main.exe differ diff --git a/2023/ocaml/day2/_build/default/bin/main.ml b/2023/ocaml/day2/_build/default/bin/main.ml new file mode 100644 index 0000000..6dba854 --- /dev/null +++ b/2023/ocaml/day2/_build/default/bin/main.ml @@ -0,0 +1,39 @@ +let input_file = "input.txt" + +let read_file f = + let ic = open_in f in + try + let lines = really_input_string ic (in_channel_length ic) in + let lines = String.trim lines in + close_in ic ; + lines + with e -> + close_in_noerr ic; + raise e + +let rec parse ?(result=0) body = + match body with + | [] -> result + | x :: tail -> + let plays = String.split_on_char ':' x + |> List.rev + |> List.hd + |> String.split_on_char ';' + |> List.map (String.split_on_char ',') + |> List.map (List.map @@ String.trim) + |> List.map (List.map (fun x -> (List.hd (String.split_on_char ' ' x) |> int_of_string, String.get (List.nth (String.split_on_char ' ' x) 1 ) 0))) + in + + + let points = List.map (List.map (fun (p,c) -> if (c = 'r' && p > 12) || (c = 'g' && p > 13) || (c = 'b' && p > 14) then 0 else 1)) plays in + let add = if List.length (List.filter (fun x -> List.length x > 0) @@ List.map (List.filter (fun x -> x = 0)) points) = 0 then + String.split_on_char ':' x |> List.hd |> String.split_on_char ' ' |> List.rev |> List.hd |> int_of_string + else + 0 in + + parse tail ~result:(result+add) + + +let () = + let result = parse (String.split_on_char '\n' (read_file input_file)) in + Printf.printf "%d" result diff --git a/2023/ocaml/day2/_build/default/bin/main.mli b/2023/ocaml/day2/_build/default/bin/main.mli new file mode 100644 index 0000000..335ae1f --- /dev/null +++ b/2023/ocaml/day2/_build/default/bin/main.mli @@ -0,0 +1 @@ +(* Auto-generated by Dune *) \ No newline at end of file diff --git a/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmi b/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmi new file mode 100644 index 0000000..7806bc1 Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmi differ diff --git a/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmo b/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmo new file mode 100644 index 0000000..72a7297 Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmo differ diff --git a/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmt b/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmt new file mode 100644 index 0000000..ead5d30 Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/.day2.objs/byte/day2.cmt differ diff --git a/2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.cmx b/2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.cmx new file mode 100644 index 0000000..23b029c Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.cmx differ diff --git a/2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.o b/2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.o new file mode 100644 index 0000000..59dab7d Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/.day2.objs/native/day2.o differ diff --git a/2023/ocaml/day2/_build/default/lib/.merlin-conf/lib-day2 b/2023/ocaml/day2/_build/default/lib/.merlin-conf/lib-day2 new file mode 100644 index 0000000..df37a97 Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/.merlin-conf/lib-day2 differ diff --git a/2023/ocaml/day2/_build/default/lib/day2.a b/2023/ocaml/day2/_build/default/lib/day2.a new file mode 100644 index 0000000..b7e4559 Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/day2.a differ diff --git a/2023/ocaml/day2/_build/default/lib/day2.cmxa b/2023/ocaml/day2/_build/default/lib/day2.cmxa new file mode 100644 index 0000000..b2af724 Binary files /dev/null and b/2023/ocaml/day2/_build/default/lib/day2.cmxa differ diff --git a/2023/ocaml/day2/_build/default/lib/day2.ml-gen b/2023/ocaml/day2/_build/default/lib/day2.ml-gen new file mode 100644 index 0000000..71d4a7c --- /dev/null +++ b/2023/ocaml/day2/_build/default/lib/day2.ml-gen @@ -0,0 +1 @@ +(* generated by dune *) diff --git a/2023/ocaml/day2/_build/install/default/bin/day2 b/2023/ocaml/day2/_build/install/default/bin/day2 new file mode 120000 index 0000000..9cc466a --- /dev/null +++ b/2023/ocaml/day2/_build/install/default/bin/day2 @@ -0,0 +1 @@ +../../../default/bin/main.exe \ No newline at end of file diff --git a/2023/ocaml/day2/_build/log b/2023/ocaml/day2/_build/log new file mode 100644 index 0000000..142f06e --- /dev/null +++ b/2023/ocaml/day2/_build/log @@ -0,0 +1,23 @@ +# dune exec day2 +# OCAMLPARAM: unset +# Shared cache: disabled +# Shared cache location: /home/santo/.cache/dune/db +# Workspace root: /home/santo/code/aoc/2023/ocaml/day2 +# Auto-detected concurrency: 8 +# Dune context: +# { name = "default" +# ; kind = "default" +# ; profile = Dev +# ; merlin = true +# ; fdo_target_exe = None +# ; build_dir = In_build_dir "default" +# ; installed_env = +# map +# { "INSIDE_DUNE" : +# "/home/santo/code/aoc/2023/ocaml/day2/_build/default" +# ; "OCAML_COLOR" : "always" +# ; "OPAMCOLOR" : "always" +# } +# ; instrument_with = [] +# } +$ /home/santo/.opam/default/bin/ocamlc.opt -config > /tmp/dune_e1b366_output -- cgit v1.2.3-18-g5258