aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruser-person <60802990+user-person@users.noreply.github.com>2020-02-09 02:48:51 -0500
committerGitHub <noreply@github.com>2020-02-09 02:48:51 -0500
commit69fe156b723e6fa2e8e311828eb2b9fe052706ca (patch)
tree2c48a7e873fdde47ce0f2ef642d76c811bf04263
parentb33db2590e7cee71bf44e66f6e3039c8a50d41e4 (diff)
downloadperlweeklychallenge-club-69fe156b723e6fa2e8e311828eb2b9fe052706ca.tar.gz
perlweeklychallenge-club-69fe156b723e6fa2e8e311828eb2b9fe052706ca.tar.bz2
perlweeklychallenge-club-69fe156b723e6fa2e8e311828eb2b9fe052706ca.zip
Create ch-2.bash
-rw-r--r--challenge-046/user-person/bash/ch-2.bash52
1 files changed, 52 insertions, 0 deletions
diff --git a/challenge-046/user-person/bash/ch-2.bash b/challenge-046/user-person/bash/ch-2.bash
new file mode 100644
index 0000000000..c85dcfeb74
--- /dev/null
+++ b/challenge-046/user-person/bash/ch-2.bash
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+###########################################################################
+# script name: ch46-2.bash #
+# #
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-046/ #
+# #
+###########################################################################
+
+declare -a doors
+readonly MAX=500
+returnString=""
+
+function change () {
+ returnString="CLOSED"
+ if [ "$1" == "CLOSED" ] ; then
+ returnString="OPENED"
+ fi
+}
+
+for ((h=1; h <= MAX; h++ ))
+do
+ doors[$h]="CLOSED"
+done
+
+for ((i=1; i <= MAX; i++ ))
+do
+ if [ $i -gt $((MAX / 2)) ]; then
+ change "${doors[$i]}"
+ doors[$i]="$returnString"
+ continue
+ fi
+
+ for ((j=1; j <= MAX; j++ ))
+ do
+ if [ $((j % i)) == 0 ]; then
+ change "${doors[$j]}"
+ doors[$j]="$returnString"
+ fi
+ done
+done
+
+for ((k=1; k <= MAX; k++ ))
+do
+ if [ "${doors[$k]}" == "OPENED" ]; then
+ printf "%s " $k
+ fi
+done
+echo
+
+# ch-2.bash output:
+# 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400 441 484