diff options
| -rw-r--r-- | challenge-119/abigail/README.md | 3 | ||||
| -rw-r--r-- | challenge-119/abigail/bash/ch-2.sh | 28 | ||||
| -rw-r--r-- | challenge-119/abigail/bc/ch-1.bc | 15 | ||||
| -rw-r--r-- | challenge-119/abigail/befunge-93/ch-1.bf93 | 1 | ||||
| -rw-r--r-- | challenge-119/abigail/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-119/abigail/pascal/ch-1.p | 23 | ||||
| -rw-r--r-- | challenge-119/abigail/python/ch-2.py | 25 | ||||
| -rw-r--r-- | challenge-119/abigail/ruby/ch-2.rb | 27 | ||||
| -rw-r--r-- | challenge-119/abigail/t/ctest.ini | 3 |
9 files changed, 126 insertions, 0 deletions
diff --git a/challenge-119/abigail/README.md b/challenge-119/abigail/README.md index 03cfcb7919..c2ba036a3f 100644 --- a/challenge-119/abigail/README.md +++ b/challenge-119/abigail/README.md @@ -33,11 +33,14 @@ decimal `33`. ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) +* [bc](bc/ch-1.bc) +* [Befunge-93](befunge-93/ch-1.bf93) * [C](c/ch-1.c) * [Go](go/ch-1.go) * [Java](java/ch-1.java) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) +* [Pascal](pascal/ch-1.p) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) * [Ruby](ruby/ch-1.rb) diff --git a/challenge-119/abigail/bash/ch-2.sh b/challenge-119/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..3357e22cd7 --- /dev/null +++ b/challenge-119/abigail/bash/ch-2.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-2.sh < input-file +# + +set -f + +function next_number () { + [[ 0$1 =~ ^(.*)([012])(3*)$ ]] + next_num=${BASH_REMATCH[1]}$((BASH_REMATCH[2] + 1))${BASH_REMATCH[3]//3/1} + next_num=${next_num//11/12} + next_num=${next_num/0/} +} + + +while read num +do number="0" + for ((i = 0; i < num; i ++)) + do next_number $number + number=$next_num + done + echo $number +done diff --git a/challenge-119/abigail/bc/ch-1.bc b/challenge-119/abigail/bc/ch-1.bc new file mode 100644 index 0000000000..caeeb31b24 --- /dev/null +++ b/challenge-119/abigail/bc/ch-1.bc @@ -0,0 +1,15 @@ +# +# See ../README.md +# + +# +# Run as: bc ch-1.bc < input-file +# + +while (1) { + num = read () + if (num == 0) { + break + } + num - (num % 256) + (num % 16) * 16 + (num % 256) / 16 +} diff --git a/challenge-119/abigail/befunge-93/ch-1.bf93 b/challenge-119/abigail/befunge-93/ch-1.bf93 new file mode 100644 index 0000000000..f8bc20d14e --- /dev/null +++ b/challenge-119/abigail/befunge-93/ch-1.bf93 @@ -0,0 +1 @@ +> & :1+!#@_ : 44* % 44** \ 44*/ + . 55+, diff --git a/challenge-119/abigail/blog.txt b/challenge-119/abigail/blog.txt new file mode 100644 index 0000000000..b0b6be697f --- /dev/null +++ b/challenge-119/abigail/blog.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-119-1.html diff --git a/challenge-119/abigail/pascal/ch-1.p b/challenge-119/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..3d8be93535 --- /dev/null +++ b/challenge-119/abigail/pascal/ch-1.p @@ -0,0 +1,23 @@ +Program XXX; + +(* *) +(* See ../README.md *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out < input-file *) +(* *) + +var num: integer; + +begin + while true do begin + readln (num); + if num = 0 then begin + break; + end; + writeln ((num and not $FF) or + (num and $0F) shl 4 or + (num and $F0) shr 4); + end +end. diff --git a/challenge-119/abigail/python/ch-2.py b/challenge-119/abigail/python/ch-2.py new file mode 100644 index 0000000000..a8d72eb708 --- /dev/null +++ b/challenge-119/abigail/python/ch-2.py @@ -0,0 +1,25 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import re +import fileinput + +def next_num (prev_num): + match = re . match ('^(.*)([012])(3*)$', "0" + prev_num) + return (re . sub ('^0', '', \ + re . sub ('11', '12', match . group (1) + \ + str (int (match . group (2)) + 1) + \ + re . sub ('3', '1', match . group (3))))) + +for num in fileinput . input (): + number = "0" + for _ in range (int (num)): + number = next_num (number) + print (number) diff --git a/challenge-119/abigail/ruby/ch-2.rb b/challenge-119/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..55ac672fca --- /dev/null +++ b/challenge-119/abigail/ruby/ch-2.rb @@ -0,0 +1,27 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-2.rb < input-file +# + +def next_num (prev_num) + ("0" + prev_num) . match (/^(.*)([012])(3*)$/) do + |match| + return (match [1] + (1 + match [2] . to_i) . to_s + + match [3] . gsub(/3/, "1")) . gsub(/11/, "12") . gsub(/^0/, "") + end +end + + +ARGF . each_line do + |num| + number = "0" + for i in 1 .. num . to_i do + number = next_num (number) + end + puts (number) +end diff --git a/challenge-119/abigail/t/ctest.ini b/challenge-119/abigail/t/ctest.ini index 204106ba9b..8158e9b492 100644 --- a/challenge-119/abigail/t/ctest.ini +++ b/challenge-119/abigail/t/ctest.ini @@ -7,3 +7,6 @@ 1-1 = Given Examples
1-2 = First 255 positive integers
2-1 = Given Examples
+
+[challenges/1/bc]
+add_to_input = 0
|
