Skip to content

Commit 40184fa

Browse files
committed
duh, there's an int.product function
1 parent 7d267a1 commit 40184fa

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

runall.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
fullstart=$(date -u +%s)
4+
for day in $(seq -f "%02g" 1 25); do
5+
finecho=1
6+
start=$(date -u +%s)
7+
dir="src/day${day}"
8+
if [ -d $dir ]; then
9+
printf "Day $day:\n"
10+
gleam run --no-print-progress -m day${day}/solution
11+
printf "\n"
12+
fi
13+
done
14+
fullend=$(date -u +%s)
15+
duration=$((fullend-fullstart))
16+
echo ""
17+
echo "Total time elapsed: ${duration}s"

src/day06/solution.gleam

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn perform_calculation(parts: List(String)) -> Int {
6767

6868
case operation {
6969
["+"] -> int.sum(int_values)
70-
["*"] -> list.fold(int_values, 1, fn(acc, v) { acc * v })
70+
["*"] -> int.product(int_values)
7171
_ -> {
7272
echo parts
7373
panic as "unexpected operation"
@@ -86,8 +86,7 @@ fn accumulate_operation(
8686
case first {
8787
#(n, " ") -> accumulate_operation(rest, sum, [n, ..values])
8888
#(n, "*") -> {
89-
let product = list.fold([n, ..values], 1, fn(p, v) { p * v })
90-
accumulate_operation(rest, sum + product, [])
89+
accumulate_operation(rest, sum + int.product([n, ..values]), [])
9190
}
9291
#(n, "+") ->
9392
accumulate_operation(rest, sum + int.sum([n, ..values]), [])

0 commit comments

Comments
 (0)