aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-06-28 14:34:16 +0200
committerAbigail <abigail@abigail.be>2021-06-28 14:34:16 +0200
commitcdbc2bb40b6c79ddae6896768daecb3fd70db92f (patch)
tree210e83e152594bc664f6f9919743e295bd50fef6
parentd14669a0f60a4846ad4bbd5ed5c6a195302a1e50 (diff)
downloadperlweeklychallenge-club-cdbc2bb40b6c79ddae6896768daecb3fd70db92f.tar.gz
perlweeklychallenge-club-cdbc2bb40b6c79ddae6896768daecb3fd70db92f.tar.bz2
perlweeklychallenge-club-cdbc2bb40b6c79ddae6896768daecb3fd70db92f.zip
Solutions in 10 languages for week 119, part 1.
-rw-r--r--challenge-119/abigail/awk/ch-1.awk15
-rw-r--r--challenge-119/abigail/bash/ch-1.sh17
-rw-r--r--challenge-119/abigail/c/ch-1.c23
-rw-r--r--challenge-119/abigail/go/ch-1.go26
-rw-r--r--challenge-119/abigail/java/ch-1.java28
-rw-r--r--challenge-119/abigail/lua/ch-1.lua16
-rw-r--r--challenge-119/abigail/node/ch-1.js17
-rw-r--r--challenge-119/abigail/perl/ch-1.pl31
-rw-r--r--challenge-119/abigail/python/ch-1.py17
-rw-r--r--challenge-119/abigail/ruby/ch-1.rb17
10 files changed, 207 insertions, 0 deletions
diff --git a/challenge-119/abigail/awk/ch-1.awk b/challenge-119/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..fce43f8a43
--- /dev/null
+++ b/challenge-119/abigail/awk/ch-1.awk
@@ -0,0 +1,15 @@
+#!/usr/bin/awk
+
+#
+# See ../README.md
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+{
+ print ( ($1 - ($1 % 256)) \
+ + ($1 % 16) * 16 \
+ + int (($1 % 256) / 16))
+}
diff --git a/challenge-119/abigail/bash/ch-1.sh b/challenge-119/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..f1ea005047
--- /dev/null
+++ b/challenge-119/abigail/bash/ch-1.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+while read num
+do echo $(( (num & ~0xFF)
+ | (num & 0x0F) << 4
+ | (num & 0xF0) >> 4 ))
+done
diff --git a/challenge-119/abigail/c/ch-1.c b/challenge-119/abigail/c/ch-1.c
new file mode 100644
index 0000000000..2c69cefc7a
--- /dev/null
+++ b/challenge-119/abigail/c/ch-1.c
@@ -0,0 +1,23 @@
+# 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 & ~0xFF)
+ | (num & 0x0F) << 4
+ | (num & 0xF0) >> 4);
+ }
+
+ return (0);
+}
diff --git a/challenge-119/abigail/go/ch-1.go b/challenge-119/abigail/go/ch-1.go
new file mode 100644
index 0000000000..0055e3a4ac
--- /dev/null
+++ b/challenge-119/abigail/go/ch-1.go
@@ -0,0 +1,26 @@
+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 &^ 0xFF) |
+ (num & 0x0F) << 4 |
+ (num & 0xF0) >> 4)
+ }
+}
diff --git a/challenge-119/abigail/java/ch-1.java b/challenge-119/abigail/java/ch-1.java
new file mode 100644
index 0000000000..28912f3ab4
--- /dev/null
+++ b/challenge-119/abigail/java/ch-1.java
@@ -0,0 +1,28 @@
+//
+// 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 & ~0xFF)
+ | (num & 0x0F) << 4
+ | (num & 0xF0) >> 4);
+ }
+ }
+ catch (Exception e) {
+ //
+ // EOF
+ //
+ }
+ }
+}
diff --git a/challenge-119/abigail/lua/ch-1.lua b/challenge-119/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..b31105ea9a
--- /dev/null
+++ b/challenge-119/abigail/lua/ch-1.lua
@@ -0,0 +1,16 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+for line in io . lines () do
+ num = tonumber (line)
+ print ( (num - (num % 0x100))
+ + ((num % 0x010) * 0x010)
+ + math . floor ((num % 0x100) / 0x010))
+end
diff --git a/challenge-119/abigail/node/ch-1.js b/challenge-119/abigail/node/ch-1.js
new file mode 100644
index 0000000000..42bc49730e
--- /dev/null
+++ b/challenge-119/abigail/node/ch-1.js
@@ -0,0 +1,17 @@
+#!/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 & ~0xFF)
+ | (+num & 0x0F) << 4
+ | (+num & 0xF0) >> 4)
+})
diff --git a/challenge-119/abigail/perl/ch-1.pl b/challenge-119/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..9c4f11c25a
--- /dev/null
+++ b/challenge-119/abigail/perl/ch-1.pl
@@ -0,0 +1,31 @@
+#!/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
+#
+
+#
+# We can solve this by just shifting some bits around.
+# There is also no need to restrict ourselves to numbers less than 256.
+#
+
+
+while (<>) {
+ say + ($_ & ~0xFF) # Number with the last two nibbles 0.
+ | ($_ & 0x0F) << 4 # Last nibble shifted 4 bits to the left.
+ | ($_ & 0xF0) >> 4 # Penultimate nibble shifted 4 bits to the right.
+}
+
diff --git a/challenge-119/abigail/python/ch-1.py b/challenge-119/abigail/python/ch-1.py
new file mode 100644
index 0000000000..7bf1c2ff41
--- /dev/null
+++ b/challenge-119/abigail/python/ch-1.py
@@ -0,0 +1,17 @@
+#!/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 & ~0xFF)
+ | (num & 0x0F) << 4
+ | (num & 0xF0) >> 4)
diff --git a/challenge-119/abigail/ruby/ch-1.rb b/challenge-119/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..f41b55ae48
--- /dev/null
+++ b/challenge-119/abigail/ruby/ch-1.rb
@@ -0,0 +1,17 @@
+#!/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 & ~0xFF) \
+ | (num & 0x0F) << 4 \
+ | (num & 0xF0) >> 4)
+end