aboutsummaryrefslogtreecommitdiff
path: root/1
diff options
context:
space:
mode:
authorMichael Hunteman <michael@huntm.net>2023-03-07 10:46:36 -0600
committerMichael Hunteman <michael@huntm.net>2023-03-07 10:46:36 -0600
commit91f4d5b4986095d3a48cdbf32240b902bf5092cc (patch)
treecd128cd3b84b0c514025b10c5b555919b65f48b7 /1
Initial commit
Diffstat (limited to '1')
-rwxr-xr-x149
1 files changed, 49 insertions, 0 deletions
diff --git a/1 b/1
new file mode 100755
index 0000000..514d500
--- /dev/null
+++ b/1
@@ -0,0 +1,49 @@
+#!/bin/sh -eu
+p1() (
+ max=0
+ temp=0
+ while IFS= read -r l
+ do
+ if [ -z $l ]
+ then
+ if [ $temp -gt $max ]
+ then
+ max=$temp
+ fi
+ temp=0
+ else
+ temp=$((temp + l))
+ fi
+ done < input.txt
+ printf "%s\n" "$max"
+)
+
+p2() (
+ set -- 0 0 0
+ temp=0
+ while IFS= read -r l
+ do
+ # TODO: check EOF
+ if [ -z $l ]
+ then
+ if [ $temp -gt $1 ]
+ then
+ shift
+ set -- $@ $temp
+ set -- $(printf "%s\n" "$@" | sort -n)
+ fi
+ temp=0
+ else
+ temp=$((temp + l))
+ fi
+ done < input.txt
+ sum=0
+ for i in $@
+ do
+ sum=$((sum + i))
+ done
+ printf "%s\n" "$sum"
+)
+
+p1
+p2