···
import simplifile as file
-
fn solve(input, size) {
-
let get_place = fn(x, y) {
-
s, _ | _, s if s == size -> <<>>
-
_, _ -> bit_array.slice(input, y * size + x, 1) |> result.unwrap(<<>>)
-
list.range(0, bit_array.byte_size(input) - 1)
|> list.fold(0, fn(acc, pos) {
-
let roll = get_place(x, y)
-
get_place(x - 1, y - 1)
-
+ get_place(x + 1, y - 1)
-
+ get_place(x - 1, y + 1)
-
+ get_place(x + 1, y + 1)
case roll, neighbours < 4 {
···
let assert Ok(input) = file.read(from: "../input.txt")
as "Input file not found"
···
let input = input |> list.fold(<<>>, fn(acc, l) { bit_array.append(acc, l) })
···
import simplifile as file
+
fn get_place(x, y, map, size) {
+
s, _ | _, s if s == size -> <<>>
+
_, _ -> bit_array.slice(map, y * size + x, 1) |> result.unwrap(<<>>)
+
list.range(0, bit_array.byte_size(map) - 1)
|> list.fold(0, fn(acc, pos) {
+
let roll = get_place(x, y, map, size)
+
get_place(x - 1, y - 1, map, size)
+
+ get_place(x, y - 1, map, size)
+
+ get_place(x + 1, y - 1, map, size)
+
+ get_place(x - 1, y, map, size)
+
+ get_place(x + 1, y, map, size)
+
+ get_place(x - 1, y + 1, map, size)
+
+ get_place(x, y + 1, map, size)
+
+ get_place(x + 1, y + 1, map, size)
case roll, neighbours < 4 {
···
+
fn part_2(map, size, rolls) {
+
let #(rolls, new_map) =
+
list.range(0, bit_array.byte_size(map) - 1)
+
|> list.fold(#(rolls, <<>>), fn(acc, pos) {
+
let #(total, new_map) = acc
+
let roll = get_place(x, y, map, size)
+
get_place(x - 1, y - 1, map, size)
+
+ get_place(x, y - 1, map, size)
+
+ get_place(x + 1, y - 1, map, size)
+
+ get_place(x - 1, y, map, size)
+
+ get_place(x + 1, y, map, size)
+
+ get_place(x - 1, y + 1, map, size)
+
+ get_place(x, y + 1, map, size)
+
+ get_place(x + 1, y + 1, map, size)
+
case roll, neighbours < 4 {
+
1, True -> #(total + 1, bit_array.append(new_map, <<".">>))
+
0, _ -> #(total, bit_array.append(new_map, <<".">>))
+
1, _ | _, _ -> #(total, bit_array.append(new_map, <<"@">>))
+
False -> part_2(new_map, size, rolls)
let assert Ok(input) = file.read(from: "../input.txt")
as "Input file not found"
···
let input = input |> list.fold(<<>>, fn(acc, l) { bit_array.append(acc, l) })