aboutsummaryrefslogtreecommitdiff
path: root/challenge-138/abigail/bash
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-11-14 13:03:11 +0100
committerAbigail <abigail@abigail.be>2021-11-14 13:03:11 +0100
commitc1db8bac0eaafcc7e7c94d712ce24dc69b776c53 (patch)
tree76f34f10adc27d237e343671818fe451490f0906 /challenge-138/abigail/bash
parent14510de14e1f435b1439c451a2fa5cb9971a7c78 (diff)
downloadperlweeklychallenge-club-c1db8bac0eaafcc7e7c94d712ce24dc69b776c53.tar.gz
perlweeklychallenge-club-c1db8bac0eaafcc7e7c94d712ce24dc69b776c53.tar.bz2
perlweeklychallenge-club-c1db8bac0eaafcc7e7c94d712ce24dc69b776c53.zip
Solutions for week 138 in 14 languages.
Diffstat (limited to 'challenge-138/abigail/bash')
-rw-r--r--challenge-138/abigail/bash/ch-1.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-138/abigail/bash/ch-1.sh b/challenge-138/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..982392620d
--- /dev/null
+++ b/challenge-138/abigail/bash/ch-1.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+SUNDAY=0
+MONDAY=1
+TUESDAY=2
+WEDNESDAY=3
+THURSDAY=4
+FRIDAY=5
+SATURDAY=6
+
+LOOKUP=(261 261 260 260 261 261 261 262 262 261 260 261 262 262)
+DDVALS=($TUESDAY $SUNDAY $FRIDAY $WEDNESDAY)
+
+function doomsday () {
+ local year=$1
+ local anchor=${DDVALS[$(((year / 100) % 4))]}
+ local y=$((year % 100))
+ doomsday=$((((y / 12) + (y % 12) + ((y % 12) / 4) + anchor) % 7))
+}
+
+function is_leap () {
+ local year=$1
+ is_leap=$(((year % 400 == 0) ||
+ (year % 4 == 0) && (year % 100 != 0) ? 1 : 0))
+}
+
+while read year
+do doomsday $year
+ is_leap $year
+ echo ${LOOKUP[$((7 * $is_leap + $doomsday))]}
+done