aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-11-01 19:36:57 +0100
committerAbigail <abigail@abigail.be>2021-11-01 19:36:57 +0100
commitdf1b35e96d20b0fbbe887974cafb077b0b1209d9 (patch)
tree5e28475d797cf7d129ad5e71841ddb2234229095
parent289bed506e57873ce957f89ab7c4093bb032e482 (diff)
downloadperlweeklychallenge-club-df1b35e96d20b0fbbe887974cafb077b0b1209d9.tar.gz
perlweeklychallenge-club-df1b35e96d20b0fbbe887974cafb077b0b1209d9.tar.bz2
perlweeklychallenge-club-df1b35e96d20b0fbbe887974cafb077b0b1209d9.zip
Bash solutions for week 137
-rw-r--r--challenge-137/abigail/bash/ch-1.sh35
-rw-r--r--challenge-137/abigail/bash/ch-2.sh39
2 files changed, 74 insertions, 0 deletions
diff --git a/challenge-137/abigail/bash/ch-1.sh b/challenge-137/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..a3b12c9266
--- /dev/null
+++ b/challenge-137/abigail/bash/ch-1.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+start_years=(1600 2000)
+m=${#start_years[@]}
+
+long_year_offsets=( 4 9 15 20 26 32 37 43 48 54 \
+ 60 65 71 76 82 88 93 99 \
+ 105 111 116 122 128 133 139 144 150 \
+ 156 161 167 172 178 184 189 195 \
+ 201 207 212 218 224 229 235 240 246 \
+ 252 257 263 268 274 280 285 291 296 \
+ 303 308 314 320 325 331 336 342 \
+ 348 353 359 364 370 376 381 387 392 398)
+n=${#long_year_offsets[@]}
+
+
+for ((j = 0; j < m; j ++))
+do for ((i = 0; i < n; i ++))
+ do year=$((${start_years[$j]} + ${long_year_offsets[$i]}))
+ if ((1900 <= year && year <= 2100))
+ then echo $year
+ fi
+ done
+done
+
diff --git a/challenge-137/abigail/bash/ch-2.sh b/challenge-137/abigail/bash/ch-2.sh
new file mode 100644
index 0000000000..6776acf025
--- /dev/null
+++ b/challenge-137/abigail/bash/ch-2.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-2.sh < input-file
+#
+
+set -f
+shopt -s extglob
+
+function reverse () {
+ local str=$1
+ local len=${#str}
+ local rev=""
+ for ((i = len - 1; i >= 0; i --))
+ do rev=$rev${str:$i:1}
+ done
+ reverse=$rev
+}
+
+function ly () {
+ local n=$1
+ reverse $n
+ local rev=${reverse/#+(0)/}
+ if ((n >= 10000000))
+ then ly=1
+ elif [[ $n = $rev ]]
+ then ly=0
+ else ly $((n + rev))
+ fi
+}
+
+while read number
+do ly $number
+ echo $ly
+done