aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-07-05 14:38:06 +0200
committerAbigail <abigail@abigail.be>2021-07-05 14:38:06 +0200
commit78c841faea1060a3b7ea63a4316e461e490d275e (patch)
tree92a3b40da3986775fbf1441d6424f720cbe6e3df
parentc79281808d6b8968f5bd105536df88b345bded7d (diff)
downloadperlweeklychallenge-club-78c841faea1060a3b7ea63a4316e461e490d275e.tar.gz
perlweeklychallenge-club-78c841faea1060a3b7ea63a4316e461e490d275e.tar.bz2
perlweeklychallenge-club-78c841faea1060a3b7ea63a4316e461e490d275e.zip
Solutions in 15 languages for week 120, part 1.
This is basically the same as last weeks challenge...
-rw-r--r--challenge-120/abigail/README.md1
-rw-r--r--challenge-120/abigail/awk/ch-1.awk21
-rw-r--r--challenge-120/abigail/bash/ch-1.sh16
-rw-r--r--challenge-120/abigail/bc/ch-1.bc27
-rw-r--r--challenge-120/abigail/c/ch-1.c22
-rw-r--r--challenge-120/abigail/go/ch-1.go25
-rw-r--r--challenge-120/abigail/java/ch-1.java27
-rw-r--r--challenge-120/abigail/lua/ch-1.lua27
-rw-r--r--challenge-120/abigail/node/ch-1.js16
-rw-r--r--challenge-120/abigail/pascal/ch-1.p22
-rw-r--r--challenge-120/abigail/perl/ch-1.pl29
-rw-r--r--challenge-120/abigail/python/ch-1.py16
-rw-r--r--challenge-120/abigail/r/ch-1.r19
-rw-r--r--challenge-120/abigail/ruby/ch-1.rb16
-rw-r--r--challenge-120/abigail/scheme/ch-1.scm23
-rw-r--r--challenge-120/abigail/tcl/ch-1.tcl12
16 files changed, 318 insertions, 1 deletions
diff --git a/challenge-120/abigail/README.md b/challenge-120/abigail/README.md
index c7dfc7d883..f2ea164db7 100644
--- a/challenge-120/abigail/README.md
+++ b/challenge-120/abigail/README.md
@@ -29,7 +29,6 @@ The decimal equivalent of `100001` is `33`.
* [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)
diff --git a/challenge-120/abigail/awk/ch-1.awk b/challenge-120/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..2f7e4310d2
--- /dev/null
+++ b/challenge-120/abigail/awk/ch-1.awk
@@ -0,0 +1,21 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+{
+ out = 0
+ num = $1
+ for (i = 0; i < 8; i ++) {
+ bit = int ((num - (num % 2 ^ i)) / 2 ^ i) % 2;
+ if (bit) {
+ out += 2 ^ (i + (i % 2 ? -1 : 1))
+ }
+ }
+ print out
+}
diff --git a/challenge-120/abigail/bash/ch-1.sh b/challenge-120/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..8ecc50d5dc
--- /dev/null
+++ b/challenge-120/abigail/bash/ch-1.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+while read num
+do echo $(( (num & 0x55) << 1
+ | (num & 0xAA) >> 1 ))
+done
diff --git a/challenge-120/abigail/bc/ch-1.bc b/challenge-120/abigail/bc/ch-1.bc
new file mode 100644
index 0000000000..8a1f52c022
--- /dev/null
+++ b/challenge-120/abigail/bc/ch-1.bc
@@ -0,0 +1,27 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc ch-1.bc < input-file
+#
+
+while (1) {
+ num = read ()
+ if (num == 0) {
+ break
+ }
+ out = 0
+ for (i = 0; i < 8; i ++) {
+ bit = ((num - (num % 2 ^ i)) / 2 ^ i) % 2
+ if (bit == 1) {
+ if (i % 2 == 1) {
+ out += 2 ^ (i - 1)
+ }
+ if (i % 2 == 0) {
+ out += 2 ^ (i + 1)
+ }
+ }
+ }
+ out
+}
diff --git a/challenge-120/abigail/c/ch-1.c b/challenge-120/abigail/c/ch-1.c
new file mode 100644
index 0000000000..ae21fa18d5
--- /dev/null
+++ b/challenge-120/abigail/c/ch-1.c
@@ -0,0 +1,22 @@
+# 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) {
+ int num;
+
+ while (scanf ("%d", &num) == 1) {
+ printf ("%d\n", (num & 0x55) << 1
+ | (num & 0xAA) >> 1);
+ }
+
+ return (0);
+}
diff --git a/challenge-120/abigail/go/ch-1.go b/challenge-120/abigail/go/ch-1.go
new file mode 100644
index 0000000000..e5ebd26ebb
--- /dev/null
+++ b/challenge-120/abigail/go/ch-1.go
@@ -0,0 +1,25 @@
+package main
+
+//
+// See ../README.md
+//
+
+//
+// Run as: go run ch-1.go
+//
+
+import (
+ "fmt"
+)
+
+func main () {
+ for {
+ var n, num int
+ n, _ = fmt . Scanf ("%d", &num)
+ if (n != 1) {
+ break
+ }
+ fmt . Printf ("%d\n", (num & 0x55) << 1 |
+ (num & 0xAA) >> 1)
+ }
+}
diff --git a/challenge-120/abigail/java/ch-1.java b/challenge-120/abigail/java/ch-1.java
new file mode 100644
index 0000000000..66cf3ee4e7
--- /dev/null
+++ b/challenge-120/abigail/java/ch-1.java
@@ -0,0 +1,27 @@
+//
+// See ../README.md
+//
+
+//
+// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file
+//
+
+import java.util.*;
+
+public class ch1 {
+ public static void main (String [] args) {
+ Scanner scanner = new Scanner (System . in);
+ try {
+ while (true) {
+ int num = scanner . nextInt ();
+ System . out . println ( (num & 0x55) << 1
+ | (num & 0xAA) >> 1);
+ }
+ }
+ catch (Exception e) {
+ //
+ // EOF
+ //
+ }
+ }
+}
diff --git a/challenge-120/abigail/lua/ch-1.lua b/challenge-120/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..0d5896f59c
--- /dev/null
+++ b/challenge-120/abigail/lua/ch-1.lua
@@ -0,0 +1,27 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+for line in io . lines () do
+ num = tonumber (line)
+ out = 0
+ for i = 0, 7 do
+ bit = math . floor ((num - (num % (2 ^ i))) / (2 ^ i)) % 2
+ if bit == 1
+ then
+ if i % 2 == 1
+ then
+ out = out + 2 ^ (i - 1)
+ else
+ out = out + 2 ^ (i + 1)
+ end
+ end
+ end
+ print (out)
+end
diff --git a/challenge-120/abigail/node/ch-1.js b/challenge-120/abigail/node/ch-1.js
new file mode 100644
index 0000000000..b40fd0d3ac
--- /dev/null
+++ b/challenge-120/abigail/node/ch-1.js
@@ -0,0 +1,16 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-1.js < input-file
+//
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', (num) => {
+ console . log ( (+num & 0x55) << 1
+ | (+num & 0xAA) >> 1)
+})
diff --git a/challenge-120/abigail/pascal/ch-1.p b/challenge-120/abigail/pascal/ch-1.p
new file mode 100644
index 0000000000..b16ebde46e
--- /dev/null
+++ b/challenge-120/abigail/pascal/ch-1.p
@@ -0,0 +1,22 @@
+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 $55) shl 1 or
+ (num and $AA) shr 1);
+ end
+end.
diff --git a/challenge-120/abigail/perl/ch-1.pl b/challenge-120/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..b5aa1b4b9d
--- /dev/null
+++ b/challenge-120/abigail/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!/opt/perl/bin/perl
+
+use 5.032;
+
+use strict;
+use warnings;
+no warnings 'syntax';
+
+use experimental 'signatures';
+use experimental 'lexical_subs';
+
+#
+# See ../README.md
+#
+
+#
+# Run as: perl ch-1.pl < input-file
+#
+
+#
+# This is just week 119 with different constants
+#
+
+
+while (<>) {
+ say + ($_ & 0x55) << 1 # Odd bits shifted one the right
+ | ($_ & 0xAA) >> 1 # Even bits shifted one to the left
+}
+
diff --git a/challenge-120/abigail/python/ch-1.py b/challenge-120/abigail/python/ch-1.py
new file mode 100644
index 0000000000..510ce33d10
--- /dev/null
+++ b/challenge-120/abigail/python/ch-1.py
@@ -0,0 +1,16 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+
+for line in fileinput . input ():
+ num = int (line)
+ print ( (num & 0x55) << 1
+ | (num & 0xAA) >> 1)
diff --git a/challenge-120/abigail/r/ch-1.r b/challenge-120/abigail/r/ch-1.r
new file mode 100644
index 0000000000..b276380d71
--- /dev/null
+++ b/challenge-120/abigail/r/ch-1.r
@@ -0,0 +1,19 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: Rscript ch-1.r < input-file
+#
+
+stdin <- file ('stdin', 'r')
+repeat {
+ n <- readLines (stdin, n = 1)
+ if (length (n) == 0) {
+ break
+ }
+ n = as.integer (n)
+
+ cat (bitwOr (bitwShiftL (bitwAnd (n, 0x55), 1),
+ bitwShiftR (bitwAnd (n, 0xAA), 1)), "\n")
+}
diff --git a/challenge-120/abigail/ruby/ch-1.rb b/challenge-120/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..51fc9f6e50
--- /dev/null
+++ b/challenge-120/abigail/ruby/ch-1.rb
@@ -0,0 +1,16 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-1.rb < input-file
+#
+
+ARGF . each_line do
+ |line|
+ num = line . to_i
+ puts ( (num & 0x55) << 1 \
+ | (num & 0xAA) >> 1)
+end
diff --git a/challenge-120/abigail/scheme/ch-1.scm b/challenge-120/abigail/scheme/ch-1.scm
new file mode 100644
index 0000000000..d28e2f668e
--- /dev/null
+++ b/challenge-120/abigail/scheme/ch-1.scm
@@ -0,0 +1,23 @@
+;;;
+;;; See ../README.md
+;;;
+
+;;;
+;;; Run as: guile --no-auto-compile ch-1.scm < input-file
+;;;
+
+
+(use-modules (ice-9 format))
+
+(define (main)
+ (define num (read))
+ (if (not (eof-object? num))
+ (begin
+ (format #t "~d\n" (logior (ash (logand num #x55) 1)
+ (ash (logand num #xAA) -1)))
+ (main)
+ )
+ )
+)
+
+(main)
diff --git a/challenge-120/abigail/tcl/ch-1.tcl b/challenge-120/abigail/tcl/ch-1.tcl
new file mode 100644
index 0000000000..5e08e4c702
--- /dev/null
+++ b/challenge-120/abigail/tcl/ch-1.tcl
@@ -0,0 +1,12 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: tclsh ch-1.tcl < input-file
+#
+
+while {[gets stdin num] >= 0} {
+ puts [expr ($num & 0x55) << 1 \
+ | ($num & 0xAA) >> 1]
+}