aboutsummaryrefslogtreecommitdiff
path: root/challenge-118
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-06-27 20:22:30 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-06-27 20:22:30 +0100
commit287d70fb03bbb2ba51e636cf051775400e94bcb4 (patch)
tree85a39b2a331bbb5b49d17f63ae76796f3999e7ce /challenge-118
parent9beb73e6913f7e462c4aca8719048a7be98e4ad2 (diff)
parent1b3142a75a8db8a886596770514e2d9fa1cd9187 (diff)
downloadperlweeklychallenge-club-287d70fb03bbb2ba51e636cf051775400e94bcb4.tar.gz
perlweeklychallenge-club-287d70fb03bbb2ba51e636cf051775400e94bcb4.tar.bz2
perlweeklychallenge-club-287d70fb03bbb2ba51e636cf051775400e94bcb4.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-118')
-rw-r--r--challenge-118/abigail/README.md106
-rw-r--r--challenge-118/abigail/awk/ch-1.awk36
-rw-r--r--challenge-118/abigail/awk/ch-2.awk14
-rw-r--r--challenge-118/abigail/bash/ch-1.sh32
-rw-r--r--challenge-118/abigail/bash/ch-2.sh11
-rw-r--r--challenge-118/abigail/basic/ch-2.bas9
-rw-r--r--challenge-118/abigail/bc/ch-2.bc10
-rw-r--r--challenge-118/abigail/befunge-93/ch-2.bf932
-rw-r--r--challenge-118/abigail/blog.txt1
-rw-r--r--challenge-118/abigail/blog1.txt1
-rw-r--r--challenge-118/abigail/c/ch-1.c42
-rw-r--r--challenge-118/abigail/c/ch-2.c16
-rw-r--r--challenge-118/abigail/cobol/ch-2.cb14
-rw-r--r--challenge-118/abigail/csh/ch-2.csh11
-rw-r--r--challenge-118/abigail/erlang/ch-2.erl15
-rw-r--r--challenge-118/abigail/forth/ch-2.fs5
-rw-r--r--challenge-118/abigail/fortran/ch-2.f9012
-rw-r--r--challenge-118/abigail/go/ch-1.go41
-rw-r--r--challenge-118/abigail/go/ch-2.go15
-rw-r--r--challenge-118/abigail/java/ch-1.java34
-rw-r--r--challenge-118/abigail/java/ch-2.java13
-rw-r--r--challenge-118/abigail/lua/ch-1.lua32
-rw-r--r--challenge-118/abigail/lua/ch-2.lua11
-rw-r--r--challenge-118/abigail/m4/ch-2.m41
-rw-r--r--challenge-118/abigail/mmix/ch-2.mms16
-rw-r--r--challenge-118/abigail/node/ch-1.js16
-rw-r--r--challenge-118/abigail/node/ch-2.js11
-rw-r--r--challenge-118/abigail/ocaml/ch-2.ml9
-rw-r--r--challenge-118/abigail/pascal/ch-2.p13
-rw-r--r--challenge-118/abigail/perl/ch-1.pl26
-rw-r--r--challenge-118/abigail/perl/ch-2.pl52
-rw-r--r--challenge-118/abigail/perl/ch-2a.pl102
-rw-r--r--challenge-118/abigail/php/ch-2.php11
-rw-r--r--challenge-118/abigail/postscript/ch-2.ps10
-rw-r--r--challenge-118/abigail/python/ch-1.py19
-rw-r--r--challenge-118/abigail/python/ch-2.py11
-rw-r--r--challenge-118/abigail/r/ch-2.r9
-rw-r--r--challenge-118/abigail/rexx/ch-2.rexx9
-rw-r--r--challenge-118/abigail/ruby/ch-1.rb15
-rw-r--r--challenge-118/abigail/ruby/ch-2.rb11
-rw-r--r--challenge-118/abigail/scheme/ch-2.scm9
-rw-r--r--challenge-118/abigail/sed/ch-2.sed12
-rw-r--r--challenge-118/abigail/sql/ch-2.sql9
-rw-r--r--challenge-118/abigail/t/ctest.ini11
-rw-r--r--challenge-118/abigail/t/input-1-12
-rw-r--r--challenge-118/abigail/t/input-2-11
-rw-r--r--challenge-118/abigail/t/output-1-1.exp2
-rw-r--r--challenge-118/abigail/t/output-2-1.exp1
-rw-r--r--challenge-118/abigail/tcl/ch-2.tcl9
-rw-r--r--challenge-118/arne-sommer/blog.txt1
-rw-r--r--challenge-118/arne-sommer/perl/ch-1.pl20
-rw-r--r--challenge-118/arne-sommer/raku/ch-1.raku9
-rw-r--r--challenge-118/arne-sommer/raku/ch-2.raku62
-rw-r--r--challenge-118/athanasius/perl/ch-1.pl128
-rw-r--r--challenge-118/athanasius/raku/ch-1.raku100
-rw-r--r--challenge-118/cheok-yin-fung/awk/ch-1.awk20
-rw-r--r--challenge-118/cheok-yin-fung/blog.txt1
-rw-r--r--challenge-118/cheok-yin-fung/blog1.txt1
-rw-r--r--challenge-118/cheok-yin-fung/perl/ch-1.pl43
-rw-r--r--challenge-118/cheok-yin-fung/perl/ch-2.pl174
-rw-r--r--challenge-118/cheok-yin-fung/perl/pre-ch-2.pl76
-rw-r--r--challenge-118/colin-crain/blog.txt1
-rwxr-xr-xchallenge-118/cristian-heredia/perl/ch-1.pl37
-rwxr-xr-xchallenge-118/cristian-heredia/python/ch-1.py28
-rwxr-xr-xchallenge-118/jo-37/perl/ch-1.pl73
-rwxr-xr-xchallenge-118/jo-37/perl/ch-2.pl158
-rw-r--r--challenge-118/lance-wicks/perl/ch-2.pl29
-rw-r--r--challenge-118/lance-wicks/perl/lib/Knight.pm5
-rw-r--r--challenge-118/mohammad-anwar/blog.txt1
-rw-r--r--challenge-118/pete-houston/perl/ch-1.pl28
-rw-r--r--challenge-118/pete-houston/perl/ch-2.pl260
-rw-r--r--challenge-118/szabgab/README1
-rw-r--r--challenge-118/szabgab/crystal/spec/palindrome_spec.cr15
-rw-r--r--challenge-118/szabgab/crystal/src/palindrome.cr5
-rw-r--r--challenge-118/szabgab/crystal/src/use_palindrome.cr10
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/README.md14
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/bb.edn11
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/deps.edn7
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/pom.xml13
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/resources/input.txt8
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/core.clj12
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t1.clj26
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/src/tw/weekly/c118/t2.clj111
-rw-r--r--challenge-118/tyler-wardhaugh/clojure/test/tw/weekly/c118_test.clj16
-rw-r--r--challenge-118/wambash/raku/ch-1.raku21
-rw-r--r--challenge-118/wanderdoc/perl/ch-1.pl24
86 files changed, 2351 insertions, 78 deletions
diff --git a/challenge-118/abigail/README.md b/challenge-118/abigail/README.md
index 7db94b7f39..ba9aad7a0c 100644
--- a/challenge-118/abigail/README.md
+++ b/challenge-118/abigail/README.md
@@ -1,27 +1,20 @@
# Solutions by Abigail
-## [Missing Row](https://perlweeklychallenge.org/blog/perl-weekly-challenge-117/#TASK1)
+## [Binary Palindrome](https://perlweeklychallenge.org/blog/perl-weekly-challenge-118/#TASK1)
-> You are given text file with rows numbered `1-15` in random order but
-> there is a catch one row in missing in the file.
+> You are given a positive integer $N.
+>
+> Write a script to find out if the binary representation of the given
+> integer is Palindrome. Print 1 if it is otherwise 0.
+>
+### Examples
~~~~
-11, Line Eleven
-1, Line one
-9, Line Nine
-13, Line Thirteen
-2, Line two
-6, Line Six
-8, Line Eight
-10, Line Ten
-7, Line Seven
-4, Line Four
-14, Line Fourteen
-3, Line three
-15, Line Fifteen
-5, Line Five
-~~~~
+Input: $N = 5
+Output: 1 as binary representation of 5 is 101 which is Palindrome.
-Write a script to find the missing row number.
+Input: $N = 4
+Output: 0 as binary representation of 4 is 100 which is NOT Palindrome.
+~~~~
### Solutions
* [AWK](awk/ch-1.awk)
@@ -36,54 +29,65 @@ Write a script to find the missing row number.
* [Ruby](ruby/ch-1.rb)
### Blog
-[Missing Row](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-117-1.html)
+[Binary Palindrome](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-118-1.html)
-## [Find Possible Paths](https://perlweeklychallenge.org/blog/perl-weekly-challenge-115/#TASK2)
+## [Adventure of Knight](https://perlweeklychallenge.org/blog/perl-weekly-challenge-118/#TASK2)
-> You are given size of a triangle.
->
-> Write a script to find all possible paths from top to the bottom
-> right corner.
->
-> In each step, we can either move horizontally to the right (`H`), or
-> move downwards to the left (`L`) or right (`R`).
+> A knight is restricted to move on an 8x8 chessboard. The knight is denoted
+> by `N` and its way of movement is the same as what it is defined in Chess.
+> `*` represents an empty square. `x` represents a square with treasure.
+>
+> > The Knight's movement is unique. It may move two squares vertically and
+> > one square horizontally, or two squares horizontally and one square
+> > vertically (with both forming the shape of an L).
+>
+> There are 6 squares with treasures.
+>
+> Write a script to find the path such that Knight can capture all
+> treasures. The Knight can start from the top-left square.
>
-> BONUS: Try if it can handle triangle of size `10` or `20`.
-
-### Examples
-~~~~
-Input: $N = 2
-
- S
- / \
- / _ \
- /\ /\
- /__\ /__\ E
-
-Output: RR, LHR, LHLH, LLHH, RLH, LRH
-~~~~
-
~~~~
-Input: $N = 1
-
- S
- / \
- / _ \ E
-
-Output: R, LH
+ a b c d e f g h
+ 8 N * * * * * * * 8
+ 7 * * * * * * * * 7
+ 6 * * * * x * * * 6
+ 5 * * * * * * * * 5
+ 4 * * x * * * * * 4
+ 3 * x * * * * * * 3
+ 2 x x * * * * * * 2
+ 1 * x * * * * * * 1
+ a b c d e f g h
~~~~
### Solutions
* [AWK](awk/ch-2.awk)
* [Bash](bash/ch-2.sh)
+* [Basic](basic/ch-2.bas)
+* [bc](bc/ch-2.bc)
+* [Befunge-93](befunge-93/ch-2.bf93)
* [C](c/ch-2.c)
+* [Cobol](cobol/ch-2.cb)
+* [Csh](csh/ch-2.csh)
+* [Erlang](erlang/ch-2.erl]
+* [Forth](forth/ch-2.fs]
+* [Fortran](fortran/ch-2.f90]
* [Go](go/ch-2.go)
* [Java](java/ch-1.java)
* [Lua](lua/ch-2.lua)
+* [m4](m4/ch-2.m4]
* [Node.js](node/ch-2.js)
+* [OCaml](ocaml/ch-2.ml]
+* [Pascal](pascal/ch-2.p]
* [Perl](perl/ch-2.pl)
+* [PHP](php/ch-2.php]
+* [PostScript](postscript/ch-2.ps]
* [Python](python/ch-2.py)
+* [R](r/ch-2.r]
+* [Rexx](rexx/ch-2.rexx]
* [Ruby](ruby/ch-2.rb)
+* [Scheme](scheme/ch-2.scm]
+* [sed](sed/ch-2.sed]
+* [Tcl](tcl/ch-2.tcl]
### Blog
-[Find Possible Paths](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-117-2.html)
+[Adventure of Knight](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-118-2.html)
diff --git a/challenge-118/abigail/awk/ch-1.awk b/challenge-118/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..490a5ceefc
--- /dev/null
+++ b/challenge-118/abigail/awk/ch-1.awk
@@ -0,0 +1,36 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+#
+# Get a binary representation
+#
+function dec2bin (dec, bin) {
+ while (dec) {
+ bin = dec % 2 bin
+ dec = int (dec / 2)
+ }
+ return (bin)
+}
+
+{
+ bin = dec2bin($1)
+ l = length (bin)
+ #
+ # Check if it's a palindrome
+ #
+ for (i = 1; i < l / 2; i ++) {
+ if (substr (bin, i, 1) != substr (bin, l - i + 1, 1)) {
+ print (0)
+ next
+ }
+ }
+ print (1)
+}
+
diff --git a/challenge-118/abigail/awk/ch-2.awk b/challenge-118/abigail/awk/ch-2.awk
new file mode 100644
index 0000000000..d4cf905f2e
--- /dev/null
+++ b/challenge-118/abigail/awk/ch-2.awk
@@ -0,0 +1,14 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-2.awk
+#
+
+BEGIN {
+ print "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2"
+}
+
diff --git a/challenge-118/abigail/bash/ch-1.sh b/challenge-118/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..873decd636
--- /dev/null
+++ b/challenge-118/abigail/bash/ch-1.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+function dec2bin () {
+ dec=$1
+ bin=""
+ while ((dec > 0))
+ do bin=$((dec % 2))$bin
+ ((dec /= 2))
+ done
+}
+
+while read dec
+do dec2bin $dec
+ for ((i = 0; i < ${#bin} / 2; i ++))
+ do if [ "${bin:$i:1}" = "${bin:$((${#bin} - i - 1)):1}" ]
+ then continue
+ fi
+ echo 0
+ continue 2
+ done
+ echo 1
+done
diff --git a/challenge-118/abigail/bash/ch-2.sh b/challenge-118/abigail/bash/ch-2.sh
new file mode 100644
index 0000000000..e48430410e
--- /dev/null
+++ b/challenge-118/abigail/bash/ch-2.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-2.sh
+#
+
+echo "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2"
diff --git a/challenge-118/abigail/basic/ch-2.bas b/challenge-118/abigail/basic/ch-2.bas
new file mode 100644
index 0000000000..8e07ba8840
--- /dev/null
+++ b/challenge-118/abigail/basic/ch-2.bas
@@ -0,0 +1,9 @@
+010 REM
+020 REM See ../README.md
+030 REM
+
+040 REM
+050 REM Run as: basic ch-2.bas
+060 REM
+
+100 PRINT "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2"
diff --git a/challenge-118/abigail/bc/ch-2.bc b/challenge-118/abigail/bc/ch-2.bc
new file mode 100644
index 0000000000..5125d6a827
--- /dev/null
+++ b/challenge-118/abigail/bc/ch-2.bc
@@ -0,0 +1,10 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc ch-2.bc
+#
+"a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2
+"
+quit
diff --git a/challenge-118/abigail/befunge-93/ch-2.bf93 b/challenge-118/abigail/befunge-93/ch-2.bf93
new file mode 100644
index 0000000000..b31e3efee9
--- /dev/null
+++ b/challenge-118/abigail/befunge-93/ch-2.bf93
@@ -0,0 +1,2 @@
+< v,_@#:< "a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2" +55
+ > ^
diff --git a/challenge-118/abigail/blog.txt b/challenge-118/abigail/blog.txt
new file mode 100644
index 0000000000..80b7af5f39
--- /dev/null
+++ b/challenge-118/abigail/blog.txt
@@ -0,0 +1 @@
+https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-118-1.html
diff --git a/challenge-118/abigail/blog1.txt b/challenge-118/abigail/blog1.txt
new file mode 100644
index 0000000000..f34b88bb1f
--- /dev/null
+++ b/challenge-118/abigail/blog1.txt
@@ -0,0 +1 @@
+https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-118-2.html
diff --git a/challenge-118/abigail/c/ch-1.c b/challenge-118/abigail/c/ch-1.c
new file mode 100644
index 0000000000..637c938d0e
--- /dev/null
+++ b/challenge-118/abigail/c/ch-1.c
@@ -0,0 +1,42 @@
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+
+/*
+ * See ../README.md
+ */
+
+/*
+ * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file
+ */
+
+
+int main (void) {
+ long long dec;
+ while (scanf ("%lld", &dec) == 1) {
+ /*
+ * Find the largest power of 2 smaller than dec;
+ * this is the position of the leading 1.
+ */
+ long long i = 1;
+ int k = 0;
+ for (k = 0; i <= dec; k ++, i = i << 1);
+ /*
+ * We overshot by 1
+ */
+ k -= 1;
+
+ /*
+ * Now, compare the bits
+ */
+ int is_palin = 1;
+ for (int j = 0; j < k; k --, j ++) {
+ if (((dec & (1 << j)) >> j) != ((dec & (1 << k)) >> k)) {
+ is_palin = 0;
+ break;
+ }
+ }
+ printf ("%d\n", is_palin);
+ }
+ return (0);
+}
diff --git a/challenge-118/abigail/c/ch-2.c b/challenge-118/abigail/c/ch-2.c
new file mode 100644
index 0000000000..74531ee18d
--- /dev/null
+++ b/challenge-118/abigail/c/ch-2.c
@@ -0,0 +1,16 @@
+# include <stdlib.h>
+# include <stdio.h>
+# include <st