aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-11-04 18:12:56 +0100
committerAbigail <abigail@abigail.be>2021-11-04 20:03:53 +0100
commit563cb2f865dcb3e10e7fe0cd3d8ca60a3e02e407 (patch)
treef67411ffa745828f70bd96aa849a36cb7a2a1aa3
parent894b6aa2f49af3178b0983689f9ba81c002ca7a3 (diff)
downloadperlweeklychallenge-club-563cb2f865dcb3e10e7fe0cd3d8ca60a3e02e407.tar.gz
perlweeklychallenge-club-563cb2f865dcb3e10e7fe0cd3d8ca60a3e02e407.tar.bz2
perlweeklychallenge-club-563cb2f865dcb3e10e7fe0cd3d8ca60a3e02e407.zip
Bash, bc, C, Lua, Node.js, Python and Ruby solutions for week 133, part 1.
-rw-r--r--challenge-133/abigail/README.md6
-rw-r--r--challenge-133/abigail/bash/ch-1.sh24
-rw-r--r--challenge-133/abigail/bc/ch-1.bc18
-rw-r--r--challenge-133/abigail/c/ch-1.c22
-rw-r--r--challenge-133/abigail/lua/ch-1.lua13
-rw-r--r--challenge-133/abigail/node/ch-1.js15
-rw-r--r--challenge-133/abigail/python/ch-1.py15
-rw-r--r--challenge-133/abigail/ruby/ch-1.rb14
-rw-r--r--challenge-133/abigail/t/ctest.ini6
9 files changed, 133 insertions, 0 deletions
diff --git a/challenge-133/abigail/README.md b/challenge-133/abigail/README.md
index a5c5601063..228c3cd83c 100644
--- a/challenge-133/abigail/README.md
+++ b/challenge-133/abigail/README.md
@@ -9,8 +9,14 @@
### "No buildin sqrt function"
* [AWK][awk/ch-1.awk)
+* [Bash][bash/ch-1.sh)
+* [bc][bc/ch-1.bc)
* [C][c/ch-1.c)
+* [Lua][lua/ch-1.lua)
+* [Node.js][node/ch-1.js)
* [Perl][perl/ch-1a.pl)
+* [Python][python/ch-1.py)
+* [Ruby][ruby/ch-1.rb)
## Part 2
diff --git a/challenge-133/abigail/bash/ch-1.sh b/challenge-133/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..19b65855f8
--- /dev/null
+++ b/challenge-133/abigail/bash/ch-1.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+while read num
+do min=1
+ max=$num
+ while ((min + 1 < max))
+ do mid=$(((min + max) / 2))
+ if ((mid * mid < num))
+ then ((min = mid))
+ else ((max = mid))
+ fi
+ done
+ echo $min
+done
diff --git a/challenge-133/abigail/bc/ch-1.bc b/challenge-133/abigail/bc/ch-1.bc
new file mode 100644
index 0000000000..22bc6047db
--- /dev/null
+++ b/challenge-133/abigail/bc/ch-1.bc
@@ -0,0 +1,18 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc ch-1.bc < input-file
+#
+
+
+while (1) {
+ n = read ()
+ if (n == 0) {break}
+ p = l (n) / 2
+ o = scale
+ scale = 0
+ e (p)
+ scale = o
+}
diff --git a/challenge-133/abigail/c/ch-1.c b/challenge-133/abigail/c/ch-1.c
new file mode 100644
index 0000000000..b750302613
--- /dev/null
+++ b/challenge-133/abigail/c/ch-1.c
@@ -0,0 +1,22 @@
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+# include <math.h>
+
+/*
+ * See ../README.md
+ */
+
+/*
+ * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file
+ */
+
+int main (void) {
+ int n;
+
+ while (scanf ("%d", &n) == 1) {
+ printf ("%.0f\n", floor (exp (log ((double) n) / 2)));
+ }
+
+ return (0);
+}
diff --git a/challenge-133/abigail/lua/ch-1.lua b/challenge-133/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..f846c84e91
--- /dev/null
+++ b/challenge-133/abigail/lua/ch-1.lua
@@ -0,0 +1,13 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+for num in io . lines () do
+ print (math . floor (math . exp (math . log (tonumber (num)) / 2)))
+end
diff --git a/challenge-133/abigail/node/ch-1.js b/challenge-133/abigail/node/ch-1.js
new file mode 100644
index 0000000000..401e7ca4f4
--- /dev/null
+++ b/challenge-133/abigail/node/ch-1.js
@@ -0,0 +1,15 @@
+#!/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 (Math . floor (Math . exp (Math . log (+num) / 2)))
+})
diff --git a/challenge-133/abigail/python/ch-1.py b/challenge-133/abigail/python/ch-1.py
new file mode 100644
index 0000000000..9fc7b1c3fd
--- /dev/null
+++ b/challenge-133/abigail/python/ch-1.py
@@ -0,0 +1,15 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+import math
+
+for num in fileinput . input ():
+ print (math . floor (math . exp (math . log (int (num)) / 2)))
diff --git a/challenge-133/abigail/ruby/ch-1.rb b/challenge-133/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..efd3e4b8a0
--- /dev/null
+++ b/challenge-133/abigail/ruby/ch-1.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-1.rb < input-file
+#
+
+ARGF . each_line do
+ |num|
+ puts ((Math . exp(Math . log(num . to_i) / 2)) . to_i)
+end
diff --git a/challenge-133/abigail/t/ctest.ini b/challenge-133/abigail/t/ctest.ini
index 70cc45fe36..3e0bbdbb23 100644
--- a/challenge-133/abigail/t/ctest.ini
+++ b/challenge-133/abigail/t/ctest.ini
@@ -7,6 +7,12 @@
1-1 = Given Examples
2-1 = Fixed output
+[1-1/perl]
+skip = Does not write to stdout
+
+[1-1/bc]
+add_to_input = 0
+exe_args = -l %RUN_FILE
[2-1]
no_input = 1