aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-10-29 14:14:54 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2021-10-29 14:14:54 +0100
commit42f850c117e589c502a2ad1d0147f229223fdf44 (patch)
tree8726b9674ad0c56a765bb142cc312ba33dff825c
parent3942303512e3ac0e48e57a2e9e8c2ef2a5e8cb6e (diff)
parent85e041ce62ebb1025717e5ad04a8681d043c3f08 (diff)
downloadperlweeklychallenge-club-42f850c117e589c502a2ad1d0147f229223fdf44.tar.gz
perlweeklychallenge-club-42f850c117e589c502a2ad1d0147f229223fdf44.tar.bz2
perlweeklychallenge-club-42f850c117e589c502a2ad1d0147f229223fdf44.zip
Merge branch 'master' into devel
-rwxr-xr-xchallenge-136/e-choroba/perl/ch-1.pl26
-rwxr-xr-xchallenge-136/e-choroba/perl/ch-2.pl82
-rw-r--r--challenge-136/james-smith/perl/ch-1.pl27
-rw-r--r--challenge-136/james-smith/perl/ch-2.pl39
-rwxr-xr-xchallenge-136/jo-37/perl/ch-1.pl70
-rwxr-xr-xchallenge-136/jo-37/perl/ch-2.pl107
-rwxr-xr-xchallenge-136/perlboy1967/perl/ch-1.pl53
-rwxr-xr-xchallenge-136/perlboy1967/perl/ch-2.pl99
-rw-r--r--challenge-136/roger-bell-west/blog.txt1
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/README.md14
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/bb.edn4
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/deps.edn3
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/pom.xml8
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/core.clj12
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t1.clj26
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t2.clj20
l---------challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj1
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t1_test.clj9
-rw-r--r--challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t2_test.clj9
-rw-r--r--stats/pwc-challenge-123.json543
-rw-r--r--stats/pwc-challenge-124.json491
-rw-r--r--stats/pwc-current.json292
-rw-r--r--stats/pwc-language-breakdown-summary.json76
-rw-r--r--stats/pwc-language-breakdown.json942
-rw-r--r--stats/pwc-leaders.json476
-rw-r--r--stats/pwc-summary-1-30.json106
-rw-r--r--stats/pwc-summary-121-150.json48
-rw-r--r--stats/pwc-summary-151-180.json40
-rw-r--r--stats/pwc-summary-181-210.json120
-rw-r--r--stats/pwc-summary-211-240.json48
-rw-r--r--stats/pwc-summary-241-270.json26
-rw-r--r--stats/pwc-summary-31-60.json44
-rw-r--r--stats/pwc-summary-61-90.json102
-rw-r--r--stats/pwc-summary-91-120.json106
-rw-r--r--stats/pwc-summary.json66
35 files changed, 2410 insertions, 1726 deletions
diff --git a/challenge-136/e-choroba/perl/ch-1.pl b/challenge-136/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..04e324c953
--- /dev/null
+++ b/challenge-136/e-choroba/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#! /usr/bin/perl
+use warnings;
+use strict;
+
+sub gcd {
+ my ($m, $n) = @_;
+ while ($m && $n) {
+ ($m, $n) = ($n, $m) if $n < $m;
+ $n -= int($n / $m) * $m;
+ }
+ return $m
+}
+
+sub two_friendly {
+ my ($m, $n) = @_;
+ my $g = gcd($m, $n);
+ my $binary = sprintf '%b', $g;
+ return 1 == $binary =~ tr/1// ? 1 : 0
+}
+
+use Test2::V0;
+plan 3;
+
+is two_friendly(8, 24), 1, 'Example 1';
+is two_friendly(26, 39), 0, 'Example 2';
+is two_friendly(4, 10), 1, 'Example 3';
diff --git a/challenge-136/e-choroba/perl/ch-2.pl b/challenge-136/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..475a906652
--- /dev/null
+++ b/challenge-136/e-choroba/perl/ch-2.pl
@@ -0,0 +1,82 @@
+#! /usr/bin/perl
+use warnings;
+use strict;
+
+use List::Util qw{ sum };
+
+my @F = (1, 2);
+sub fibonacci_sequence {
+ my ($n) = @_;
+ my $count = 0;
+ my $indicator = 1;
+ my $bin = 1;
+ while ($F[ length($bin) - 1 ] <= $n) {
+ push @F, $F[-2] + $F[-1] if @F <= length $bin;
+ my $sum = sum(@F[ grep substr($bin, -$_ - 1, 1),
+ 0 .. length($bin) - 1 ]);
+ ++$count if $sum == $n;
+ ++$indicator;
+ $bin = sprintf '%b', $indicator;
+ }
+ return $count
+}
+
+use Test2::V0;
+plan 52;
+
+is fibonacci_sequence(16), 4, 'Example 1';
+is fibonacci_sequence(9), 2, 'Example 2';
+is fibonacci_sequence(15), 2, 'Example 3';
+
+# Used $n ** 2 instead of $n in the while condition to verify the numbers are
+# correct.
+
+is fibonacci_sequence(17), 2, 'Check 17';
+is fibonacci_sequence(18), 3, 'Check 18';
+is fibonacci_sequence(19), 3, 'Check 19';
+is fibonacci_sequence(20), 1, 'Check 20';
+is fibonacci_sequence(21), 4, 'Check 21';
+is fibonacci_sequence(22), 3, 'Check 22';
+is fibonacci_sequence(23), 3, 'Check 23';
+is fibonacci_sequence(24), 5, 'Check 24';
+is fibonacci_sequence(25), 2, 'Check 25';
+is fibonacci_sequence(26), 4, 'Check 26';
+is fibonacci_sequence(27), 4, 'Check 27';
+is fibonacci_sequence(28), 2, 'Check 28';
+is fibonacci_sequence(29), 5, 'Check 29';
+is fibonacci_sequence(30), 3, 'Check 30';
+is fibonacci_sequence(31), 3, 'Check 31';
+is fibonacci_sequence(32), 4, 'Check 32';
+is fibonacci_sequence(33), 1, 'Check 33';
+is fibonacci_sequence(34), 4, 'Check 34';
+is fibonacci_sequence(35), 4, 'Check 35';
+is fibonacci_sequence(36), 3, 'Check 36';
+is fibonacci_sequence(37), 6, 'Check 37';
+is fibonacci_sequence(38), 3, 'Check 38';
+is fibonacci_sequence(39), 5, 'Check 39';
+is fibonacci_sequence(40), 5, 'Check 40';
+is fibonacci_sequence(41), 2, 'Check 41';
+is fibonacci_sequence(42), 6, 'Check 42';
+is fibonacci_sequence(43), 4, 'Check 43';
+is fibonacci_sequence(44), 4, 'Check 44';
+is fibonacci_sequence(45), 6, 'Check 45';
+is fibonacci_sequence(46), 2, 'Check 46';
+is fibonacci_sequence(47), 5, 'Check 47';
+is fibonacci_sequence(48), 5, 'Check 48';
+is fibonacci_sequence(49), 3, 'Check 49';
+is fibonacci_sequence(50), 6, 'Check 50';
+is fibonacci_sequence(51), 3, 'Check 51';
+is fibonacci_sequence(52), 4, 'Check 52';
+is fibonacci_sequence(53), 4, 'Check 53';
+is fibonacci_sequence(54), 1, 'Check 54';
+is fibonacci_sequence(55), 5, 'Check 55';
+is fibonacci_sequence(56), 4, 'Check 56';
+is fibonacci_sequence(57), 4, 'Check 57';
+is fibonacci_sequence(58), 7, 'Check 58';
+is fibonacci_sequence(59), 3, 'Check 59';
+is fibonacci_sequence(60), 6, 'Check 60';
+is fibonacci_sequence(61), 6, 'Check 61';
+is fibonacci_sequence(62), 3, 'Check 62';
+is fibonacci_sequence(63), 8, 'Check 63';
+is fibonacci_sequence(64), 5, 'Check 64';
+is fibonacci_sequence(65), 5, 'Check 65';
diff --git a/challenge-136/james-smith/perl/ch-1.pl b/challenge-136/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..d38d98b87c
--- /dev/null
+++ b/challenge-136/james-smith/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+my @TESTS = (
+ [ [8,24], 1 ],
+ [ [26,39], 0 ],
+ [ [4,10], 1 ],
+);
+
+is( friendly(@{$_->[0]}), $_->[1] ) foreach @TESTS;
+
+done_testing();
+
+sub friendly {
+ my($a,$b) = @_;
+ ($a,$b) = ($b,$a%$b) while $b; ## Get GCD
+ $a>>=1 until $a&1; ## Remove trailing binary digits
+ return $a == 1 ? 1 : 0; ## For powers of two $a == 1
+}
+
diff --git a/challenge-136/james-smith/perl/ch-2.pl b/challenge-136/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..410c95d2ba
--- /dev/null
+++ b/challenge-136/james-smith/perl/ch-2.pl
@@ -0,0 +1,39 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+my @TESTS = (
+ [ 16, 4 ],
+ [ 9, 2 ],
+ [ 15, 2 ],
+ [ 99_999, 192 ],
+);
+my @fib = (1,2);
+
+is( fib_sum($_->[0]), $_->[1] ) foreach @TESTS;
+
+done_testing();
+
+
+sub fib_sum {
+ my $n = shift;
+ push @fib, $fib[-1]+$fib[-2] while $n > $fib[-1];
+ return sum( $n, @fib[0..@fib-2] );
+}
+
+sub sum {
+ local $_;
+ my ( $t, @n) = @_;
+ return 1 unless $t;
+ return 0 if $t < 0;
+ my $c = 0;
+ $c += sum( $t-$_, @n ) while $_ = shift @n;
+ return $c;
+}
+
diff --git a/challenge-136/jo-37/perl/ch-1.pl b/challenge-136/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..32293d1e8e
--- /dev/null
+++ b/challenge-136/jo-37/perl/ch-1.pl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl -s
+
+use v5.16;
+use Test2::V0;
+use Math::Prime::Util qw(gcd logint);
+use experimental 'signatures';
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [M N ...]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+M N ...
+ Check if M, N, ... are "friendly".
+
+EOS
+
+
+### Input and Output
+
+say 0 + !!friendly(@ARGV);
+
+
+### Implementation
+
+# I couldn't find any reference to "two friendly". Maybe Mohammad
+# created this concept?
+# There's no need to restrict the definition to two numbers.
+
+sub friendly (@n) {
+ my ($gcd, $pot) = gcd @n;
+ # Calculate the integer binary logarithm of the GCD together with
+ # its (back-)exponentiation and return "false" for a zero logarithm.
+ logint $gcd, 2, \$pot or return;
+
+ # Check if the GCD is a full power of two.
+ $gcd == $pot;
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ ok friendly(8, 24), 'example 1';
+ ok !friendly(26, 39), 'example 2';
+ ok friendly(4, 10), 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+
+ ok !friendly(2, 3), 'no common divisor';
+ ok friendly(12, 20, 28), 'three friendly';
+ ok !friendly(12, 36, 60), 'GCD not a power of two';
+ }
+
+ done_testing;
+ exit;
+}
diff --git a/challenge-136/jo-37/perl/ch-2.pl b/challenge-136/jo-37/perl/ch-2.pl
new file mode 100755
index 0000000000..25290da21b
--- /dev/null
+++ b/challenge-136/jo-37/perl/ch-2.pl
@@ -0,0 +1,107 @@
+#!/usr/bin/perl -s
+
+use v5.16;
+use Math::Prime::Util qw(todigits lucasu);
+use List::MoreUtils 'reduce_0';
+use Memoize qw(memoize flush_cache);
+use Benchmark 'cmpthese';
+use Test2::V0;
+use experimental 'signatures';
+
+our ($tests, $examples, $benchmark);
+memoize('count_fib_seq');
+
+run_tests() if $tests || $examples || $benchmark; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [-benchmark] [N]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+-benchmark
+ compare a recursive counting implementation with a brute force scan.
+
+N
+ Count Fibonacci subsequences that give a sum of N.
+
+EOS
+
+
+### Input and Output
+
+say count_fib_seq($ARGV[0]);
+
+
+### Implementation
+
+# Try Fibonacci numbers F(k) starting with the k-th element, utilizing
+# F(k) == lucas_u(1, -1, k):
+# - Return the count if if F(k) is larger than or equal to N.
+# - Add to the count the number of Fibonacci sequences that give a sum
+# of N - F(k), starting with F(k + 1) by recursion.
+# Note: The XS implementation of "lucasu" is much faster than its
+# memoizing counterpart.
+
+sub count_fib_seq ($n, $k = 2) {
+ my $count = 0;
+ while () {
+ my $fib = lucasu 1, -1, $k;
+ return $count + ($fib == $n) if $fib >= $n;
+ $count += count_fib_seq($n - $fib, ++$k);
+ }
+}
+
+# An alternative brute force approach:
+# Try all Fibonacci subsequences for a matching sum. Taking the binary
+# digits of the iterator variable as selectors for corresponding
+# Fibonacci numbers.
+# This was intended as a cross check for the counting implementation.
+
+sub scan_fib_seq ($n) {
+ my (@fib, $f) = (1, 1);
+ push @fib, $f while ($f = $fib[-2] + $fib[-1]) <= $n;
+ shift @fib;
+
+ scalar grep {
+ $n == reduce_0 {$a += $fib[$_] * $b} todigits($_, 2, @fib)
+ } 1 .. 2 ** @fib - 1;
+}
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ is count_fib_seq(16), 4, 'example 1';
+ is count_fib_seq(9), 2, 'example 2';
+ is count_fib_seq(15), 2, 'example 3';
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+
+ grep {
+ count_fib_seq($_) != scan_fib_seq($_) and !fail "$_ failed";
+ } 0 .. 100 or pass 'cross check';
+ }
+
+ SKIP: {
+ skip "benchmark" unless $benchmark;
+
+ cmpthese(0, {
+ scan => sub {scan_fib_seq(1000)},
+ count => sub {
+ flush_cache('count_fib_seq');
+ count_fib_seq(1000);
+ }
+ });
+ }
+
+ done_testing;
+ exit;
+}
diff --git a/challenge-136/perlboy1967/perl/ch-1.pl b/challenge-136/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..0fd84eef77
--- /dev/null
+++ b/challenge-136/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+=pod
+
+Perl Weekly Challenge - 136
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-136/#TASK1
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #1 › Two Friendly
+Submitted by: Mohammad S Anwar
+
+You are given 2 positive numbers, $m and $n.
+
+Write a script to find out if the given two numbers are Two Friendly.
+
+ || Two positive numbers, m and n are two friendly when gcd(m, n) = 2 ^ p where p > 0.
+ || The greatest common divisor (gcd) of a set of numbers is the largest positive number
+ || that divides all the numbers in the set without remainder.
+
+=cut
+
+use v5.16;
+use strict;
+use warnings;
+
+# Prototype
+sub gcd($$);
+
+# Unbuffered STDOUT
+$|++;
+
+use Scalar::Util qw(looks_like_number);
+
+my ($M, $N) = @ARGV;
+
+die "Please provide two positive integer numbers"
+ unless (looks_like_number($M) and $M > 0 and $M == int($M) and
+ looks_like_number($N) and $N > 0 and $N == int($N));
+
+my $gcd = gcd($M,$N);
+my $exponent = log($gcd)/log(2);
+my $isTwoFriendly = (int($exponent) == $exponent) && ($exponent > 0);
+
+printf "Input: m = %d, n = %d\n", $M, $N;
+printf "Output: %d\n", $isTwoFriendly;
+printf "Reason: gcd(%d,%d) = %d %s\n", $M, $N, $gcd,
+ ($isTwoFriendly ? sprintf(' => 2 ^ %d', $exponent) : '');
+
+
+sub gcd ($$) {
+ return 0 == $_[1] ? $_[0] : gcd($_[1], $_[0] % $_[1]);
+}
diff --git a/challenge-136/perlboy1967/perl/ch-2.pl b/challenge-136/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..06e5609d91
--- /dev/null
+++ b/challenge-136/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+
+=pod
+
+Perl Weekly Challenge - 136
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-136/#TASK2
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #2 › Fibonacci Sequence
+Submitted by: Mohammad S Anwar
+
+You are given a positive number $n.
+
+Write a script to find how many different sequences you can create using Fibonacci numbers where the sum of unique numbers in each sequence are the same as the given number.
+
+ || Fibonacci Numbers: 1,2,3,5,8,13,21,34,55,89, …
+
+NOTE: This script is a 100% copy of week 77, task 1!
+
+=cut
+
+use v5.16;
+use strict;
+use warnings;
+
+# Unbuffered STDOUT
+$|++;
+
+use Algorithm::Combinatorics qw(combinations);
+use List::Util qw(sum);
+use Memoize;
+
+# Prototypes
+sub fibonacci ($);
+sub getFibonacciNumbersSmallerN ($);
+sub findFibonacciSumSolutions ($\@\@);
+
+memoize('fibonacci');
+
+my ($N) = @ARGV;
+
+die "Input must be integer value and >= 2"
+ unless (defined $N and $N =~ m#^[1-9][0-9]*$# and $N >= 2);
+
+my @solutions;
+
+my @fib = getFibonacciNumbersSmallerN($N);
+findFibonacciSumSolutions($N, @solutions, @fib);
+
+print "Input:\n";
+printf "\t%s = %d\n\n", '$N', $N;
+
+print "Output:\n";
+if (scalar @solutions) {
+ printf "\t%d as the sum of Fibonacci numbers (%s) is same as input number.\n",
+ scalar(@solutions),
+ join(', ', map { '['.join(',',@$_).']' } @solutions);
+} else {
+ print "\tNo solution can be found.\n";
+}
+
+
+sub fibonacci ($) {
+ my ($n) = @_;
+
+ return 1 if ($n == 1 or $n == 2);
+
+ return fibonacci($n - 1) + fibonacci($n - 2);
+}
+
+
+sub getFibonacciNumbersSmallerN ($) {
+ my ($n) = @_;
+
+ my @fib;
+
+ my $i = 2;
+ my $f;
+
+ while ($f = fibonacci($i++) and $f < $n) {
+ push(@fib, $f);
+ }
+
+ return @fib;
+}
+
+
+sub findFibonacciSumSolutions($\@\@) {
+ my ($n, $arSol, $arFib) = @_;
+
+ foreach my $level (1 .. scalar @$arFib) {
+ my $iter = combinations($arFib, $level);
+ while (my $arCombi = $iter->next) {
+ push(@$arSol, $arCombi)
+ if (sum(@$arCombi) == $n);
+ }
+ }
+}
diff --git a/challenge-136/roger-bell-west/blog.txt b/challenge-136/roger-bell-west/blog.txt
new file mode 100644
index 0000000000..f7b726d2a8
--- /dev/null
+++ b/challenge-136/roger-bell-west/blog.txt
@@ -0,0 +1 @@
+https://blog.firedrake.org/archive/2021/10/Perl_Weekly_Challenge_136__Fibonacci_Friends.html
diff --git a/challenge-136/tyler-wardhaugh/clojure/README.md b/challenge-136/tyler-wardhaugh/clojure/README.md
index 203cf79b7b..d05825bedb 100644
--- a/challenge-136/tyler-wardhaugh/clojure/README.md
+++ b/challenge-136/tyler-wardhaugh/clojure/README.md
@@ -1,7 +1,7 @@
-# tw.weekly.c135
+# tw.weekly.c136
-The Weekly Challenge - #135 - Tyler Wardhaugh
+The Weekly Challenge - #136 - Tyler Wardhaugh
## Usage
@@ -9,7 +9,7 @@ Clojure ([installation instructions](https://clojure.org/guides/getting_started#
Run the project directly (shows default output from both tasks):
- $ clojure -M -m tw.weekly.c135.core
+ $ clojure -M -m tw.weekly.c136.core
# ... or ...
$ bb run both
@@ -21,13 +21,15 @@ Run the project's tests (which are samples from the task descriptions):
Run Task #1 with input
- $ clojure -M -m tw.weekly.c135.t1 N
+ $ clojure -M -m tw.weekly.c136.t1 M N
+ # ... or ...
+ $ bb run task-1 M N
Run Task #2 with input:
- $ clojure -M -m tw.weekly.c135.t2 SEDOL
+ $ clojure -M -m tw.weekly.c136.t2 N
# ... or ...
- $ bb run task-2 SEDOL
+ $ bb run task-2 N
View available tasks Babashka can run:
diff --git a/challenge-136/tyler-wardhaugh/clojure/bb.edn b/challenge-136/tyler-wardhaugh/clojure/bb.edn
index 69331331eb..2299ced5c9 100644
--- a/challenge-136/tyler-wardhaugh/clojure/bb.edn
+++ b/challenge-136/tyler-wardhaugh/clojure/bb.edn
@@ -70,7 +70,9 @@
:task (run-task :t2 *command-line-args*)}
task-2-bb {:doc "Run Task 2 (via Babashka)"
- :task (run-task-bb :t2 *command-line-args*)}
+ :task (binding [*out* *err*]
+ (println "error: can't run Task 2 via Babashka because it depends on some incompatible libraries.")
+ (System/exit 1))}
both {:doc "Run both tasks (via clojure)"
:task (do
diff --git a/challenge-136/tyler-wardhaugh/clojure/deps.edn b/challenge-136/tyler-wardhaugh/clojure/deps.edn
index 5b1400b27e..99b46a9e15 100644
--- a/challenge-136/tyler-wardhaugh/clojure/deps.edn
+++ b/challenge-136/tyler-wardhaugh/clojure/deps.edn
@@ -1,5 +1,6 @@
{:paths ["src" "resources"]
- :deps {org.clojure/clojure {:mvn/version "1.10.3"}}
+ :deps {org.clojure/clojure {:mvn/version "1.10.3"}
+ org.clojure/math.combinatorics {:mvn/version "0.1.6"}}
:aliases
{:test {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}
diff --git a/challenge-136/tyler-wardhaugh/clojure/pom.xml b/challenge-136/tyler-wardhaugh/clojure/pom.xml
index 4fb7c617a2..fbbe52d202 100644
--- a/challenge-136/tyler-wardhaugh/clojure/pom.xml
+++ b/challenge-136/tyler-wardhaugh/clojure/pom.xml
@@ -2,11 +2,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tw.weekly</groupId>
- <artifactId>tw.weekly.c135</artifactId>
+ <artifactId>tw.weekly.c136</artifactId>
<version>0.1.0-SNAPSHOT</version>
- <name>tw.weekly.c135</name>
- <description>Challenge #135</description>
- <url>https://github.com/tw.weekly/tw.weekly.c135</url>
+ <name>tw.weekly.c136</name>
+ <description>Challenge #136</description>
+ <url>https://github.com/tw.weekly/tw.weekly.c136</url>
<licenses>
<license>
<name>Eclipse Public License</name>
diff --git a/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/core.clj b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/core.clj
new file mode 100644
index 0000000000..4f1dcd8562
--- /dev/null
+++ b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/core.clj
@@ -0,0 +1,12 @@
+(ns tw.weekly.c136.core
+ (:require [tw.weekly.c136.t1 :as t1])
+ (:require [tw.weekly.c136.t2 :as t2])
+ (:gen-class))
+
+(defn -main
+ "Run all tasks"
+ [& _]
+ (println "Task #1:")
+ (t1/-main)
+ (println "\nTask #2:")
+ (t2/-main))
diff --git a/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t1.clj b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t1.clj
new file mode 100644
index 0000000000..dddde5d12f
--- /dev/null
+++ b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t1.clj
@@ -0,0 +1,26 @@
+(ns tw.weekly.c136.t1
+ (:require [clojure.edn :as edn]))
+
+;;;
+; Task description for TASK #1 › Two Friendly
+;;;
+(def DEFAULT-INPUT [8 24])
+
+(defn- power-of-2?
+ "Assuming n is a positive BigInteger, is it a power of 2?"
+ [n]
+ (= (.getLowestSetBit n) (dec (.bitLength n))))
+
+(defn two-friendly?
+ "Determine if two positive integers m and n are two friendly, that is:
+ gcd(m, n) = 2^p where p > 0."
+ [m n]
+ (when-let [gcd (.gcd (biginteger m) (biginteger n))]
+ (and (< 1 gcd) (power-of-2? gcd))))
+
+(defn -main
+ "Run Task 1 with a given input M and N, defaulting to the first example from
+ the task description."
+ [& args]
+ (let [[M N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)]
+ (println (if (two-friendly? M N) 1 0))))
diff --git a/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t2.clj b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t2.clj
new file mode 100644
index 0000000000..b9de2a6b8a
--- /dev/null
+++ b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/c136/t2.clj
@@ -0,0 +1,20 @@
+(ns tw.weekly.c136.t2
+ (:require [clojure.edn :as edn]
+ [tw.weekly.ch-1 :as c77-t1]))
+
+;;;
+; Task description for TASK #2 › Fibonacci Sequence
+;;;
+(def DEFAULT-INPUT [16])
+
+; Reuse our solution from Challenge 77, Task #2 (Fibonacci Sum)
+(defn fibo-sum-count
+ [n]
+ (count (c77-t1/fibo-sum n)))
+
+(defn -main
+ "Run Task 2 with a given input N, defaulting to the first example from the
+ task description."
+ [& args]
+ (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)]
+ (println (fibo-sum-count N))))
diff --git a/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj
new file mode 120000
index 0000000000..a4157827b9
--- /dev/null
+++ b/challenge-136/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj
@@ -0,0 +1 @@
+../../../../../../challenge-077/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj \ No newline at end of file
diff --git a/challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t1_test.clj b/challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t1_test.clj
new file mode 100644
index 0000000000..cf5b6ea6e0
--- /dev/null
+++ b/challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t1_test.clj
@@ -0,0 +1,9 @@
+(ns tw.weekly.c136.t1-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [tw.weekly.c136.t1 :refer [two-friendly?]]))
+
+(deftest examples
+ (testing "Examples from description"
+ (is (true? (two-friendly? 8 24)))
+ (is (false? (two-friendly? 26 39)))
+ (is (true? (two-friendly? 4 10)))))
diff --git a/challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t2_test.clj b/challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t2_test.clj
new file mode 100644
index 0000000000..79deae4cc8
--- /dev/null
+++ b/challenge-136/tyler-wardhaugh/clojure/test/tw/weekly/c136/t2_test.clj
@@ -0,0 +1,9 @@
+(ns tw.weekly.c136.t2-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [tw.weekly.c136.t2 :refer [fibo-sum-count]]))
+
+(deftest examples
+ (testing "Examples from description"
+ (is (= 4 (fibo-sum-count 16)))
+ (is (= 2 (fibo-sum-count 9)))
+ (is (= 2 (fibo-sum-count 15)))))
diff --git a/stats/pwc-challenge-123.json b/stats/pwc-challenge-123.json
index 1b2da70f79..4d2e3f3d5b 100644
--- a/stats/pwc-challenge-123.json
+++ b/stats/pwc-challenge-123.json
@@ -1,10 +1,206 @@
{
+ "tooltip" : {
+ "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>",
+ "followPointer" : 1,
+ "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>"
+ },
+ "xAxis" : {
+ "type" : "category"
+ },
+ "series" : [
+ {
+ "data" : [
+ {
+ "drilldown" : "Abigail",
+ "name" : "Abigail",
+ "y" : 4
+ },
+ {
+ "drilldown" : "Adam Russell",
+ "y" : 4,
+