aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2023-10-09 17:41:51 -0400
committerDave Jacoby <jacoby.david@gmail.com>2023-10-09 17:41:51 -0400
commit3836c2699de4c708b32fc6bd59770463cc00eeec (patch)
tree654684ebf0dce0eb3180ec5b711848be766b3b55
parent7cccf2f51d1a1ad5027dcdf2fb9058cd7804808f (diff)
parent3ce214ad99d99c1edcae374b6eac3c16448216c8 (diff)
downloadperlweeklychallenge-club-3836c2699de4c708b32fc6bd59770463cc00eeec.tar.gz
perlweeklychallenge-club-3836c2699de4c708b32fc6bd59770463cc00eeec.tar.bz2
perlweeklychallenge-club-3836c2699de4c708b32fc6bd59770463cc00eeec.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
-rw-r--r--challenge-235/steven-wilson/python/ch-1.py8
-rwxr-xr-xchallenge-238/e-choroba/perl/ch-1.pl17
-rwxr-xr-xchallenge-238/e-choroba/perl/ch-2.pl26
-rwxr-xr-xchallenge-238/eric-cheung/python/ch-1.py12
-rwxr-xr-xchallenge-238/eric-cheung/python/ch-2.py23
-rw-r--r--challenge-238/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-238/laurent-rosenfeld/perl/ch-1.pl17
-rw-r--r--challenge-238/laurent-rosenfeld/raku/ch-1.raku9
-rw-r--r--challenge-238/mark-anderson/raku/ch-1.raku6
-rw-r--r--challenge-238/mark-anderson/raku/ch-2.raku19
-rwxr-xr-xchallenge-238/perlboy1967/perl/ch-1.pl37
-rwxr-xr-xchallenge-238/perlboy1967/perl/ch-2.pl54
-rwxr-xr-xchallenge-238/peter-meszaros/perl/ch-1.pl55
-rwxr-xr-xchallenge-238/peter-meszaros/perl/ch-2.pl73
-rw-r--r--challenge-238/robert-dicicco/perl/ch-1.pl37
-rw-r--r--challenge-238/robert-dicicco/raku/ch-1.raku40
-rwxr-xr-xchallenge-238/ulrich-rieke/cpp/ch-1.cpp38
-rwxr-xr-xchallenge-238/ulrich-rieke/cpp/ch-2.cpp73
-rwxr-xr-xchallenge-238/ulrich-rieke/haskell/ch-1.hs5
-rwxr-xr-xchallenge-238/ulrich-rieke/haskell/ch-2.hs33
-rwxr-xr-xchallenge-238/ulrich-rieke/perl/ch-1.pl17
-rwxr-xr-xchallenge-238/ulrich-rieke/perl/ch-2.pl42
-rwxr-xr-xchallenge-238/ulrich-rieke/raku/ch-1.raku13
-rwxr-xr-xchallenge-238/ulrich-rieke/raku/ch-2.raku55
-rwxr-xr-xchallenge-238/ulrich-rieke/rust/ch-1.rs18
-rwxr-xr-xchallenge-238/ulrich-rieke/rust/ch-2.rs52
-rw-r--r--challenge-238/wlmb/blog.txt1
-rwxr-xr-xchallenge-238/wlmb/perl/ch-1.pl13
-rwxr-xr-xchallenge-238/wlmb/perl/ch-2.pl22
-rw-r--r--stats/pwc-challenge-237.json636
-rw-r--r--stats/pwc-current.json548
-rw-r--r--stats/pwc-language-breakdown-summary.json70
-rw-r--r--stats/pwc-language-breakdown.json3151
-rw-r--r--stats/pwc-leaders.json366
-rw-r--r--stats/pwc-summary-1-30.json38
-rw-r--r--stats/pwc-summary-121-150.json34
-rw-r--r--stats/pwc-summary-151-180.json118
-rw-r--r--stats/pwc-summary-181-210.json100
-rw-r--r--stats/pwc-summary-211-240.json34
-rw-r--r--stats/pwc-summary-241-270.json34
-rw-r--r--stats/pwc-summary-271-300.json90
-rw-r--r--stats/pwc-summary-31-60.json62
-rw-r--r--stats/pwc-summary-61-90.json128
-rw-r--r--stats/pwc-summary-91-120.json114
-rw-r--r--stats/pwc-summary.json64
45 files changed, 3714 insertions, 2689 deletions
diff --git a/challenge-235/steven-wilson/python/ch-1.py b/challenge-235/steven-wilson/python/ch-1.py
index 4d5a26bae5..b7cbbe1543 100644
--- a/challenge-235/steven-wilson/python/ch-1.py
+++ b/challenge-235/steven-wilson/python/ch-1.py
@@ -9,12 +9,18 @@ def remove_one(elements):
False
>>> remove_one( [2, 2, 3] )
True
+ >>> remove_one( [1, 2, 3, 1, 2, 3] )
+ False
+ >>> remove_one( [1, 2, 3, 1])
+ True
"""
remove = 0
for i in range(len(elements) - 1):
if(elements[i] > elements[i+1]):
remove += 1
- if remove == 2:
+ if (i > 0) and (i < len(elements) - 2) and (elements[i-1] > elements[i+1]):
+ remove += 1
+ if remove > 1:
return False
return True
diff --git a/challenge-238/e-choroba/perl/ch-1.pl b/challenge-238/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..108c79e992
--- /dev/null
+++ b/challenge-238/e-choroba/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub running_sum(@int) {
+ my @running_sum = shift @int;
+ push @running_sum, $running_sum[-1] + shift @int while @int;
+ return \@running_sum
+}
+
+use Test2::V0;
+plan 3;
+
+is running_sum(1, 2, 3, 4, 5), [1, 3, 6, 10, 15], 'Example 1';
+is running_sum(1, 1, 1, 1, 1), [1, 2, 3, 4, 5], 'Example 2';
+is running_sum(0, -1, 1, 2), [0, -1, 0, 2], 'Example 3';
diff --git a/challenge-238/e-choroba/perl/ch-2.pl b/challenge-238/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..9c689dc07f
--- /dev/null
+++ b/challenge-238/e-choroba/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use List::Util qw{ product };
+
+sub persistence_sort(@int) {
+ return [ sort { steps($a) <=> steps($b) || $a <=> $b } @int ]
+}
+
+sub steps($n) {
+ my $steps = 0;
+ while (length($n) > 1) {
+ my @digits = split //, $n;
+ $n = product(@digits);
+ ++$steps
+ }
+ return $steps
+}
+
+use Test2::V0;
+plan 2;
+
+is persistence_sort(15, 99, 1, 34), [1, 15, 34, 99], 'Example 1';
+is persistence_sort(50, 25, 33, 22), [22, 33, 50, 25], 'Example 2';
diff --git a/challenge-238/eric-cheung/python/ch-1.py b/challenge-238/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..940af19099
--- /dev/null
+++ b/challenge-238/eric-cheung/python/ch-1.py
@@ -0,0 +1,12 @@
+
+## arrInput = [1, 2, 3, 4, 5] ## Example 1
+## arrInput = [1, 1, 1, 1, 1] ## Example 2
+arrInput = [0, -1, 1, 2] ## Example 3
+
+arrOutput = []
+for nLoop in arrInput:
+ ## print (nLoop)
+ arrOutput.append(nLoop if len(arrOutput) == 0 else nLoop + arrOutput[-1])
+ ## print (arrOutput)
+
+print (arrOutput)
diff --git a/challenge-238/eric-cheung/python/ch-2.py b/challenge-238/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..e215581ec3
--- /dev/null
+++ b/challenge-238/eric-cheung/python/ch-2.py
@@ -0,0 +1,23 @@
+
+from numpy import prod
+
+def GetStep (nStep, nInput):
+ if nInput < 10:
+ return nStep
+ return GetStep (nStep + 1, prod([int(charLoop) for charLoop in str(nInput)]))
+
+## print (GetStep(0, 1))
+
+## arrInput = [15, 99, 1, 34] ## Example 1
+arrInput = [50, 25, 33, 22] ## Example 2
+
+arrOutput = arrInput[:]
+
+for nRow in range(0, len(arrOutput) - 1):
+ for nCol in range(nRow + 1, len(arrOutput)):
+ if GetStep (0, arrOutput[nRow]) > GetStep (0, arrOutput[nCol]) or GetStep (0, arrOutput[nRow]) == GetStep (0, arrOutput[nCol]) and arrOutput[nRow] > arrOutput[nCol]:
+ vTemp = arrOutput[nRow]
+ arrOutput[nRow] = arrOutput[nCol]
+ arrOutput[nCol] = vTemp
+
+print (arrOutput)
diff --git a/challenge-238/laurent-rosenfeld/blog.txt b/challenge-238/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..8cfb474024
--- /dev/null
+++ b/challenge-238/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+https://blogs.perl.org/users/laurent_r/2023/10/perl-weekly-challenge-238-running-sum.html
diff --git a/challenge-238/laurent-rosenfeld/perl/ch-1.pl b/challenge-238/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..6164c90358
--- /dev/null
+++ b/challenge-238/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+use feature 'say';
+
+sub running_sum {
+ my @sum = shift;
+ for my $item (@_) {
+ push @sum, $item + $sum[-1];
+ }
+ return @sum;
+}
+
+my @tests = ([<1 2 3 4 5>], [<1 1 1 1 1>], [<0 -1 1 2>]);
+for my $test (@tests) {
+ printf "%-15s => ", "@$test";
+ say join ", ", running_sum @$test;
+}
diff --git a/challenge-238/laurent-rosenfeld/raku/ch-1.raku b/challenge-238/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..aa519c8e8f
--- /dev/null
+++ b/challenge-238/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,9 @@
+sub running-sum (@in) {
+ return [\+] @in;
+}
+
+my @tests = <1 2 3 4 5>, <1 1 1 1 1>, <0 -1 1 2>;
+for @tests -> @test {
+ printf "%-15s => ", "@test[]";
+ say join ", ", running-sum @test;
+}
diff --git a/challenge-238/mark-anderson/raku/ch-1.raku b/challenge-238/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..23f7e08675
--- /dev/null
+++ b/challenge-238/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,6 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply ([\+] 1,2,3,4,5), (1,3,6,10,15);
+is-deeply ([\+] 1,1,1,1,1), (1,2,3,4,5);
+is-deeply ([\+] 0,-1,1,2), (0,-1,0,2);
diff --git a/challenge-238/mark-anderson/raku/ch-2.raku b/challenge-238/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..6422d0ea3b
--- /dev/null
+++ b/challenge-238/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/env raku
+use Test;
+
+is persistence(277777788888899), 11;
+is-deeply persistence(39,999,4,9876), (4,9876,39,999);
+is-deeply persistence(1,27,90), (1,90,27);
+is-deeply persistence(868,769,976,679), (679,769,868,976);
+is-deeply persistence(15,99,1,34), (1,15,34,99);
+is-deeply persistence(50,25,33,22), (22,33,50,25);
+
+multi persistence(+@a)
+{
+ @a.sort: { persistence($_), $_ }
+}
+
+multi persistence($_ is copy)
+{
+ sum do while .chars > 1 { $_ = [*] .comb; 1 }
+}
diff --git a/challenge-238/perlboy1967/perl/ch-1.pl b/challenge-238/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..159ba18e4b
--- /dev/null
+++ b/challenge-238/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 238
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-238
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Running Sum
+Submitted by: Mohammad S Anwar
+
+You are given an array of integers.
+
+Write a script to return the running sum of the given array. The running
+sum can be calculated as sum[i] = num[0] + num[1] + ... + num[i].
+
+=cut
+
+use v5.32;
+use common::sense;
+use feature 'signatures';
+
+use Test::More;
+use Test::Deep qw(cmp_deeply);
+
+
+sub runningSum (@numbers) {
+ my $s = 0;
+ return map { $s += $_; } @numbers;
+}
+
+cmp_deeply([runningSum(1,2,3,4,5)],[1,3,6,10,15]);
+cmp_deeply([runningSum(1,1,1,1,1)],[1,2,3,4,5]);
+cmp_deeply([runningSum(0,-1,1,2)],[0,-1,0,2]);
+
+done_testing;
diff --git a/challenge-238/perlboy1967/perl/ch-2.pl b/challenge-238/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..c1e3b5be91
--- /dev/null
+++ b/challenge-238/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,54 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 238
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-238
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Persistence Sort
+Submitted by: Mohammad S Anwar
+
+You are given an array of positive integers.
+
+Write a script to sort the given array in increasing order with respect
+to the count of steps required to obtain a single-digit number by multiplying
+its digits recursively for each array element. If any two numbers have the
+same count of steps, then print the smaller number first.
+
+=cut
+
+use v5.32;
+use common::sense;
+use feature 'signatures';
+
+use Test::More;
+use Test::Deep qw(cmp_deeply);
+
+use List::MoreUtils qw(slide);
+use Memoize;
+
+memoize 'cnt_steps';
+
+sub cnt_steps($i) {
+ my $n = 0;
+
+ while (1) {
+ my @d = split(//,$i);
+ last if (@d == 1);
+ $i = slide { $a * $b } @d;
+ $n++;
+ }
+
+ return $n;
+}
+
+sub persistenceSort (@numbers) {
+ sort { cnt_steps($a) <=> cnt_steps($b) || $a <=> $b} @numbers;
+}
+
+cmp_deeply([persistenceSort(15,99,1,34)],[1,15,34,99]);
+cmp_deeply([persistenceSort(50,25,33,22)],[22,33,50,25]);
+
+done_testing;
diff --git a/challenge-238/peter-meszaros/perl/ch-1.pl b/challenge-238/peter-meszaros/perl/ch-1.pl
new file mode 100755
index 0000000000..b80ae4211a
--- /dev/null
+++ b/challenge-238/peter-meszaros/perl/ch-1.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+#
+# You are given an array of integers.
+#
+# Write a script to return the running sum of the given array. The running sum
+# can be calculated as sum[i] = num[0] + num[1] + …. + num[i].
+# Example 1
+#
+# Input: @int = (1, 2, 3, 4, 5)
+# Output: (1, 3, 6, 10, 15)
+#
+# Example 2
+#
+# Input: @int = (1, 1, 1, 1, 1)
+# Output: (1, 2, 3, 4, 5)
+#
+# Example 3
+#
+# Input: @int = (0, -1, 1, 2)
+# Output: (0, -1, 0, 2)
+#
+
+use strict;
+use warnings;
+use Test::More;
+use Data::Dumper;
+
+my $cases = [
+ [1, 2, 3, 4, 5],
+ [1, 1, 1, 1, 1],
+ [0, -1, 1, 2],
+];
+
+sub running_sum
+{
+ my $l = shift;
+
+ my @ret;
+ my $sum = 0;
+ for my $v (@$l) {
+ $sum += $v;
+ push @ret, $sum;
+ }
+
+ return \@ret;
+}
+
+is_deeply(running_sum($cases->[0]), [1, 3, 6, 10, 15], '[1, 2, 3, 4, 5]');
+is_deeply(running_sum($cases->[1]), [1, 2, 3, 4, 5], '[1, 1, 1, 1, 1]');
+is_deeply(running_sum($cases->[2]), [0, -1, 0, 2], '[0, -1, 1, 2]');
+done_testing();
+
+exit 0;
+
+
diff --git a/challenge-238/peter-meszaros/perl/ch-2.pl b/challenge-238/peter-meszaros/perl/ch-2.pl
new file mode 100755
index 0000000000..0236251275
--- /dev/null
+++ b/challenge-238/peter-meszaros/perl/ch-2.pl
@@ -0,0 +1,73 @@
+#!/usr/bin/env perl
+#
+# You are given an array of positive integers.
+#
+# Write a script to sort the given array in increasing order with respect to
+# the count of steps required to obtain a single-digit number by multiplying its
+# digits recursively for each array element. If any two numbers have the same
+# count of steps, then print the smaller number first.
+# Example 1
+#
+# Input: @int = (15, 99, 1, 34)
+# Output: (1, 15, 34, 99)
+#
+# 15 => 1 x 5 => 5 (1 step)
+# 99 => 9 x 9 => 81 => 8 x 1 => 8 (2 steps)
+# 1 => 0 step
+# 34 => 3 x 4 => 12 => 1 x 2 => 2 (2 steps)
+#
+# Example 2
+#
+# Input: @int = (50, 25, 33, 22)
+# Output: (22, 33, 50, 25)
+#
+# 50 => 5 x 0 => 0 (1 step)
+# 25 => 2 x 5 => 10 => 1 x 0 => 0 (2 steps)
+# 33 => 3 x 3 => 6 (1 step)
+# 22 => 2 x 2 => 4 (1 step)
+#
+
+use strict;
+use warnings;
+use Test::More;
+use Data::Dumper;
+
+my $cases = [
+ [15, 99, 1, 34],
+ [50, 25, 33, 22],
+];
+
+sub count_steps
+{
+ my $n = shift;
+
+ my $steps = 0;
+ while(length($n)> 1) {
+ ++$steps;
+ my @n = split('', $n);
+ $n = 1;
+ $n *= $_ for @n;
+ }
+ return $steps;
+}
+
+sub persistence_sort
+{
+ my $l = shift;
+
+ my @steps = map { count_steps($_) } @$l;
+
+ my @ord = sort { if ($steps[$a] == $steps[$b]) {
+ return $l->[$a] <=> $l->[$b];
+ }
+ return $steps[$a] <=> $steps[$b]
+ } (0 .. $#$l);
+
+ return [$l->@[@ord]];
+}
+
+is_deeply(persistence_sort($cases->[0]), [1, 15, 34, 99], '[15, 99, 1, 34]');
+is_deeply(persistence_sort($cases->[1]), [22, 33, 50, 25], '[50, 25, 33, 22]');
+done_testing();
+
+exit 0;
diff --git a/challenge-238/robert-dicicco/perl/ch-1.pl b/challenge-238/robert-dicicco/perl/ch-1.pl
new file mode 100644
index 0000000000..a5729284dc
--- /dev/null
+++ b/challenge-238/robert-dicicco/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+=begin comment
+AUTHOR: Robert DiCicco
+DATE : 2023-10-09
+Challenge 238 Task 01 Running Sum ( Perl )
+=cut
+
+use v5.38;
+
+my @myints = ([1, 2, 3, 4, 5],[1, 1, 1, 1, 1],[0, -1, 1, 2]);
+
+for my $mints (@myints) {
+ my $sum = 0;
+ my @out = ();
+ say "Input: \@int = [@$mints]";
+ for my $i (@$mints) {
+ push(@out, $i + $sum);
+ $sum += $i;
+ }
+ say "Output: [@out]\n";
+}
+
+=begin comment
+SAMPLE OUTPUT
+perl .\RunningSum.pl
+
+Input: @int = [1 2 3 4 5]
+Output: [1 3 6 10 15]
+
+Input: @int = [1 1 1 1 1]
+Output: [1 2 3 4 5]
+
+Input: @int = [0 -1 1 2]
+Output: [0 -1 0 2]
+=cut
+
+
diff --git a/challenge-238/robert-dicicco/raku/ch-1.raku b/challenge-238/robert-dicicco/raku/ch-1.raku
new file mode 100644
index 0000000000..4e9944e28d
--- /dev/null
+++ b/challenge-238/robert-dicicco/raku/ch-1.raku
@@ -0,0 +1,40 @@
+#!/usr/bin/env raku
+
+=begin comment
+---------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-10-09
+Challenge 238 Task 01 Running Sum ( Raku )
+---------------------------------
+=end comment
+
+my @myints = ([1, 2, 3, 4, 5],[1, 1, 1, 1, 1],[0, -1, 1, 2]);
+
+for (@myints) -> @mints {
+ my $sum = 0;
+ my @out = ();
+ say "Input: \@int = ", @mints;
+ for (@mints) -> $i {
+ @out.push($i + $sum);
+ $sum += $i;
+ }
+ say "Output: ",@out,"\n";
+}
+
+=begin comment
+---------------------------------
+SAMPLE OUTPUT
+raku .\RunningSum.rk
+
+Input: @int = [1 2 3 4 5]
+Output: [1 3 6 10 15]
+
+Input: @int = [1 1 1 1 1]
+Output: [1 2 3 4 5]
+
+Input: @int = [0 -1 1 2]
+Output: [0 -1 0 2]
+---------------------------------
+=end comment
+
+
diff --git a/challenge-238/ulrich-rieke/cpp/ch-1.cpp b/challenge-238/ulrich-rieke/cpp/ch-1.cpp
new file mode 100755
index 0000000000..255523fb1f
--- /dev/null
+++ b/challenge-238/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,38 @@
+#include <vector>
+#include <string>
+#include <iostream>
+
+std::vector<std::string> split( const std::string & startline ,
+ const std::string & sep ) {
+ std::vector<std::string> separated ;
+ std::string::size_type start { 0 } ;
+ std::string::size_type pos ;
+ do {
+ pos = startline.find_first_of( sep , start ) ;
+ separated.push_back( startline.substr(start , pos - start )) ;
+ start = pos + 1 ;
+ } while ( pos != std::string::npos ) ;
+ return separated ;
+}
+
+int main( ) {
+ std::cout << "Enter some integers, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> numberstrings( split( line , " " ) ) ;
+ std::vector<int> numbers ;
+ for ( auto s : numberstrings )
+ numbers.push_back( std::stoi( s ) ) ;
+ std::vector<int> result ;
+ int current_sum = 0 ;
+ int size = numbers.size( ) ;
+ for ( int i = 0 ; i < size ; i++ ) {
+ current_sum += numbers[ i ] ;
+ result.push_back( current_sum ) ;
+ }
+ std::cout << "( " ;
+ for ( int i : result )
+ std::cout << i << " " ;
+ std::cout << ")\n" ;
+ return 0 ;
+}
diff --git a/challenge-238/ulrich-rieke/cpp/ch-2.cpp b/challenge-238/ulrich-rieke/cpp/ch-2.cpp
new file mode 100755
index 0000000000..695c38c7c1
--- /dev/null
+++ b/challenge-238/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,73 @@
+#include <vector>
+#include <string>
+#include <algorithm>
+#include <iostream>
+#include <numeric>
+
+std::vector<std::string> split( const std::string & startline ,
+ const std::string & sep ) {
+ std::vector<std::string> separated ;
+ std::string::size_type start { 0 } ;
+ std::string::size_type pos ;
+ do {
+ pos = startline.find_first_of( sep , start ) ;
+ separated.push_back( startline.substr(start , pos - start )) ;
+ start = pos + 1 ;
+ } while ( pos != std::string::npos ) ;
+ return separated ;
+}
+
+std::vector<int> decompose( int number ) {
+ std::vector<int> digits ;
+ while ( number != 0 ) {
+ int remainder = number % 10 ;
+ digits.push_back( remainder ) ;
+ number /= 10 ;
+ }
+ return digits ;
+}
+
+int findSteps( int number ) {
+ if ( number < 10 )
+ return 0 ;
+ else {
+ int steps = 1 ;
+ std::vector<int> digits ( decompose( number ) ) ;
+ int product = std::accumulate( digits.begin( ) , digits.end( ) ,
+ 1 , std::multiplies<int>( ) ) ;
+ while ( product > 9 ) {
+ steps++ ;
+ digits = decompose( product ) ;
+ product = std::accumulate( digits.begin( ) , digits.end( ) ,
+ 1 , std::multiplies<int>( ) ) ;
+ }
+ return steps ;
+ }
+}
+
+bool mySorter( int a , int b ) {
+ int steps1 = findSteps( a ) ;
+ int steps2 = findSteps( b ) ;
+ if ( steps1 != steps2 )
+ return steps1 < steps2 ;
+ else
+ return a < b ;
+}
+
+int main( ) {
+ std::cout << "Enter some positive integers, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> numberstrings( split( line , " " ) ) ;
+ std::vector<int> numbers ;
+ for ( auto s : numberstrings )
+ numbers.push_back( std::stoi( s ) ) ;
+ std::sort( numbers.begin( ) , numbers.end( ) , []( int a , int b ) {
+ return mySorter( a , b ) ; } ) ;
+ std::cout << "(" ;
+ for ( int i : numbers ) {
+ std::cout << i << " " ;
+ }
+ std::cout << ")\n" ;
+ return 0 ;
+}
diff --git a/challenge-238/ulrich-rieke/haskell/ch-1.hs b/challenge-238/ulrich-rieke/haskell/ch-1.hs
new file mode 100755
index 0000000000..35d2766786
--- /dev/null
+++ b/challenge-238/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,5 @@
+module Challenge238
+ where
+
+solution :: [Int] -> [Int]
+solution list = map (\n -> sum $ take n list ) [1..length list]
diff --git a/challenge-238/ulrich-rieke/haskell/ch-2.hs b/challenge-238/ulrich-rieke/haskell/ch-2.hs
new file mode 100755
index 0000000000..7c9b38a720
--- /dev/null
+++ b/challenge-238/ulrich-rieke/haskell/ch-2.hs
@@ -0,0 +1,33 @@
+module Challenge238_2
+ where
+import Data.Char ( digitToInt )
+import Data.List ( sortBy )
+
+decompose :: Int -> [Int]
+decompose = map digitToInt . show
+
+findSteps :: Int -> Int
+findSteps n
+ |n < 10 = 0
+ |otherwise = fst $ until ( ( < 10 ) . snd ) action ( 0 , n )
+ where
+ action :: (Int , Int ) -> (Int , Int )
+ action ( count , d ) = ( count + 1 , product $ decompose d )
+
+mySorter :: Int -> Int -> Ordering
+mySorter d1 d2
+ |st1 /= st2 = compare st1 st2
+ |otherwise = compare d1 d2
+ where
+ st1 = findSteps d1
+ st2 = findSteps d2
+
+solution :: [Int] -> [Int]
+solution = sortBy mySorter
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some positive integers , separated by blanks!"
+ numberstrings <- getLine
+ let numbers = map read $ words numberstrings
+ print $ solution numbers
diff --git a/challenge-238/ulrich-rieke/perl/ch-1.pl b/challenge-238/ulrich-rieke/perl/ch-1.pl
new file mode 100755
index 0000000000..e53dec077d
--- /dev/null
+++ b/challenge-238/ulrich-rieke/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter some integers, separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s/ , $line ) ;
+my $len = scalar( @numbers ) ;
+my $current_sum = 0 ;
+my @result ;
+for my $i (0..$len - 1 ) {
+ $current_sum += $numbers[ $i ] ;
+ push @result , $current_sum ;
+}
+say "(" . join( ',' , @result ) . ")" ;
diff --git a/challenge-238/ulrich-rieke/perl/ch-2.pl b/challenge-238/ulrich-rieke/perl/ch-2.pl
new file mode 100755
index 0000000000..2e11c42b1d
--- /dev/null
+++ b/