Garrit Franke
2 years ago
8 changed files with 322 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||||||
|
# Used by "mix format" |
||||||
|
[ |
||||||
|
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] |
||||||
|
] |
@ -0,0 +1,26 @@ |
|||||||
|
# The directory Mix will write compiled artifacts to. |
||||||
|
/_build/ |
||||||
|
|
||||||
|
# If you run "mix test --cover", coverage assets end up here. |
||||||
|
/cover/ |
||||||
|
|
||||||
|
# The directory Mix downloads your dependencies sources to. |
||||||
|
/deps/ |
||||||
|
|
||||||
|
# Where third-party dependencies like ExDoc output generated docs. |
||||||
|
/doc/ |
||||||
|
|
||||||
|
# Ignore .fetch files in case you like to edit your project deps locally. |
||||||
|
/.fetch |
||||||
|
|
||||||
|
# If the VM crashes, it generates a dump, let's ignore it too. |
||||||
|
erl_crash.dump |
||||||
|
|
||||||
|
# Also ignore archive artifacts (built via "mix archive.build"). |
||||||
|
*.ez |
||||||
|
|
||||||
|
# Ignore package tarball (built via "mix hex.build"). |
||||||
|
day1-*.tar |
||||||
|
|
||||||
|
# Temporary files, for example, from tests. |
||||||
|
/tmp/ |
@ -0,0 +1,21 @@ |
|||||||
|
# Day1 |
||||||
|
|
||||||
|
**TODO: Add description** |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
If [available in Hex](https://hex.pm/docs/publish), the package can be installed |
||||||
|
by adding `day1` to your list of dependencies in `mix.exs`: |
||||||
|
|
||||||
|
```elixir |
||||||
|
def deps do |
||||||
|
[ |
||||||
|
{:day1, "~> 0.1.0"} |
||||||
|
] |
||||||
|
end |
||||||
|
``` |
||||||
|
|
||||||
|
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) |
||||||
|
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can |
||||||
|
be found at [https://hexdocs.pm/day1](https://hexdocs.pm/day1). |
||||||
|
|
@ -0,0 +1,200 @@ |
|||||||
|
1429 |
||||||
|
1368 |
||||||
|
1661 |
||||||
|
1687 |
||||||
|
1593 |
||||||
|
1495 |
||||||
|
1565 |
||||||
|
1500 |
||||||
|
1635 |
||||||
|
1845 |
||||||
|
1645 |
||||||
|
1999 |
||||||
|
1415 |
||||||
|
1054 |
||||||
|
1930 |
||||||
|
1774 |
||||||
|
1405 |
||||||
|
1993 |
||||||
|
1757 |
||||||
|
1623 |
||||||
|
1675 |
||||||
|
1665 |
||||||
|
631 |
||||||
|
1950 |
||||||
|
1702 |
||||||
|
1311 |
||||||
|
1509 |
||||||
|
1790 |
||||||
|
1643 |
||||||
|
1884 |
||||||
|
226 |
||||||
|
1455 |
||||||
|
1679 |
||||||
|
1746 |
||||||
|
1284 |
||||||
|
1342 |
||||||
|
1684 |
||||||
|
1543 |
||||||
|
1396 |
||||||
|
1806 |
||||||
|
1523 |
||||||
|
1363 |
||||||
|
1011 |
||||||
|
1577 |
||||||
|
1767 |
||||||
|
1287 |
||||||
|
1885 |
||||||
|
1517 |
||||||
|
1556 |
||||||
|
1722 |
||||||
|
1260 |
||||||
|
1624 |
||||||
|
1466 |
||||||
|
1263 |
||||||
|
1162 |
||||||
|
1688 |
||||||
|
1202 |
||||||
|
1913 |
||||||
|
1964 |
||||||
|
1385 |
||||||
|
1970 |
||||||
|
1976 |
||||||
|
1431 |
||||||
|
858 |
||||||
|
1748 |
||||||
|
1544 |
||||||
|
1438 |
||||||
|
1300 |
||||||
|
1926 |
||||||
|
1587 |
||||||
|
1376 |
||||||
|
1939 |
||||||
|
1039 |
||||||
|
1639 |
||||||
|
1539 |
||||||
|
1491 |
||||||
|
1631 |
||||||
|
1521 |
||||||
|
1564 |
||||||
|
1507 |
||||||
|
1637 |
||||||
|
1534 |
||||||
|
1713 |
||||||
|
1533 |
||||||
|
1118 |
||||||
|
1356 |
||||||
|
2003 |
||||||
|
282 |
||||||
|
1079 |
||||||
|
1837 |
||||||
|
1259 |
||||||
|
1941 |
||||||
|
1836 |
||||||
|
1903 |
||||||
|
1433 |
||||||
|
1467 |
||||||
|
1027 |
||||||
|
1441 |
||||||
|
1048 |
||||||
|
1742 |
||||||
|
1087 |
||||||
|
1872 |
||||||
|
1476 |
||||||
|
1657 |
||||||
|
1361 |
||||||
|
1182 |
||||||
|
1494 |
||||||
|
1529 |
||||||
|
1822 |
||||||
|
1444 |
||||||
|
1330 |
||||||
|
1514 |
||||||
|
1723 |
||||||
|
1432 |
||||||
|
1683 |
||||||
|
1997 |
||||||
|
1443 |
||||||
|
1474 |
||||||
|
1932 |
||||||
|
1504 |
||||||
|
1313 |
||||||
|
1765 |
||||||
|
19 |
||||||
|
1784 |
||||||
|
1619 |
||||||
|
992 |
||||||
|
1560 |
||||||
|
1680 |
||||||
|
1626 |
||||||
|
1558 |
||||||
|
1899 |
||||||
|
1293 |
||||||
|
1676 |
||||||
|
1161 |
||||||
|
1140 |
||||||
|
1341 |
||||||
|
1597 |
||||||
|
1628 |
||||||
|
1611 |
||||||
|
1302 |
||||||
|
1269 |
||||||
|
1241 |
||||||
|
1952 |
||||||
|
1591 |
||||||
|
1726 |
||||||
|
428 |
||||||
|
1703 |
||||||
|
1289 |
||||||
|
1109 |
||||||
|
1478 |
||||||
|
1002 |
||||||
|
1817 |
||||||
|
1849 |
||||||
|
1838 |
||||||
|
1319 |
||||||
|
1641 |
||||||
|
583 |
||||||
|
1920 |
||||||
|
1453 |
||||||
|
1411 |
||||||
|
1870 |
||||||
|
1763 |
||||||
|
1469 |
||||||
|
1646 |
||||||
|
1719 |
||||||
|
1213 |
||||||
|
1462 |
||||||
|
1545 |
||||||
|
1682 |
||||||
|
1711 |
||||||
|
18 |
||||||
|
2004 |
||||||
|
1252 |
||||||
|
1620 |
||||||
|
1559 |
||||||
|
1315 |
||||||
|
781 |
||||||
|
1656 |
||||||
|
1987 |
||||||
|
1436 |
||||||
|
1630 |
||||||
|
1985 |
||||||
|
1897 |
||||||
|
1551 |
||||||
|
1296 |
||||||
|
1282 |
||||||
|
1735 |
||||||
|
1320 |
||||||
|
1659 |
||||||
|
1271 |
||||||
|
1380 |
||||||
|
1274 |
||||||
|
1876 |
||||||
|
1492 |
||||||
|
1298 |
||||||
|
1399 |
||||||
|
1692 |
||||||
|
1265 |
||||||
|
1555 |
||||||
|
1337 |
@ -0,0 +1,34 @@ |
|||||||
|
# iex()> Day1.load_file |> Day1.first |
||||||
|
|
||||||
|
defmodule Day1 do |
||||||
|
def load_file() do |
||||||
|
File.read!("input.txt") |
||||||
|
|> String.split("\n", trim: true) |
||||||
|
|> Enum.map(fn n -> Integer.parse(n) end) |
||||||
|
|> Enum.map(fn tup -> Kernel.elem(tup, 0) end) |
||||||
|
end |
||||||
|
|
||||||
|
@spec first([Integer]) :: Integer |
||||||
|
def first(input) do |
||||||
|
Enum.reduce(input, 0, fn curr1, res1 -> |
||||||
|
if res1 > 0 and res1 != nil do |
||||||
|
res1 |
||||||
|
else |
||||||
|
Enum.reduce(input, 0, fn curr2, res2 -> |
||||||
|
if res2 > 0 and res2 != nil do |
||||||
|
res2 |
||||||
|
else |
||||||
|
if curr1 + curr2 == 2020 do |
||||||
|
curr1 * curr2 |
||||||
|
end |
||||||
|
end |
||||||
|
end) |
||||||
|
end |
||||||
|
end) |
||||||
|
end |
||||||
|
|
||||||
|
@spec second([Integer]) :: Integer |
||||||
|
def second(input) do |
||||||
|
:second |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,28 @@ |
|||||||
|
defmodule Day1.MixProject do |
||||||
|
use Mix.Project |
||||||
|
|
||||||
|
def project do |
||||||
|
[ |
||||||
|
app: :day1, |
||||||
|
version: "0.1.0", |
||||||
|
elixir: "~> 1.12", |
||||||
|
start_permanent: Mix.env() == :prod, |
||||||
|
deps: deps() |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
# Run "mix help compile.app" to learn about applications. |
||||||
|
def application do |
||||||
|
[ |
||||||
|
extra_applications: [:logger] |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
# Run "mix help deps" to learn about dependencies. |
||||||
|
defp deps do |
||||||
|
[ |
||||||
|
# {:dep_from_hexpm, "~> 0.3.0"}, |
||||||
|
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} |
||||||
|
] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,8 @@ |
|||||||
|
defmodule Day1Test do |
||||||
|
use ExUnit.Case |
||||||
|
doctest Day1 |
||||||
|
|
||||||
|
test "greets the world" do |
||||||
|
assert Day1.hello() == :world |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue