Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

2023-09

2023-09.livemd

2023-09

Mix.install(
  [
    {:benchee, "~> 1.2"},
    {:exla, "~> 0.6.0"},
    {:kino, "~> 0.11.0"},
    {:kino_aoc, "~> 0.1.5"},
    {:nimble_parsec, "~> 1.4"},
    {:nx, "~> 0.6.0"}
  ],
  config: [
    nx: [
      default_backend: EXLA.Backend,
      default_defn_options: [compiler: EXLA]
    ],
    exla: [
      default_client: :host,
      clients: [
        host: [platform: :host],
        cuda: [platform: :cuda]
      ]
    ]
  ],
  system_env: [
    XLA_TARGET: "cuda120"
  ]
)

Nx.global_default_backend(EXLA.Backend)

Problem

{:ok, input} = KinoAOC.download_puzzle("2023", "9", System.fetch_env!("LB_AOC_SESSION"))
{:ok,
 "0 14 45 109 238 493 989 1942 3763 7260 14077 27610 54805 109473 218063 429227 829002 1564034 2875989 5151147 8990168\n15 18 30 59 111 187 296 499 999 2292 5394 12159 25703 50949 95308 169511 288607 473142 750534 1156659 1737663\n5 11 15 33 90 214 428 752 1253 2229 4693 11450 29258 72870 172222 384737 815757 1651623 3212059 6031479 10982866\n11 16 23 24 13 -7 -3 134 674 2194 5828 13721 29926 62289 126510 254929 515555 1053450 2181099 4575420 9702689\n16 31 60 112 215 439 934 1988 4110 8143 15412 27912 48541 81383 132046 208060 319340 478719 702556 1011424 1430883\n12 7 12 54 178 448 938 1712 2791 4113 5527 6958 9104 15500 37718 107235 300798 792410 1957506 4580209 10266638\n17 21 30 48 77 119 191 374 932 2554 6791 16781 38378 81826 164146 312433 568291 993667 1678380 2749678 4384195\n24 37 63 112 194 319 497 738 1052 1449 1939 2532 3238 4067 5029 6134 7392 8813 10407 12184 14154\n11 8 18 52 130 304 693 1530 3221 6416 12092 21648 37012 60760 96247 147750 220623 321464 458294 640748 880278\n22 33 42 54 85 172 386 856 1822 3745 7512 14784 28545 53920 99340 178142 310702 527209 871198 1403970 2210037\n18 20 24 34 54 88 140 214 314 444 608 810 1054 1344 1684 2078 2530 3044 3624 4274 4998\n-8 -10 1 46 151 357 744 1469 2818 5272 9587 16888 28777 47455 75858 117807 178172 263050 379957 538034 748267\n1 6 26 72 171 381 806 1611 3037 5416 9186 14906 23271 35127 51486 73541 102681 140506 188842 249756 325571\n5 20 41 68 101 140 185 236 293 356 425 500 581 668 761 860 965 1076 1193 1316 1445\n20 38 72 140 277 545 1041 1903 3314 5504 8750 13374 19739 28243 39311 53385 70912 92330 118052 148448 183825\n4 7 21 74 220 564 1301 2769 5512 10346 18439 31487 52233 85884 143500 249291 455277 869701 1711690 3417800 6854447\n0 1 9 36 101 231 473 938 1906 4032 8710 18677 38984 78578 153085 290356 542855 1017057 1944000 3845866 7918498\n12 15 30 67 130 208 262 208 -104 -915 -2586 -5631 -10754 -18890 -31250 -49370 -75164 -110981 -159666 -224625 -309894\n2 18 45 83 132 192 263 345 438 542 657 783 920 1068 1227 1397 1578 1770 1973 2187 2412\n10 11 20 47 100 195 375 731 1422 2715 5135 9968 20651 46080 107649 252985 580950 1284615 2721626 5524697 10768850\n-4 -4 9 49 141 337 751 1623 3426 7039 14036 27210 51589 96428 178991 331412 612714 1129686 2074056 3792092 6922209\n5 12 40 97 192 356 683 1398 2974 6351 13364 27575 55854 111344 219060 426682 825747 1593398 3073408 5928841 11418708\n18 36 65 116 222 456 965 2037 4241 8715 17723 35658 70733 137675 261817 485069 874340 1533078 2616693 4352728 7066744\n3 14 33 56 81 125 268 732 2005 5030 11514 24508 49620 97614 189795 368602 717489 1397080 2710069 5218030 9953981\n26 50 97 182 323 552 935 1601 2780 4850 8393 14260 23645 38168 59967 91799 137150 200354 286721 402674 555895\n14 29 73 160 309 548 930 1575 2752 5015 9407 17746 33007 59814 105056 178641 294402 471169 734021 1115732 1658425\n2 2 6 31 105 278 643 1364 2702 5023 8781 14539 23309 38000 67770 138871 318530 762996 1807680 4127011 9005033\n19 20 30 70 181 451 1057 2322 4787 9298 17108 29994 50389 81529 127615 193990 287331 415856 589546 820382 1122597\n17 32 74 157 295 502 792 1179 1677 2300 3062 3977 5059 6322 7780 9447 11337 13464 15842 18485 21407\n3 4 4 4 17 74 232 595 1362 2914 5950 11697 22294 41677 77846 148591 295156 612955 1317215 2877781 6287522\n19 37 64 98 137 179 222 264 303 337 364 382 389 383 362 324 267 189 88 -38 -191\n7 7 26 85 209 438 867 1734 3593 7652 16437 35081 73762 152177 307542 608680 1180815 2249821 4223028 7840205 14459843\n-5 -12 -20 -22 7 125 448 1196 2772 5887 11745 22303 40622 71326 121187 199855 320753 502158 768490 1151832 1693705\n5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45 -50 -55 -60 -65 -70 -75 -80 -85 -90 -95\n-1 6 15 19 10 -3 49 371 1430 4169 10381 23363 49033 97772 187349 347401 626073 1099576 1885595 3161675 5189932\n13 26 42 57 64 60 53 70 173 497 1331 3267 7438 15847 31746 59946 106813 179516 283824 419381 570900\n18 44 94 176 298 479 782 1395 2798 6078 13503 29553 62744 128783 255871 493340 925282 1691416 3018156 5263702 8981990\n13 21 39 94 224 472 881 1507 2474 4102 7152 13269 25811 51524 104128 212091 435133 898089 1858087 3834270 7853652\n1" <> ...}
test_input = """
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45
"""
"0 3 6 9 12 15\n1 3 6 10 15 21\n10 13 16 21 30 45\n"

Parser

defmodule ParseDay9 do
  import NimbleParsec

  ws = ignore(ascii_char([?\s]))
  newline = ignore(ascii_char([?\n]))

  value =
    concat(
      optional(ws),
      ascii_string([?-, ?0..?9], min: 1) |> map({String, :to_integer, []})
    )

  series = times(value, min: 1) |> concat(optional(newline)) |> tag(:series)
  input = times(series, min: 1)

  defparsec(:input, input)
end
{:module, ParseDay9, <<70, 79, 82, 49, 0, 0, 39, ...>>,
 [input__0: 6, input__1: 6, input__1: 6, input__2: 6, input__3: 6, input__4: 6, ...]}
ParseDay9.input("-1 0 1")
{:ok, [series: [-1, 0, 1]], "", %{}, {1, 0}, 6}

Solvers

defmodule Extrapolate do
  import Nx.Defn

  defn not_all_zeros(t) do
    t |> Nx.not_equal(0) |> Nx.any()
  end

  def extrapolate(t) do
    width = Nx.axis_size(t, 0)

    Enum.reduce_while(1..(width - 1), [t], fn depth, batch ->
      diff = Nx.diff(t, order: depth)

      if not_all_zeros(diff) do
        new = Nx.pad(diff, 0, [{depth, 0, 0}])
        {:cont, [new | batch]}
      else
        {:halt, batch}
      end
    end)
    |> Nx.stack(name: :depth)
    |> Nx.sum(axes: [:depth])
    |> Access.get(-1)
  end
end
{:module, Extrapolate, <<70, 79, 82, 49, 0, 0, 13, ...>>, {:extrapolate, 1}}
t = Nx.tensor([-3, -6, -9])
Extrapolate.extrapolate(t)
#Nx.Tensor<
  s64
  EXLA.Backend
  -12
>
defmodule PartOne do
  @doc ~S"""
      iex> parsed = PartOne.parse("0 3 6 9 12 15\n1 3 6 10 15 21")
      ...> Keyword.get_values(parsed, :series)
      [[0,3,6,9,12,15],[1,3,6,10,15,21]]
  """
  def parse(input) do
    {:ok, parsed, "", _context, _line, _col} = ParseDay9.input(input)
    parsed
  end

  def process(input) do
    input
    |> Keyword.get_values(:series)
    |> Stream.map(&amp;Nx.tensor/1)
    |> Enum.map(&amp;Extrapolate.extrapolate/1)
    |> Nx.stack()
    |> Nx.sum()
    |> Nx.to_number()
  end

  def solve(input) do
    input
    |> parse()
    |> process()
  end
end
{:module, PartOne, <<70, 79, 82, 49, 0, 0, 9, ...>>, {:solve, 1}}
defmodule PartTwo do
  import PartOne, only: [parse: 1]

  def process(input) do
    input
    |> Keyword.get_values(:series)
    |> Stream.map(&amp;:lists.reverse/1)
    |> Stream.map(&amp;Nx.tensor/1)
    |> Enum.map(&amp;Extrapolate.extrapolate/1)
    |> Nx.stack()
    |> Nx.sum()
    |> Nx.to_number()
  end

  def solve(input) do
    input
    |> parse()
    |> process()
  end
end
{:module, PartTwo, <<70, 79, 82, 49, 0, 0, 8, ...>>, {:solve, 1}}

Solutions

PartOne.solve(input)
1939607039
PartTwo.solve(input)
1041

Tests

ExUnit.start(auto_run: false, seed: 12345, timeout: 5000)

defmodule PartOneTest do
  use ExUnit.Case, async: true

  doctest PartOne

  describe "Part One" do
    @test_input """
    0 3 6 9 12 15
    1 3 6 10 15 21
    10 13 16 21 30 45
    """
    test "extrapolates and sums next values" do
      assert PartOne.solve(@test_input) == 114
    end
  end
end

defmodule PartTwoTest do
  use ExUnit.Case, async: true

  doctest PartOne

  describe "Part Two" do
    @test_input """
    0 3 6 9 12 15
    1 3 6 10 15 21
    10 13 16 21 30 45
    """
    test "extrapolates and sums previous values" do
      assert PartTwo.solve(@test_input) == 2
    end
  end
end

ExUnit.run()
....
Finished in 0.01 seconds (0.01s async, 0.00s sync)
2 doctests, 2 tests, 0 failures

Randomized with seed 12345
%{total: 4, skipped: 0, failures: 0, excluded: 0}

Golfing

Benchmarks

Benchee.run(
  %{
    "PartOne" => &amp;PartOne.solve/1,
    "PartTwo" => &amp;PartTwo.solve/1
  },
  inputs: %{
    input: input,
    test_input: """
    0 3 6 9 12 15
    1 3 6 10 15 21
    10 13 16 21 30 45
    """
  },
  warmup: 2,
  time: 3,
  memory_time: 3,
  reduction_time: 3
)
Operating System: Linux
CPU Information: AMD Ryzen 9 5950X 16-Core Processor
Number of Available Cores: 32
Available memory: 62.71 GB
Elixir 1.15.7
Erlang 26.1.2

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 3 s
memory time: 3 s
reduction time: 3 s
parallel: 1
inputs: input, test_input
Estimated total run time: 44 s

Benchmarking PartOne with input input ...
Benchmarking PartOne with input test_input ...
Benchmarking PartTwo with input input ...
Benchmarking PartTwo with input test_input ...

##### With input input #####
Name              ips        average  deviation         median         99th %
PartTwo          0.37         2.72 s     ±4.56%         2.72 s         2.81 s
PartOne          0.30         3.28 s     ±0.00%         3.28 s         3.28 s

Comparison: 
PartTwo          0.37
PartOne          0.30 - 1.20x slower +0.56 s

Memory usage statistics:

Name       Memory usage
PartTwo       822.60 MB
PartOne       822.10 MB - 1.00x memory usage -0.49926 MB

**All measurements for memory usage were the same**

Reduction count statistics:

Name            average  deviation         median         99th %
PartTwo         68.73 M     ±0.02%        68.73 M        68.74 M
PartOne         69.21 M     ±0.00%        69.21 M        69.21 M

Comparison: 
PartTwo         68.73 M
PartOne         69.21 M - 1.01x reduction count +0.48 M

##### With input test_input #####
Name              ips        average  deviation         median         99th %
PartTwo        237.69        4.21 ms     ±4.02%        4.16 ms        4.62 ms
PartOne        222.50        4.49 ms     ±4.18%        4.43 ms        4.86 ms

Comparison: 
PartTwo        237.69
PartOne        222.50 - 1.07x slower +0.29 ms

Memory usage statistics:

Name       Memory usage
PartTwo         1.20 MB
PartOne         1.21 MB - 1.01x memory usage +0.0135 MB

**All measurements for memory usage were the same**

Reduction count statistics:

Name            average  deviation         median         99th %
PartTwo        101.74 K     ±0.14%       101.73 K       102.17 K
PartOne        101.98 K     ±0.25%       101.92 K       103.58 K

Comparison: 
PartTwo        101.73 K
PartOne        101.98 K - 1.00x reduction count +0.23 K
%Benchee.Suite{
  system: %{
    erlang: "26.1.2",
    os: :Linux,
    elixir: "1.15.7",
    num_cores: 32,
    cpu_speed: "AMD Ryzen 9 5950X 16-Core Processor",
    available_memory: "62.71 GB"
  },
  configuration: %Benchee.Configuration{
    parallel: 1,
    time: 3000000000.0,
    warmup: 2000000000.0,
    memory_time: 3000000000.0,
    reduction_time: 3000000000.0,
    pre_check: false,
    formatters: [Benchee.Formatters.Console],
    percentiles: ~c"2c",
    print: %{configuration: true, fast_warning: true, benchmarking: true},
    inputs: [
      {"input",
       "0 14 45 109 238 493 989 1942 3763 7260 14077 27610 54805 109473 218063 429227 829002 1564034 2875989 5151147 8990168\n15 18 30 59 111 187 296 499 999 2292 5394 12159 25703 50949 95308 169511 288607 473142 750534 1156659 1737663\n5 11 15 33 90 214 428 752 1253 2229 4693 11450 29258 72870 172222 384737 815757 1651623 3212059 6031479 10982866\n11 16 23 24 13 -7 -3 134 674 2194 5828 13721 29926 62289 126510 254929 515555 1053450 2181099 4575420 9702689\n16 31 60 112 215 439 934 1988 4110 8143 15412 27912 48541 81383 132046 208060 319340 478719 702556 1011424 1430883\n12 7 12 54 178 448 938 1712 2791 4113 5527 6958 9104 15500 37718 107235 300798 792410 1957506 4580209 10266638\n17 21 30 48 77 119 191 374 932 2554 6791 16781 38378 81826 164146 312433 568291 993667 1678380 2749678 4384195\n24 37 63 112 194 319 497 738 1052 1449 1939 2532 3238 4067 5029 6134 7392 8813 10407 12184 14154\n11 8 18 52 130 304 693 1530 3221 6416 12092 21648 37012 60760 96247 147750 220623 321464 458294 640748 880278\n22 33 42 54 85 172 386 856 1822 3745 7512 14784 28545 53920 99340 178142 310702 527209 871198 1403970 2210037\n18 20 24 34 54 88 140 214 314 444 608 810 1054 1344 1684 2078 2530 3044 3624 4274 4998\n-8 -10 1 46 151 357 744 1469 2818 5272 9587 16888 28777 47455 75858 117807 178172 263050 379957 538034 748267\n1 6 26 72 171 381 806 1611 3037 5416 9186 14906 23271 35127 51486 73541 102681 140506 188842 249756 325571\n5 20 41 68 101 140 185 236 293 356 425 500 581 668 761 860 965 1076 1193 1316 1445\n20 38 72 140 277 545 1041 1903 3314 5504 8750 13374 19739 28243 39311 53385 70912 92330 118052 148448 183825\n4 7 21 74 220 564 1301 2769 5512 10346 18439 31487 52233 85884 143500 249291 455277 869701 1711690 3417800 6854447\n0 1 9 36 101 231 473 938 1906 4032 8710 18677 38984 78578 153085 290356 542855 1017057 1944000 3845866 7918498\n12 15 30 67 130 208 262 208 -104 -915 -2586 -5631 -10754 -18890 -31250 -49370 -75164 -110981 -159666 -224625 -309894\n2 18 45 83 132 192 263 345 438 542 657 783 920 1068 1227 1397 1578 1770 1973 2187 2412\n10 11 20 47 100 195 375 731 1422 2715 5135 9968 20651 46080 107649 252985 580950 1284615 2721626 5524697 10768850\n-4 -4 9 49 141 337 751 1623 3426 7039 14036 27210 51589 96428 178991 331412 612714 1129686 2074056 3792092 6922209\n5 12 40 97 192 356 683 1398 2974 6351 13364 27575 55854 111344 219060 426682 825747 1593398 3073408 5928841 11418708\n18 36 65 116 222 456 965 2037 4241 8715 17723 35658 70733 137675 261817 485069 874340 1533078 2616693 4352728 7066744\n3 14 33 56 81 125 268 732 2005 5030 11514 24508 49620 97614 189795 368602 717489 1397080 2710069 5218030 9953981\n26 50 97 182 323 552 935 1601 2780 4850 8393 14260 23645 38168 59967 91799 137150 200354 286721 402674 555895\n14 29 73 160 309 548 930 1575 2752 5015 9407 17746 33007 59814 105056 178641 294402 471169 734021 1115732 1658425\n2 2 6 31 105 278 643 1364 2702 5023 8781 14539 23309 38000 67770 138871 318530 762996 1807680 4127011 9005033\n19 20 30 70 181 451 1057 2322 4787 9298 17108 29994 50389 81529 127615 193990 287331 415856 589546 820382 1122597\n17 32 74 157 295 502 792 1179 1677 2300 3062 3977 5059 6322 7780 9447 11337 13464 15842 18485 21407\n3 4 4 4 17 74 232 595 1362 2914 5950 11697 22294 41677 77846 148591 295156 612955 1317215 2877781 6287522\n19 37 64 98 137 179 222 264 303 337 364 382 389 383 362 324 267 189 88 -38 -191\n7 7 26 85 209 438 867 1734 3593 7652 16437 35081 73762 152177 307542 608680 1180815 2249821 4223028 7840205 14459843\n-5 -12 -20 -22 7 125 448 1196 2772 5887 11745 22303 40622 71326 121187 199855 320753 502158 768490 1151832 1693705\n5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45 -50 -55 -60 -65 -70 -75 -80 -85 -90 -95\n-1 6 15 19 10 -3 49 371 1430 4169 10381 23363 49033 97772 187349 347401 626073 1099576 1885595 3161675 5189932\n13 26 42 57 64 60 53 70 173 497 1331 3267 7438 15847 31746 59946 106813 179516 283824 419381 570900\n18 44 94 176 298 479 782 1395 2798 6078 13503 29553 62744 128783 255871 493340 925282 1691416 3018156 5263702 8981990\n13 21 39 94 224 472 881 1507 2474 4102 7152 13269 25811 51524 104128 212091 435133 898089 1858087 3834270 7853652\n1" <> ...},
      {"test_input", "0 3 6 9 12 15\n1 3 6 10 15 21\n10 13 16 21 30 45\n"}
    ],
    save: false,
    load: false,
    unit_scaling: :best,
    assigns: %{},
    before_each: nil,
    after_each: nil,
    before_scenario: nil,
    after_scenario: nil,
    measure_function_call_overhead: false,
    title: nil,
    profile_after: false
  },
  scenarios: [
    %Benchee.Scenario{
      name: "PartTwo",
      job_name: "PartTwo",
      function: &PartTwo.solve/1,
      input_name: "input",
      input: "0 14 45 109 238 493 989 1942 3763 7260 14077 27610 54805 109473 218063 429227 829002 1564034 2875989 5151147 8990168\n15 18 30 59 111 187 296 499 999 2292 5394 12159 25703 50949 95308 169511 288607 473142 750534 1156659 1737663\n5 11 15 33 90 214 428 752 1253 2229 4693 11450 29258 72870 172222 384737 815757 1651623 3212059 6031479 10982866\n11 16 23 24 13 -7 -3 134 674 2194 5828 13721 29926 62289 126510 254929 515555 1053450 2181099 4575420 9702689\n16 31 60 112 215 439 934 1988 4110 8143 15412 27912 48541 81383 132046 208060 319340 478719 702556 1011424 1430883\n12 7 12 54 178 448 938 1712 2791 4113 5527 6958 9104 15500 37718 107235 300798 792410 1957506 4580209 10266638\n17 21 30 48 77 119 191 374 932 2554 6791 16781 38378 81826 164146 312433 568291 993667 1678380 2749678 4384195\n24 37 63 112 194 319 497 738 1052 1449 1939 2532 3238 4067 5029 6134 7392 8813 10407 12184 14154\n11 8 18 52 130 304 693 1530 3221 6416 12092 21648 37012 60760 96247 147750 220623 321464 458294 640748 880278\n22 33 42 54 85 172 386 856 1822 3745 7512 14784 28545 53920 99340 178142 310702 527209 871198 1403970 2210037\n18 20 24 34 54 88 140 214 314 444 608 810 1054 1344 1684 2078 2530 3044 3624 4274 4998\n-8 -10 1 46 151 357 744 1469 2818 5272 9587 16888 28777 47455 75858 117807 178172 263050 379957 538034 748267\n1 6 26 72 171 381 806 1611 3037 5416 9186 14906 23271 35127 51486 73541 102681 140506 188842 249756 325571\n5 20 41 68 101 140 185 236 293 356 425 500 581 668 761 860 965 1076 1193 1316 1445\n20 38 72 140 277 545 1041 1903 3314 5504 8750 13374 19739 28243 39311 53385 70912 92330 118052 148448 183825\n4 7 21 74 220 564 1301 2769 5512 10346 18439 31487 52233 85884 143500 249291 455277 869701 1711690 3417800 6854447\n0 1 9 36 101 231 473 938 1906 4032 8710 18677 38984 78578 153085 290356 542855 1017057 1944000 3845866 7918498\n12 15 30 67 130 208 262 208 -104 -915 -2586 -5631 -10754 -18890 -31250 -49370 -75164 -110981 -159666 -224625 -309894\n2 18 45 83 132 192 263 345 438 542 657 783 920 1068 1227 1397 1578 1770 1973 2187 2412\n10 11 20 47 100 195 375 731 1422 2715 5135 9968 20651 46080 107649 252985 580950 1284615 2721626 5524697 10768850\n-4 -4 9 49 141 337 751 1623 3426 7039 14036 27210 51589 96428 178991 331412 612714 1129686 2074056 3792092 6922209\n5 12 40 97 192 356 683 1398 2974 6351 13364 27575 55854 111344 219060 426682 825747 1593398 3073408 5928841 11418708\n18 36 65 116 222 456 965 2037 4241 8715 17723 35658 70733 137675 261817 485069 874340 1533078 2616693 4352728 7066744\n3 14 33 56 81 125 268 732 2005 5030 11514 24508 49620 97614 189795 368602 717489 1397080 2710069 5218030 9953981\n26 50 97 182 323 552 935 1601 2780 4850 8393 14260 23645 38168 59967 91799 137150 200354 286721 402674 555895\n14 29 73 160 309 548 930 1575 2752 5015 9407 17746 33007 59814 105056 178641 294402 471169 734021 1115732 1658425\n2 2 6 31 105 278 643 1364 2702 5023 8781 14539 23309 38000 67770 138871 318530 762996 1807680 4127011 9005033\n19 20 30 70 181 451 1057 2322 4787 9298 17108 29994 50389 81529 127615 193990 287331 415856 589546 820382 1122597\n17 32 74 157 295 502 792 1179 1677 2300 3062 3977 5059 6322 7780 9447 11337 13464 15842 18485 21407\n3 4 4 4 17 74 232 595 1362 2914 5950 11697 22294 41677 77846 148591 295156 612955 1317215 2877781 6287522\n19 37 64 98 137 179 222 264 303 337 364 382 389 383 362 324 267 189 88 -38 -191\n7 7 26 85 209 438 867 1734 3593 7652 16437 35081 73762 152177 307542 608680 1180815 2249821 4223028 7840205 14459843\n-5 -12 -20 -22 7 125 448 1196 2772 5887 11745 22303 40622 71326 121187 199855 320753 502158 768490 1151832 1693705\n5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45 -50 -55 -60 -65 -70 -75 -80 -85 -90 -95\n-1 6 15 19 10 -3 49 371 1430 4169 10381 23363 49033 97772 187349 347401 626073 1099576 1885595 3161675 5189932\n13 26 42 57 64 60 53 70 173 497 1331 3267 7438 15847 31746 59946 106813 179516 283824 419381 570900\n18 44 94 176 298 479 782 1395 2798 6078 13503 29553 62744 128783 255871 493340 925282 1691416 3018156 5263702 8981990\n13 21 39 94 224 472 881 1507 2474 4102 7152 13269 25811 51524 104128 212091 435133 898089 1858087 3834270 7853652\n1" <> ...,
      before_each: nil,
      after_each: nil,
      before_scenario: nil,
      after_scenario: nil,
      tag: nil,
      run_time_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 2722326936.5,
          ips: 0.36733280877926616,
          std_dev: 124078312.97102706,
          std_dev_ratio: 0.04557803521224023,
          std_dev_ips: 0.0167423076931525,
          median: 2722326936.5,
          percentiles: %{50 => 2722326936.5, 99 => 2810063553.0},
          mode: nil,
          minimum: 2634590320,
          maximum: 2810063553,
          relative_more: nil,
          relative_less: nil,
          absolute_difference: nil,
          sample_size: 2
        },
        samples: [2810063553, 2634590320]
      },
      memory_usage_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 862558456.0,
          ips: nil,
          std_dev: 0.0,
          std_dev_ratio: 0.0,
          std_dev_ips: nil,
          median: 862558456.0,
          percentiles: %{50 => 862558456.0, 99 => 862558456.0},
          mode: 862558456,
          minimum: 862558456,
          maximum: 862558456,
          relative_more: nil,
          relative_less: nil,
          absolute_difference: nil,
          sample_size: 2
        },
        samples: [862558456, 862558456]
      },
      reductions_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 68732996.0,
          ips: nil,
          std_dev: 12886.313980343642,
          std_dev_ratio: 1.8748366476478985e-4,
          std_dev_ips: nil,
          median: 68732996.0,
          percentiles: %{50 => 68732996.0, 99 => 68742108.0},
          mode: nil,
          minimum: 68723884,
          maximum: 68742108,
          relative_more: nil,
          relative_less: nil,
          absolute_difference: nil,
          sample_size: 2
        },
        samples: [68742108, 68723884]
      }
    },
    %Benchee.Scenario{
      name: "PartOne",
      job_name: "PartOne",
      function: &PartOne.solve/1,
      input_name: "input",
      input: "0 14 45 109 238 493 989 1942 3763 7260 14077 27610 54805 109473 218063 429227 829002 1564034 2875989 5151147 8990168\n15 18 30 59 111 187 296 499 999 2292 5394 12159 25703 50949 95308 169511 288607 473142 750534 1156659 1737663\n5 11 15 33 90 214 428 752 1253 2229 4693 11450 29258 72870 172222 384737 815757 1651623 3212059 6031479 10982866\n11 16 23 24 13 -7 -3 134 674 2194 5828 13721 29926 62289 126510 254929 515555 1053450 2181099 4575420 9702689\n16 31 60 112 215 439 934 1988 4110 8143 15412 27912 48541 81383 132046 208060 319340 478719 702556 1011424 1430883\n12 7 12 54 178 448 938 1712 2791 4113 5527 6958 9104 15500 37718 107235 300798 792410 1957506 4580209 10266638\n17 21 30 48 77 119 191 374 932 2554 6791 16781 38378 81826 164146 312433 568291 993667 1678380 2749678 4384195\n24 37 63 112 194 319 497 738 1052 1449 1939 2532 3238 4067 5029 6134 7392 8813 10407 12184 14154\n11 8 18 52 130 304 693 1530 3221 6416 12092 21648 37012 60760 96247 147750 220623 321464 458294 640748 880278\n22 33 42 54 85 172 386 856 1822 3745 7512 14784 28545 53920 99340 178142 310702 527209 871198 1403970 2210037\n18 20 24 34 54 88 140 214 314 444 608 810 1054 1344 1684 2078 2530 3044 3624 4274 4998\n-8 -10 1 46 151 357 744 1469 2818 5272 9587 16888 28777 47455 75858 117807 178172 263050 379957 538034 748267\n1 6 26 72 171 381 806 1611 3037 5416 9186 14906 23271 35127 51486 73541 102681 140506 188842 249756 325571\n5 20 41 68 101 140 185 236 293 356 425 500 581 668 761 860 965 1076 1193 1316 1445\n20 38 72 140 277 545 1041 1903 3314 5504 8750 13374 19739 28243 39311 53385 70912 92330 118052 148448 183825\n4 7 21 74 220 564 1301 2769 5512 10346 18439 31487 52233 85884 143500 249291 455277 869701 1711690 3417800 6854447\n0 1 9 36 101 231 473 938 1906 4032 8710 18677 38984 78578 153085 290356 542855 1017057 1944000 3845866 7918498\n12 15 30 67 130 208 262 208 -104 -915 -2586 -5631 -10754 -18890 -31250 -49370 -75164 -110981 -159666 -224625 -309894\n2 18 45 83 132 192 263 345 438 542 657 783 920 1068 1227 1397 1578 1770 1973 2187 2412\n10 11 20 47 100 195 375 731 1422 2715 5135 9968 20651 46080 107649 252985 580950 1284615 2721626 5524697 10768850\n-4 -4 9 49 141 337 751 1623 3426 7039 14036 27210 51589 96428 178991 331412 612714 1129686 2074056 3792092 6922209\n5 12 40 97 192 356 683 1398 2974 6351 13364 27575 55854 111344 219060 426682 825747 1593398 3073408 5928841 11418708\n18 36 65 116 222 456 965 2037 4241 8715 17723 35658 70733 137675 261817 485069 874340 1533078 2616693 4352728 7066744\n3 14 33 56 81 125 268 732 2005 5030 11514 24508 49620 97614 189795 368602 717489 1397080 2710069 5218030 9953981\n26 50 97 182 323 552 935 1601 2780 4850 8393 14260 23645 38168 59967 91799 137150 200354 286721 402674 555895\n14 29 73 160 309 548 930 1575 2752 5015 9407 17746 33007 59814 105056 178641 294402 471169 734021 1115732 1658425\n2 2 6 31 105 278 643 1364 2702 5023 8781 14539 23309 38000 67770 138871 318530 762996 1807680 4127011 9005033\n19 20 30 70 181 451 1057 2322 4787 9298 17108 29994 50389 81529 127615 193990 287331 415856 589546 820382 1122597\n17 32 74 157 295 502 792 1179 1677 2300 3062 3977 5059 6322 7780 9447 11337 13464 15842 18485 21407\n3 4 4 4 17 74 232 595 1362 2914 5950 11697 22294 41677 77846 148591 295156 612955 1317215 2877781 6287522\n19 37 64 98 137 179 222 264 303 337 364 382 389 383 362 324 267 189 88 -38 -191\n7 7 26 85 209 438 867 1734 3593 7652 16437 35081 73762 152177 307542 608680 1180815 2249821 4223028 7840205 14459843\n-5 -12 -20 -22 7 125 448 1196 2772 5887 11745 22303 40622 71326 121187 199855 320753 502158 768490 1151832 1693705\n5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45 -50 -55 -60 -65 -70 -75 -80 -85 -90 -95\n-1 6 15 19 10 -3 49 371 1430 4169 10381 23363 49033 97772 187349 347401 626073 1099576 1885595 3161675 5189932\n13 26 42 57 64 60 53 70 173 497 1331 3267 7438 15847 31746 59946 106813 179516 283824 419381 570900\n18 44 94 176 298 479 782 1395 2798 6078 13503 29553 62744 128783 255871 493340 925282 1691416 3018156 5263702 8981990\n13 21 39 94 224 472 881 1507 2474 4102 7152 13269 25811 51524 104128 212091 435133 898089 1858087 3834270 7853652\n1" <> ...,
      before_each: nil,
      after_each: nil,
      before_scenario: nil,
      after_scenario: nil,
      tag: nil,
      run_time_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 3280005723.0,
          ips: 0.3048775168249912,
          std_dev: 0.0,
          std_dev_ratio: 0.0,
          std_dev_ips: 0.0,
          median: 3280005723.0,
          percentiles: %{50 => 3280005723.0, 99 => 3280005723.0},
          mode: nil,
          minimum: 3280005723,
          maximum: 3280005723,
          relative_more: 1.2048537150416576,
          relative_less: 0.8299762763859055,
          absolute_difference: 557678786.5,
          sample_size: 1
        },
        samples: [3280005723]
      },
      memory_usage_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 862034944.0,
          ips: nil,
          std_dev: 0.0,
          std_dev_ratio: 0.0,
          std_dev_ips: nil,
          median: 862034944.0,
          percentiles: %{50 => 862034944.0, 99 => 862034944.0},
          mode: nil,
          minimum: 862034944,
          maximum: 862034944,
          relative_more: 0.9993930706998947,
          relative_less: 1.0006072978869869,
          absolute_difference: -523512.0,
          sample_size: 1
        },
        samples: [862034944]
      },
      reductions_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 69211208.0,
          ips: nil,
          std_dev: 0.0,
          std_dev_ratio: 0.0,
          std_dev_ips: nil,
          median: 69211208.0,
          percentiles: %{50 => 69211208.0, 99 => 69211208.0},
          mode: nil,
          minimum: 69211208,
          maximum: 69211208,
          relative_more: 1.0069575317217367,
          relative_less: 0.9930905410580321,
          absolute_difference: 478212.0,
          sample_size: 1
        },
        samples: [69211208]
      }
    },
    %Benchee.Scenario{
      name: "PartTwo",
      job_name: "PartTwo",
      function: &PartTwo.solve/1,
      input_name: "test_input",
      input: "0 3 6 9 12 15\n1 3 6 10 15 21\n10 13 16 21 30 45\n",
      before_each: nil,
      after_each: nil,
      before_scenario: nil,
      after_scenario: nil,
      tag: nil,
      run_time_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 4207183.093969145,
          ips: 237.68872845906475,
          std_dev: 168954.415035289,
          std_dev_ratio: 0.04015856007728294,
          std_dev_ips: 9.545237081516342,
          median: 4163372.0,
          percentiles: %{50 => 4163372.0, 99 => 4616775.600000001},
          mode: [4069140, 4423614, 4098511, 4102051, 4296354],
          minimum: 3966459,
          maximum: 5916753,
          relative_more: nil,
          relative_less: nil,
          absolute_difference: nil,
          sample_size: 713
        },
        samples: [4318683, 4254193, 4290753, 4245062, 4384054, 4252543, 4257392, 4239503, 4511265,
         4322524, 4398434, 4300643, 4347364, 4405804, 4409265, 4307953, 4398414, 4344834, 4371724,
         4345813, 4527136, 4509906, 4407124, 4392375, 4300222, 4377205, 4369214, 4470015, 4314573,
         4393904, 4307583, ...]
      },
      memory_usage_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 1253144.0,
          ips: nil,
          std_dev: 0.0,
          std_dev_ratio: 0.0,
          std_dev_ips: nil,
          median: 1253144.0,
          percentiles: %{50 => 1253144.0, 99 => 1253144.0},
          mode: 1253144,
          minimum: 1253144,
          maximum: 1253144,
          relative_more: nil,
          relative_less: nil,
          absolute_difference: nil,
          sample_size: 599
        },
        samples: [1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144,
         1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144,
         1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144, 1253144,
         1253144, ...]
      },
      reductions_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 101744.20058565153,
          ips: nil,
          std_dev: 142.00900140693534,
          std_dev_ratio: 0.0013957454143775753,
          std_dev_ips: nil,
          median: 101731.0,
          percentiles: %{50 => 101731.0, 99 => 102167.95999999998},
          mode: 101739,
          minimum: 101687,
          maximum: 103639,
          relative_more: nil,
          relative_less: nil,
          absolute_difference: nil,
          sample_size: 683
        },
        samples: [101843, 101775, 101763, 101831, 101767, 101723, 101743, 101719, 101751, 101699,
         101939, 101715, 101859, 101707, 101739, 101699, 101739, 101723, 101743, 101695, 101899,
         101707, 101751, 101695, 101871, 101827, 101843, 101791, 101847, ...]
      }
    },
    %Benchee.Scenario{
      name: "PartOne",
      job_name: "PartOne",
      function: &PartOne.solve/1,
      input_name: "test_input",
      input: "0 3 6 9 12 15\n1 3 6 10 15 21\n10 13 16 21 30 45\n",
      before_each: nil,
      after_each: nil,
      before_scenario: nil,
      after_scenario: nil,
      tag: nil,
      run_time_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 4494386.72754491,
          ips: 222.49976706972365,
          std_dev: 188074.61012305508,
          std_dev_ratio: 0.04184655694410885,
          std_dev_ips: 9.310849172734144,
          median: 4426789.0,
          percentiles: %{50 => 4426789.0, 99 => 4860335.49},
          mode: [4724578, 4417094, 4457285, 4340064, 4676097, 4700368, 4748738],
          minimum: 4233982,
          maximum: 5953434,
          relative_more: 1.0682650664734468,
          relative_less: 0.9360972584278139,
          absolute_difference: 287203.6335757654,
          sample_size: 668
        },
        samples: [4451475, 4339703, 4381654, 4363523, 4450415, 4416724, 4540866, 4521975, 4453065,
         4749628, 4374994, 4422554, 4291223, 4458985, 4329883, 4522245, 4375384, 4418504, 4476734,
         4399254, 4358984, 4413134, 4469515, 4437574, 4376034, 4393724, 4461945, 4463715, 4512085,
         4455535, ...]
      },
      memory_usage_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 1267248.0,
          ips: nil,
          std_dev: 0.0,
          std_dev_ratio: 0.0,
          std_dev_ips: nil,
          median: 1267248.0,
          percentiles: %{50 => 1267248.0, 99 => 1267248.0},
          mode: 1267248,
          minimum: 1267248,
          maximum: 1267248,
          relative_more: 1.0112548916964053,
          relative_less: 0.9888703710718029,
          absolute_difference: 14104.0,
          sample_size: 543
        },
        samples: [1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248,
         1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248,
         1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248, 1267248,
         ...]
      },
      reductions_data: %Benchee.CollectionData{
        statistics: %Benchee.Statistics{
          average: 101976.59550561798,
          ips: nil,
          std_dev: 250.58976758766389,
          std_dev_ratio: 0.0024573262751633896,
          std_dev_ips: nil,
          median: 101925.0,
          percentiles: %{50 => 101925.0, 99 => 103577.0},
          mode: 101929,
          minimum: 101865,
          maximum: 104337,
          relative_more: 1.0022841097441304,
          relative_less: 0.9977210955237896,
          absolute_difference: 232.39491996644938,
          sample_size: 623
        },
        samples: [101941, 101929, 101905, 101925, 101921, 101953, 101961, 101917, 101989, 101925,
         101877, 101945, 101937, 101917, 101941, 101905, 101953, 101881, 101937, 102009, 101921,
         101953, 101889, 101941, 101973, 101913, 101933, 101901, ...]
      }
    }
  ]
}

Failures

Sometimes my ideas don’t work out.