defmodule Main do def numBlock(width, blocks), do: numBlock(width, Enum.sort(blocks), 0, 0) defp numBlock(width, blocks, total, acc) do if total > width do acc - 1 else case blocks do [head | tail] -> numBlock(width, tail, total + head, acc + 1) _ -> acc end end end def main do inputs = IO.binread(:all) |> String.split [l, _ | ws] = inputs |> Enum.map(&(String.to_integer(&1))) IO.puts numBlock(l, ws) end end