my solutions to advent of code
aoc advent-of-code

i am an idiot but this still sucks

aylac.top f6340663 ba53422e

verified
Changed files
+16 -18
2015
2
elixir
gleam
+6 -6
2015/2/elixir/main.exs
···
|> Enum.reduce(0, fn v, acc ->
[l, w, h] = v
sides = [l * w, w * h, h * l]
-
smallest = sides |> Enum.reduce(fn a, b -> min(a, b) end)
-
(sides |> Enum.sum()) * 2 + smallest + acc
+
acc + Enum.sum(sides) * 2 + Enum.min(sides)
end)
|> IO.puts()
input
-
|> Enum.reduce(0, fn v, acc ->
-
[l, w, h] = v
+
|> Enum.reduce(0, fn measure, acc ->
+
[l, w, h] = measure
half_perimeter = [l + w, w + h, h + l]
-
smallest_half_perimeter = half_perimeter |> Enum.reduce(fn a, b -> min(a, b) end)
-
l * w * h + smallest_half_perimeter * 2 + acc
+
+
acc + Enum.reduce(measure, fn a, b -> a * b end) +
+
Enum.min(half_perimeter) * 2
end)
|> IO.puts()
end
+10 -12
2015/2/gleam/src/main.gleam
···
// part 1
input
-
|> list.fold(0, fn(prev, cur) {
+
|> list.fold(0, fn(acc, cur) {
let sides =
cur
|> list.combinations(2)
|> list.map(fn(v) { list.fold(v, 1, int.multiply) })
-
prev
-
+ list.fold(sides, 0, fn(prev, cur) { prev + 2 * cur })
+
acc
+
+ { list.fold(sides, 0, int.add) |> int.multiply(2) }
+ { list.reduce(sides, int.min) |> result.unwrap(0) }
})
|> int.to_string
···
// part 2
input
-
|> list.fold(0, fn(prev, cur) {
+
|> list.fold(0, fn(acc, cur) {
let smallest_perimeter =
-
list.reduce(
-
cur
-
|> list.map(fn(v) { v |> int.multiply(2) })
-
|> list.combinations(2)
-
|> list.map(fn(v) { list.fold(v, 0, int.add) }),
-
int.min,
-
)
+
cur
+
|> list.map(fn(v) { v |> int.multiply(2) })
+
|> list.combinations(2)
+
|> list.map(fn(v) { list.fold(v, 0, int.add) })
+
|> list.reduce(int.min)
|> result.unwrap(0)
-
prev + smallest_perimeter + list.fold(cur, 1, int.multiply)
+
acc + smallest_perimeter + list.fold(cur, 1, int.multiply)
})
|> int.to_string
|> io.println