aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-10-26 01:39:02 +0200
committerAbigail <abigail@abigail.be>2021-10-26 01:39:02 +0200
commit848f09825ecee5c5097a1fbc9268a77fedf34a30 (patch)
tree276d3b84d347a2d4bf32ba9db04077bb125f9a10
parentfb5bf8970ed9e1caf0ddcc71e6dd3ffd9162d1af (diff)
downloadperlweeklychallenge-club-848f09825ecee5c5097a1fbc9268a77fedf34a30.tar.gz
perlweeklychallenge-club-848f09825ecee5c5097a1fbc9268a77fedf34a30.tar.bz2
perlweeklychallenge-club-848f09825ecee5c5097a1fbc9268a77fedf34a30.zip
Call "count()" with just one argument
-rw-r--r--challenge-136/abigail/awk/ch-2.awk4
-rw-r--r--challenge-136/abigail/c/ch-2.c12
-rw-r--r--challenge-136/abigail/go/ch-2.go12
-rw-r--r--challenge-136/abigail/lua/ch-2.lua12
-rw-r--r--challenge-136/abigail/node/ch-2.js4
-rw-r--r--challenge-136/abigail/python/ch-2.py11
-rw-r--r--challenge-136/abigail/ruby/ch-2.rb12
7 files changed, 45 insertions, 22 deletions
diff --git a/challenge-136/abigail/awk/ch-2.awk b/challenge-136/abigail/awk/ch-2.awk
index f950feb582..2df5623041 100644
--- a/challenge-136/abigail/awk/ch-2.awk
+++ b/challenge-136/abigail/awk/ch-2.awk
@@ -9,6 +9,8 @@
#
function count (target, this_fib, prev_fib) {
+ if (!this_fib) {this_fib = 1}
+ if (!prev_fib) {prev_fib = 1}
return target < this_fib ? 0 \
: target == this_fib ? 1 \
: count(target - this_fib, this_fib + prev_fib, this_fib) + \
@@ -16,5 +18,5 @@ function count (target, this_fib, prev_fib) {
}
{
- print count($1, 1, 1)
+ print count($1)
}
diff --git a/challenge-136/abigail/c/ch-2.c b/challenge-136/abigail/c/ch-2.c
index b5ef913ac9..e3c2cb8fd8 100644
--- a/challenge-136/abigail/c/ch-2.c
+++ b/challenge-136/abigail/c/ch-2.c
@@ -10,17 +10,21 @@
* Run as: cc -o ch-2.o ch-2.c; ./ch-2.o < input-file
*/
-int count (long long target, long long this_fib, long long prev_fib) {
+int _count (long long target, long long this_fib, long long prev_fib) {
return target < this_fib ? 0
: target == this_fib ? 1
- : count (target - this_fib, this_fib + prev_fib, this_fib) +
- count (target, this_fib + prev_fib, this_fib);
+ : _count (target - this_fib, this_fib + prev_fib, this_fib) +
+ _count (target, this_fib + prev_fib, this_fib);
+}
+
+int count (long long target) {
+ return _count (target, 1, 1);
}
int main (void) {
long long n;
while (scanf ("%lld", &n) == 1) {
- printf ("%d\n", count (n, 1, 1));
+ printf ("%d\n", count (n));
}
return (0);
diff --git a/challenge-136/abigail/go/ch-2.go b/challenge-136/abigail/go/ch-2.go
index b0e177f75c..adff1db0df 100644
--- a/challenge-136/abigail/go/ch-2.go
+++ b/challenge-136/abigail/go/ch-2.go
@@ -12,11 +12,15 @@ import (
"fmt"
)
-func count (target int, this_fib int, prev_fib int) int {
+func _count (target int, this_fib int, prev_fib int) int {
if target < this_fib {return 0}
if target == this_fib {return 1}
- return count (target - this_fib, this_fib + prev_fib, this_fib) +
- count (target, this_fib + prev_fib, this_fib)
+ return _count (target - this_fib, this_fib + prev_fib, this_fib) +
+ _count (target, this_fib + prev_fib, this_fib)
+}
+
+func count (target int) int {
+ return _count (target, 1, 1)
}
func main () {
@@ -27,6 +31,6 @@ func main () {
break;
}
- fmt . Printf ("%d\n", count (n, 1, 1))
+ fmt . Printf ("%d\n", count (n))
}
}
diff --git a/challenge-136/abigail/lua/ch-2.lua b/challenge-136/abigail/lua/ch-2.lua
index d403ce64d6..06d92984f4 100644
--- a/challenge-136/abigail/lua/ch-2.lua
+++ b/challenge-136/abigail/lua/ch-2.lua
@@ -8,13 +8,17 @@
-- Run as: lua ch-2.lua < input-file
--
-function count (target, this_fib, prev_fib)
+function _count (target, this_fib, prev_fib)
if target < this_fib then return 0 end
if target == this_fib then return 1 end
- return (count (target - this_fib, this_fib + prev_fib, this_fib) +
- count (target, this_fib + prev_fib, this_fib))
+ return (_count (target - this_fib, this_fib + prev_fib, this_fib) +
+ _count (target, this_fib + prev_fib, this_fib))
+end
+
+function count (target)
+ return (_count (target, 1, 1))
end
for line in io . lines () do
- print (count (tonumber (line), 1, 1))
+ print (count (tonumber (line)))
end
diff --git a/challenge-136/abigail/node/ch-2.js b/challenge-136/abigail/node/ch-2.js
index 7d6c4538fb..eaf2a426a0 100644
--- a/challenge-136/abigail/node/ch-2.js
+++ b/challenge-136/abigail/node/ch-2.js
@@ -9,6 +9,8 @@
//
function count (target, this_fib, prev_fib) {
+ if (!this_fib) {this_fib = 1}
+ if (!prev_fib) {prev_fib = 1}
return target < this_fib ? 0
: target == this_fib ? 1
: count (target - this_fib, this_fib + prev_fib, this_fib) +
@@ -18,4 +20,4 @@ function count (target, this_fib, prev_fib) {
require ('readline')
. createInterface ({input: process . stdin})
-. on ('line', line => console . log (count (+line, 1, 1)))
+. on ('line', line => console . log (count (+line)))
diff --git a/challenge-136/abigail/python/ch-2.py b/challenge-136/abigail/python/ch-2.py
index 8a73a45846..88960021ef 100644
--- a/challenge-136/abigail/python/ch-2.py
+++ b/challenge-136/abigail/python/ch-2.py
@@ -8,15 +8,18 @@
# Run as: python ch-2.py < input-file
#
-def count (target, this_fib, prev_fib):
+def _count (target, this_fib, prev_fib):
if target < this_fib:
return (0)
if target == this_fib:
return (1)
- return (count (target - this_fib, this_fib + prev_fib, this_fib) +
- count (target, this_fib + prev_fib, this_fib))
+ return (_count (target - this_fib, this_fib + prev_fib, this_fib) +
+ _count (target, this_fib + prev_fib, this_fib))
+
+def count (target):
+ return (_count (target, 1, 1))
import fileinput
for line in fileinput . input ():
- print (count (int (line), 1, 1))
+ print (count (int (line)))
diff --git a/challenge-136/abigail/ruby/ch-2.rb b/challenge-136/abigail/ruby/ch-2.rb
index d1bd264ff6..24e129a00d 100644
--- a/challenge-136/abigail/ruby/ch-2.rb
+++ b/challenge-136/abigail/ruby/ch-2.rb
@@ -8,14 +8,18 @@
# Run as: ruby ch-2.rb < input-file
#
-def count (target, this_fib, prev_fib)
+def _count (target, this_fib, prev_fib)
return target < this_fib ? 0
: target == this_fib ? 1
- : count(target - this_fib, this_fib + prev_fib, this_fib) +
- count(target, this_fib + prev_fib, this_fib)
+ : _count(target - this_fib, this_fib + prev_fib, this_fib) +
+ _count(target, this_fib + prev_fib, this_fib)
+end
+
+def count (target)
+ return _count(target, 1, 1)
end
ARGF . each_line do
| line |
- puts (count(line . to_i, 1, 1))
+ puts (count(line . to_i))
end