aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-117/abigail/awk/ch-2.awk10
-rw-r--r--challenge-117/abigail/bash/ch-2.sh10
-rw-r--r--challenge-117/abigail/c/ch-2.c30
-rw-r--r--challenge-117/abigail/lua/ch-2.lua10
-rw-r--r--challenge-117/abigail/node/ch-2.js10
-rw-r--r--challenge-117/abigail/perl/ch-2.pl12
-rw-r--r--challenge-117/abigail/python/ch-2.py10
-rw-r--r--challenge-117/abigail/ruby/ch-2.rb10
8 files changed, 51 insertions, 51 deletions
diff --git a/challenge-117/abigail/awk/ch-2.awk b/challenge-117/abigail/awk/ch-2.awk
index 961b53df39..e401f2360d 100644
--- a/challenge-117/abigail/awk/ch-2.awk
+++ b/challenge-117/abigail/awk/ch-2.awk
@@ -8,17 +8,17 @@
# Run as: awk -f ch-2.awk < input-file
#
-function steps (x, y, prefix) {
+function steps (x, y, path) {
if (x == 0 && y == 0) {
- print prefix
+ print path
return
}
if (x > 0) {
- steps(x - 1, y, prefix "R")
- steps(x - 1, y + 1, prefix "L")
+ steps(x - 1, y, path "R")
+ steps(x - 1, y + 1, path "L")
}
if (y > 0) {
- steps(x, y - 1, prefix "H")
+ steps(x, y - 1, path "H")
}
}
diff --git a/challenge-117/abigail/bash/ch-2.sh b/challenge-117/abigail/bash/ch-2.sh
index 97096b31d2..a5a5593dad 100644
--- a/challenge-117/abigail/bash/ch-2.sh
+++ b/challenge-117/abigail/bash/ch-2.sh
@@ -13,17 +13,17 @@ set -f
function steps () {
local x=$1
local y=$2
- local prefix=$3
+ local path=$3
if ((x == 0 && y == 0))
- then echo $prefix
+ then echo $path
return
fi
if ((x > 0))
- then steps $((x - 1)) $y ${prefix}R
- steps $((x - 1)) $((y + 1)) ${prefix}L
+ then steps $((x - 1)) $y ${path}R
+ steps $((x - 1)) $((y + 1)) ${path}L
fi
if ((y > 0))
- then steps $x $((y - 1)) ${prefix}H
+ then steps $x $((y - 1)) ${path}H
fi
}
diff --git a/challenge-117/abigail/c/ch-2.c b/challenge-117/abigail/c/ch-2.c
index f40f9980a5..7fe29480dc 100644
--- a/challenge-117/abigail/c/ch-2.c
+++ b/challenge-117/abigail/c/ch-2.c
@@ -10,36 +10,36 @@
* Run as: cc -o ch-2.o ch-2.c; ./ch-2.o < input-file
*/
-void steps (int x, int y, char * prefix, size_t l) {
+void steps (int x, int y, char * path, size_t l) {
if (x == 0 && y == 0) {
- printf ("%s\n", prefix);
+ printf ("%s\n", path);
return;
}
if (x > 0) {
- prefix [l] = 'R';
- prefix [l + 1] = '\0';
- steps (x - 1, y, prefix, l + 1);
- prefix [l] = 'L';
- prefix [l + 1] = '\0';
- steps (x - 1, y + 1, prefix, l + 1);
+ path [l] = 'R';
+ path [l + 1] = '\0';
+ steps (x - 1, y, path, l + 1);
+ path [l] = 'L';
+ path [l + 1] = '\0';
+ steps (x - 1, y + 1, path, l + 1);
}
if (y > 0) {
- prefix [l] = 'H';
- prefix [l + 1] = '\0';
- steps (x, y - 1, prefix, l + 1);
+ path [l] = 'H';
+ path [l + 1] = '\0';
+ steps (x, y - 1, path, l + 1);
}
}
int main (void) {
int size;
if (scanf ("%d", &size) == 1) {
- char * prefix;
- if ((prefix = (char *) malloc ((size + 1) * sizeof (char))) == NULL) {
+ char * path;
+ if ((path = (char *) malloc ((size + 1) * sizeof (char))) == NULL) {
perror ("Malloc failed");
exit (1);
}
- prefix [0] = '\0';
- steps (size, 0, prefix, 0);
+ path [0] = '\0';
+ steps (size, 0, path, 0);
}
return (0);
}
diff --git a/challenge-117/abigail/lua/ch-2.lua b/challenge-117/abigail/lua/ch-2.lua
index 3e47c2aa9b..bfe11d74d3 100644
--- a/challenge-117/abigail/lua/ch-2.lua
+++ b/challenge-117/abigail/lua/ch-2.lua
@@ -8,17 +8,17 @@
-- Run as: lua ch-2.lua < input-file
--
-function steps (x, y, prefix)
+function steps (x, y, path)
if x == 0 and y == 0
- then print (prefix)
+ then print (path)
return
end
if x > 0
- then steps (x - 1, y, prefix .. "R")
- steps (x - 1, y + 1, prefix .. "L")
+ then steps (x - 1, y, path .. "R")
+ steps (x - 1, y + 1, path .. "L")
end
if y > 0
- then steps (x, y - 1, prefix .. "H")
+ then steps (x, y - 1, path .. "H")
end
end
diff --git a/challenge-117/abigail/node/ch-2.js b/challenge-117/abigail/node/ch-2.js
index ae6449d9f4..0d6d48e6b7 100644
--- a/challenge-117/abigail/node/ch-2.js
+++ b/challenge-117/abigail/node/ch-2.js
@@ -8,17 +8,17 @@
// Run as: node ch-2.js < input-file
//
-function steps (x, y, prefix) {
+function steps (x, y, path) {
if (x == 0 && y == 0) {
- console . log (prefix)
+ console . log (path)
return
}
if (x > 0) {
- steps (x - 1, y, prefix + "R")
- steps (x - 1, y + 1, prefix + "L")
+ steps (x - 1, y, path + "R")
+ steps (x - 1, y + 1, path + "L")
}
if (y > 0) {
- steps (x, y - 1, prefix + "H")
+ steps (x, y - 1, path + "H")
}
}
diff --git a/challenge-117/abigail/perl/ch-2.pl b/challenge-117/abigail/perl/ch-2.pl
index e72dd46461..cac9bfe888 100644
--- a/challenge-117/abigail/perl/ch-2.pl
+++ b/challenge-117/abigail/perl/ch-2.pl
@@ -40,17 +40,17 @@ use experimental 'lexical_subs';
# a step to the right. The first coordinate stays the same,
# the second decreases by one.
# In each of the calls, we add the direction we took ("R", "L", or "H"),
-# to prefix.
+# to path.
#
#
# We will be reading a single line of input ($N)
#
-sub steps ($x, $y, $prefix) {
- say $prefix if $x == $y == 0;
- steps ($x - 1, $y, $prefix . "R") if $x > 0;
- steps ($x - 1, $y + 1, $prefix . "L") if $x > 0;
- steps ($x, $y - 1, $prefix . "H") if $y > 0;
+sub steps ($x, $y, $path) {
+ say $path if $x == $y == 0;
+ steps ($x - 1, $y, $path . "R") if $x > 0;
+ steps ($x - 1, $y + 1, $path . "L") if $x > 0;
+ steps ($x, $y - 1, $path . "H") if $y > 0;
}
steps (<>, 0, "");
diff --git a/challenge-117/abigail/python/ch-2.py b/challenge-117/abigail/python/ch-2.py
index 6ecf44b8f4..c52987fee8 100644
--- a/challenge-117/abigail/python/ch-2.py
+++ b/challenge-117/abigail/python/ch-2.py
@@ -10,15 +10,15 @@
import sys
-def steps (x, y, prefix):
+def steps (x, y, path):
if x == 0 and y == 0:
- print (prefix)
+ print (path)
return
if x > 0:
- steps (x - 1, y, prefix + "R")
- steps (x - 1, y + 1, prefix + "L")
+ steps (x - 1, y, path + "R")
+ steps (x - 1, y + 1, path + "L")
if y > 0:
- steps (x, y - 1, prefix + "H")
+ steps (x, y - 1, path + "H")
steps (int (sys . stdin . readline ()), 0, "")
diff --git a/challenge-117/abigail/ruby/ch-2.rb b/challenge-117/abigail/ruby/ch-2.rb
index 2b02c6e34f..d80f89616b 100644
--- a/challenge-117/abigail/ruby/ch-2.rb
+++ b/challenge-117/abigail/ruby/ch-2.rb
@@ -8,17 +8,17 @@
# Run as: ruby ch-2.rb < input-file
#
-def steps (x, y, prefix)
+def steps (x, y, path)
if x == 0 && y == 0
- then puts (prefix)
+ then puts (path)
return
end
if x > 0
- then steps(x - 1, y, prefix + "R")
- steps(x - 1, y + 1, prefix + "L")
+ then steps(x - 1, y, path + "R")
+ steps(x - 1, y + 1, path + "L")
end
if y > 0
- then steps(x, y - 1, prefix + "H")
+ then steps(x, y - 1, path + "H")
end
end