aboutsummaryrefslogtreecommitdiff
path: root/challenge-261
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-03-18 13:26:14 -0400
committerGitHub <noreply@github.com>2024-03-18 13:26:14 -0400
commit4e3f2749e5e6a4c4e9c53ffd5a3dde78204efb0e (patch)
tree2e2743718c62dd4698210bb4b03617d0a8d96963 /challenge-261
parent9e7e80939c8a0ae12ace548d7b9efb43b32ec4c3 (diff)
parentb91a4623cd4c2b51f779f59b53310a0bd745f03f (diff)
downloadperlweeklychallenge-club-4e3f2749e5e6a4c4e9c53ffd5a3dde78204efb0e.tar.gz
perlweeklychallenge-club-4e3f2749e5e6a4c4e9c53ffd5a3dde78204efb0e.tar.bz2
perlweeklychallenge-club-4e3f2749e5e6a4c4e9c53ffd5a3dde78204efb0e.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-261')
-rw-r--r--challenge-261/ash/raku/ch-1.raku19
-rw-r--r--challenge-261/ash/raku/ch-2.raku20
-rwxr-xr-xchallenge-261/e-choroba/perl/ch-1.pl17
-rwxr-xr-xchallenge-261/e-choroba/perl/ch-2.pl15
-rwxr-xr-xchallenge-261/eric-cheung/python/ch-1.py13
-rwxr-xr-xchallenge-261/eric-cheung/python/ch-2.py18
-rwxr-xr-xchallenge-261/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-261/feng-chang/raku/ch-2.raku7
-rwxr-xr-xchallenge-261/feng-chang/raku/test.raku25
-rw-r--r--challenge-261/mark-anderson/blog-2.md132
-rw-r--r--challenge-261/mark-anderson/raku/ch-1.raku12
-rw-r--r--challenge-261/mark-anderson/raku/ch-2.raku10
-rw-r--r--challenge-261/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-261/peter-campbell-smith/perl/ch-1.pl37
-rwxr-xr-xchallenge-261/peter-campbell-smith/perl/ch-2.pl32
-rwxr-xr-xchallenge-261/peter-meszaros/perl/ch-1.pl74
-rwxr-xr-xchallenge-261/peter-meszaros/perl/ch-2.pl72
-rwxr-xr-xchallenge-261/ulrich-rieke/cpp/ch-1.cpp30
-rwxr-xr-xchallenge-261/ulrich-rieke/cpp/ch-2.cpp35
-rwxr-xr-xchallenge-261/ulrich-rieke/haskell/ch-1.hs17
-rwxr-xr-xchallenge-261/ulrich-rieke/haskell/ch-2.hs13
-rwxr-xr-xchallenge-261/ulrich-rieke/perl/ch-1.pl13
-rwxr-xr-xchallenge-261/ulrich-rieke/perl/ch-2.pl17
-rwxr-xr-xchallenge-261/ulrich-rieke/raku/ch-1.raku8
-rwxr-xr-xchallenge-261/ulrich-rieke/raku/ch-2.raku13
-rwxr-xr-xchallenge-261/ulrich-rieke/rust/ch-1.rs27
-rwxr-xr-xchallenge-261/ulrich-rieke/rust/ch-2.rs22
-rw-r--r--challenge-261/wlmb/blog.txt1
-rwxr-xr-xchallenge-261/wlmb/perl/ch-1.pl13
-rwxr-xr-xchallenge-261/wlmb/perl/ch-2.pl15
-rw-r--r--challenge-261/zapwai/c/ch-1.c29
-rw-r--r--challenge-261/zapwai/c/ch-2.c26
-rw-r--r--challenge-261/zapwai/javascript/ch-1.js25
-rw-r--r--challenge-261/zapwai/javascript/ch-2.js22
-rw-r--r--challenge-261/zapwai/perl/ch-1.pl15
-rw-r--r--challenge-261/zapwai/perl/ch-2.pl19
-rw-r--r--challenge-261/zapwai/python/ch-1.py12
-rw-r--r--challenge-261/zapwai/python/ch-2.py14
-rw-r--r--challenge-261/zapwai/rust/ch-1.rs26
-rw-r--r--challenge-261/zapwai/rust/ch-2.rs21
40 files changed, 810 insertions, 132 deletions
diff --git a/challenge-261/ash/raku/ch-1.raku b/challenge-261/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..1c6a73c9ac
--- /dev/null
+++ b/challenge-261/ash/raku/ch-1.raku
@@ -0,0 +1,19 @@
+# Solution to the Task 1 of The Weekly Challenge 261
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-261/#TASK1
+
+# Test run:
+# $ raku ch-1.raku
+# 36
+# 9
+# 0
+
+my @tests =
+ (1, 2, 3, 45),
+ (1, 12, 3),
+ (1, 2, 3, 4);
+
+for @tests -> @test {
+ my $sum = [+] @test;
+ my $dig = [+]((@test.map: *.comb).flat);
+ say ($dig - $sum).abs;
+}
diff --git a/challenge-261/ash/raku/ch-2.raku b/challenge-261/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..6864850b42
--- /dev/null
+++ b/challenge-261/ash/raku/ch-2.raku
@@ -0,0 +1,20 @@
+# Solution to the Task 2 of The Weekly Challenge 261
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-261/#TASK2
+
+# Test run:
+# $ raku ch-2.raku
+# 24
+# 8
+# 2
+
+my @tests =
+ ((5,3,6,1,12), 3),
+ ((1,2,4,3), 1),
+ ((5,6,7), 2);
+
+for @tests -> (@ints, $start is copy) {
+ my $ints = @ints.Bag;
+
+ $start *= 2 while $ints{$start};
+ say $start;
+}
diff --git a/challenge-261/e-choroba/perl/ch-1.pl b/challenge-261/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..7d99202d5e
--- /dev/null
+++ b/challenge-261/e-choroba/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use List::Util qw{ sum };
+
+sub element_digit_sum(@ints) {
+ abs(sum(@ints) - sum(map { split // } @ints))
+}
+
+use Test::More tests => 4;
+
+is element_digit_sum(1, 2, 3, 45), 36, 'Example 1';
+is element_digit_sum(1, 12, 3), 9, 'Example 2';
+is element_digit_sum(1, 2, 3, 4), 0, 'Example 3';
+is element_digit_sum(236, 416, 336, 350), 1296, 'Example 4';
diff --git a/challenge-261/e-choroba/perl/ch-2.pl b/challenge-261/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..2cca2ac3f6
--- /dev/null
+++ b/challenge-261/e-choroba/perl/ch-2.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub multiple_by_two($start, @ints) {
+ $start *= 2 while grep $_ == $start, @ints;
+ return $start
+}
+
+use Test::More tests => 3;
+
+is multiple_by_two(3, 5, 3, 6, 1, 12), 24, 'Example 1';
+is multiple_by_two(1, 1, 2, 4, 3), 8, 'Example 2';
+is multiple_by_two(2, 5, 6, 7), 2, 'Example 3';
diff --git a/challenge-261/eric-cheung/python/ch-1.py b/challenge-261/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..348279526f
--- /dev/null
+++ b/challenge-261/eric-cheung/python/ch-1.py
@@ -0,0 +1,13 @@
+
+## arrInt = [1, 2, 3, 45] ## Example 1
+## arrInt = [1, 12, 3] ## Example 2
+## arrInt = [1, 2, 3, 4] ## Example 3
+arrInt = [236, 416, 336, 350] ## Example 4
+
+arrSplit = []
+for nLoop in arrInt:
+ arrSplit = arrSplit + [int(elem) for elem in str(nLoop)]
+
+## print (sum(arrInt))
+## print (sum(arrSplit))
+print (abs(sum(arrInt) - sum(arrSplit)))
diff --git a/challenge-261/eric-cheung/python/ch-2.py b/challenge-261/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..a275000b69
--- /dev/null
+++ b/challenge-261/eric-cheung/python/ch-2.py
@@ -0,0 +1,18 @@
+
+## Example 1
+## arrInt = [5, 3, 6, 1, 12]
+## nStart = 3
+
+## Example 2
+## arrInt = [1, 2, 4, 3]
+## nStart = 1
+
+## Example 3
+arrInt = [5, 6, 7]
+nStart = 2
+
+nFinal = nStart
+while nFinal in arrInt:
+ nFinal = nFinal * 2
+
+print (nFinal)
diff --git a/challenge-261/feng-chang/raku/ch-1.raku b/challenge-261/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..b913f2f35c
--- /dev/null
+++ b/challenge-261/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.sum - @intsĀ».combĀ».sum.sum;
diff --git a/challenge-261/feng-chang/raku/ch-2.raku b/challenge-261/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..fbb2ac591f
--- /dev/null
+++ b/challenge-261/feng-chang/raku/ch-2.raku
@@ -0,0 +1,7 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+my $start = @ints.pop;
+$start *= 2 while @ints.grep($start);
+put $start;
diff --git a/challenge-261/feng-chang/raku/test.raku b/challenge-261/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..d78a96d7db
--- /dev/null
+++ b/challenge-261/feng-chang/raku/test.raku
@@ -0,0 +1,25 @@
+#!/bin/env raku
+
+# The Weekly Challenge 261
+use Test;
+
+sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) {
+ my ($expect, $assertion) = @input.splice(*-2, 2);
+ my $p = run $script, |@input, :out;
+ if $deeply {
+ is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion;
+ } else {
+ is $p.out.slurp(:close).chomp, $expect, $assertion;
+ }
+}
+
+# Task 1, Element Digit Sum
+pwc-test './ch-1.raku', <1 2 3 45>, 36, 'Element Digit Sum: (1,2,3,45) => 36';
+pwc-test './ch-1.raku', <1 12 3>, 9, 'Element Digit Sum: (1,12,3) => 9';
+pwc-test './ch-1.raku', <1 2 3 4>, 0, 'Element Digit Sum: (1,2,3,4) => 0';
+pwc-test './ch-1.raku', <236 416 336 350>, 1296, 'Element Digit Sum: (236, 416, 336, 350) => 1296';
+
+# Task 2, Multiply by Two
+pwc-test './ch-2.raku', <5 3 6 1 12>, 3, 24, 'Multiply by Two: @ints=(5,3,6,1,12), $start=3 => 24';
+pwc-test './ch-2.raku', <1 2 4 3>, 1, 8, 'Multiply by Two: @ints=(1,2,4,3), $start=1 => 8';
+pwc-test './ch-2.raku', <5 6 7>, 2, 2, 'Multiply by Two: @ints=(5,6,7), $start=2 => 2';
diff --git a/challenge-261/mark-anderson/blog-2.md b/challenge-261/mark-anderson/blog-2.md
deleted file mode 100644
index 55b5699cf5..0000000000
--- a/challenge-261/mark-anderson/blog-2.md
+++ /dev/null
@@ -1,132 +0,0 @@
-# Weekly Challenge #260
-
-### Task 2: Dictionary Rank
-**Submitted by: Mark Anderson**
-
-You are given a word, ```$word```.
-
-Write a script to compute the dictionary rank of the given word.
-
-#### Example 1
-```
-Input: $word = 'CAT'
-Output: 3
-
-All possible combinations of the letters:
-CAT, CTA, ATC, TCA, ACT, TAC
-
-Arrange them in alphabetical order:
-ACT, ATC, CAT, CTA, TAC, TCA
-
-CAT is the 3rd in the list.
-Therefore the dictionary rank of CAT is 3.
-```
-
-#### Example 2
-```
-Input: $word = 'GOOGLE'
-Output: 88
-```
-
-#### Example 3
-```
-Input: $word = 'SECRET'
-Output: 255
-```
-
----
-
-### Solution
-
-One approach is to create all permutations, sort them, and find the index of ```$word```.
-
-This is fine for short words but there's a better solution for long words.
-
-There are numerous videos on youtube explaining the algorithm - I think this a good one [https://www.youtube.com/watch?v=-MpL0X3AHAs](https://www.youtube.com/watch?v=-MpL0X3AHAs)
-
-Here's the gist of the algorithm:
-
-1. Find the rank of each letter.
-
- ```
- G O O G L E
- 1 3 3 1 2 0
- ```
-
-2. For each letter, find the number of letters to its right that have a lower rank.
-
- ```
- G O O G L E
- 1 3 3 1 1 0
- ```
-
-3. For each letter, take the number of repeating letters from that letter to the end of the string.
- Take the factorial of each result and multiply them together.
-
- ```
- G O O G L E
- 2!*2! 2! 1! 1! 1! 1!
- ```
-
- Starting with the first letter, there are 2 Gs and 2 Os so we end up with 2!*2!.
- The next letter is O. From that letter to the end of the string there is just the repeating O so we end up with 2!
- and so on.
-
-4. Take the terms from step 2 and divide them by the terms from step 3.
-
- ```
- G O O G L E
- 1/4 3/2 3/1 1/1 1/1 0/1
- ```
-
-5. Create the sequence ```$word```.end...0 and take the factorial of each term.
-
- ```
- G O O G L E
- 5! 4! 3! 2! 1! 0!
- ```
-
-6. Multipy the terms from step 4 with the terms from step 5.
-
- ```
- G O O G L E
- 120/4 (3*24)/2 3*6 1*2 1*1 0*1
- ```
-
-7. Sum the terms from step 6 and add 1 for a result of 88.
- ```
- G O O G L E
- 30 + 36 + 18 + 2 + 1 + 0 + 1 = 88
- ```
-### My translation to Raku:
-
-```
-#!/usr/bin/env raku
-use experimental :cached;
-
-say rank('google');
-
-sub postfix:<!>($n) is cached { [*] 1..$n }
-
-sub rank($word)
-{
- my @w = $word.comb;
- my @ranks = @w.sort.squish.antipairs.Map{@w};
- my $bag = @ranks.BagHash;
-
- my @n = gather for @ranks -> $r
- {
- my @less-than = $bag.keys.grep(* < $r);
- take ([+] $bag{@less-than}) / ([*] $bag.values>>!);
- $bag{$r}--
- }
-
- 1 + [+] @n Z* (@ranks.end...0)>>!
-}
-```
-
-[The full program.](https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-260/mark-anderson/raku/ch-2.raku)
-
-Thank you for reading my solution to the [Weekly Challenge #260 Task #2.](https://theweeklychallenge.org/blog/perl-weekly-challenge-260/)
-
-*-Mark Anderson*
diff --git a/challenge-261/mark-anderson/raku/ch-1.raku b/challenge-261/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..c1144ce45b
--- /dev/null
+++ b/challenge-261/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/usr/bin/env raku
+use Test;
+
+is element-digit-sum(1,2,3,45), 36;
+is element-digit-sum(1,12,3), 9;
+is element-digit-sum(1,2,3,4), 0;
+is element-digit-sum(236,416,336,350), 1296;
+
+sub element-digit-sum(+@ints)
+{
+ abs ([+] @ints) - [+] @ints.comb(/<digit>/)
+}
diff --git a/challenge-261/mark-anderson/raku/ch-2.raku b/challenge-261/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..8254214c62
--- /dev/null
+++ b/challenge-261/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+use Test;
+
+is multiply-by-two([5,3,6,1,12], 3), 24;
+is multiply-by-two([1,2,4,3], 1), 8;
+is multiply-by-two([5,6,7], 2), 2;
+
+multi multiply-by-two(@i, $s) { samewith(@i.BagHash, $s) }
+multi multiply-by-two($b, $s) { return $s }
+multi multiply-by-two($b, $s where ?$b{$s}) { $b{(0..$s)}:delete; samewith($b, $s*2) }
diff --git a/challenge-261/peter-campbell-smith/blog.txt b/challenge-261/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..292afaaa8c
--- /dev/null
+++ b/challenge-261/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+http://ccgi.campbellsmiths.force9.co.uk/challenge/261
diff --git a/challenge-261/peter-campbell-smith/perl/ch-1.pl b/challenge-261/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..d7d2b79ee1
--- /dev/null
+++ b/challenge-261/peter-campbell-smith/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-03-18
+use utf8; # Week 261 - task 1 - Element digit sum
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+my (@ints, $j);
+
+element_digit_sum(1, 2, 3, 45);
+element_digit_sum(1, 12, 3);
+element_digit_sum(1, 2, 3, 4);
+element_digit_sum(236, 416, 336, 350);
+
+# longer random example
+for $j (0 .. 49) {
+ $ints[$j] = int(rand(1000));
+}
+element_digit_sum(@ints);
+
+sub element_digit_sum {
+
+ my (@ints, $digit_sum, $element_sum, $difference);
+
+ # calculate sums
+ @ints = @_;
+ $element_sum += $_ for @ints;
+ $digit_sum += $_ for split('', join('', @ints));
+
+ # calculate difference
+ $difference = abs($element_sum - $digit_sum);
+
+ say qq[\nInput: \@ints = (] . join(', ', @ints) . qq[)\n] .
+ qq[Output: $difference (element sum = $element_sum, digit sum = $digit_sum)];
+}
diff --git a/challenge-261/peter-campbell-smith/perl/ch-2.pl b/challenge-261/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..0995b67779
--- /dev/null
+++ b/challenge-261/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-03-18
+use utf8; # Week 261 - task 2 - Multiply by 2
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+multiply_by_2([5, 3, 6, 1, 12], 3);
+multiply_by_2([1, 2, 4, 3], 1);
+multiply_by_2([5, 6, 7], 2);
+multiply_by_2([64, 256, 4, 64, 128, 2, 16, 32, 8], 2);
+
+sub multiply_by_2 {
+
+ my (@ints, $start, $string);
+
+ # initialise
+ @ints = @{$_[0]};
+ $start = $_[1];
+
+ # join @ints as string
+ $string = ',' . join(',', @ints) . ',';
+
+ # search string as per task
+ $start *= 2 while ($string =~ m|,$start,|);
+
+ say qq[\nInput: \@ints = (] . join(', ', @ints) .
+ qq[}, \$start = $_[1]];
+ say qq[Output: $start];
+}
diff --git a/challenge-261/peter-meszaros/perl/ch-1.pl b/challenge-261/peter-meszaros/perl/ch-1.pl
new file mode 100755
index 0000000000..976027a7f6
--- /dev/null
+++ b/challenge-261/peter-meszaros/perl/ch-1.pl
@@ -0,0 +1,74 @@
+#!/usr/bin/env perl
+#
+#
+# You are given an array of integers, @ints.
+#
+# Write a script to evaluate the absolute difference between element and digit
+# sum of the given array.
+# Example 1
+#
+# Input: @ints = (1,2,3,45)
+# Output: 36
+#
+# Element Sum: 1 + 2 + 3 + 45 = 51
+# Digit Sum: 1 + 2 + 3 + 4 + 5 = 15
+# Absolute Difference: | 51 - 15 | = 36
+#
+# Example 2
+#
+# Input: @ints = (1,12,3)
+# Output: 9
+#
+# Element Sum: 1 + 12 + 3 = 16
+# Digit Sum: 1 + 1 + 2 + 3 = 7
+# Absolute Difference: | 16 - 7 | = 9
+#
+# Example 3
+#
+# Input: @ints = (1,2,3,4)
+# Output: 0
+#
+# Element Sum: 1 + 2 + 3 + 4 = 10
+# Digit Sum: 1 + 2 + 3 + 4 = 10
+# Absolute Difference: | 10 - 10 | = 0
+#
+# Example 4
+#
+# Input: @ints = (236, 416, 336, 350)
+# Output: 1296
+#
+
+use strict;
+use warnings;
+use Test2::V0 -no_srand => 1;
+use Data::Dumper;
+
+my $cases = [
+ [1, 2, 3, 45],
+ [1, 12, 3],
+ [1, 2, 3, 4],
+ [236, 416, 336, 350],
+];
+
+sub element_digit_sum
+{
+ my $l = shift;
+
+ my $elem_sum = 0;
+ my $digi_sum = 0;
+
+ for my $e (@$l) {
+ $elem_sum += $e;
+ $digi_sum += $_ for split('', $e);
+ }
+
+ return abs($elem_sum - $digi_sum);
+}
+
+is(element_digit_sum($cases->[0]), 36, 'Example 1');
+is(element_digit_sum($cases->[1]), 9, 'Example 2');
+is(element_digit_sum($cases->[2]), 0, 'Example 3');
+is(element_digit_sum($cases->[3]), 1296, 'Example 4');
+done_testing();
+
+exit 0;
diff --git a/challenge-261/peter-meszaros/perl/ch-2.pl b/challenge-261/peter-meszaros/perl/ch-2.pl
new file mode 100755
index 0000000000..1cc344c748
--- /dev/null
+++ b/challenge-261/peter-meszaros/perl/ch-2.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/env perl
+#
+# You are given an array of integers, @ints and an integer $start..
+#
+# Write a script to do the followings:
+#
+# a) Look for $start in the array @ints, if found multiply the number by 2
+# b) If not found stop the process otherwise repeat
+#
+# In the end return the final value.
+# Example 1
+#
+# Input: @ints = (5,3,6,1,12) and $start = 3
+# Output: 24
+#
+# Step 1: 3 is in the array so 3 x 2 = 6
+# Step 2: 6 is in the array so 6 x 2 = 12
+# Step 3: 12 is in the array so 12 x 2 = 24
+#
+# 24 is not found in the array so return 24.
+#
+# Example 2
+#
+# Input: @ints = (1,2,4,3) and $start = 1
+# Output: 8
+#
+# Step 1: 1 is in the array so 1 x 2 = 2
+# Step 2: 2 is in the array so 2 x 2 = 4
+# Step 3: 4 is in the array so 4 x 2 = 8
+#
+# 8 is not found in the array so return 8.
+#
+# Example 3
+#
+# Input: @ints = (5,6,7) and $start = 2
+# Output: 2
+#
+# 2 is not found in the array so return 2.
+#
+
+use strict;
+use warnings;
+use Test2::V0 -no_srand => 1;
+use Data::Dumper;
+
+my $cases = [
+ [[5, 3, 6, 1, 12], 3],
+ [[1, 2, 4, 3], 1],
+ [[5, 6, 7], 2],
+];
+
+sub multiply_by_two
+{
+ my ($l, $s) = $_[0]->@*;
+
+ START:
+ for my $i (@$l) {
+ if ($i == $s) {
+ $s *= 2;
+ goto START;
+ }
+ }
+ return $s;
+}
+
+is(multiply_by_two($cases->[0]), 24, 'Example 1');
+is(multiply_by_two($cases->[1]), 8, 'Example 2');
+is(multiply_by_two($cases->[2]), 2, 'Example 3');
+done_testing();
+
+exit 0;
+
diff --git a/challenge-261/ulrich-rieke/cpp/ch-1.cpp b/challenge-261/ulrich-rieke/cpp/ch-1.cpp
new file mode 100755
index 0000000000..a088bfc147
--- /dev/null
+++ b/challenge-261/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,30 @@
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <iterator>
+#include <cstdlib>
+
+int digitsum( int n ) {
+ int sum = 0 ;
+ while ( n != 0 ) {
+ sum += n % 10 ;
+ n /= 10 ;
+ }
+ return sum ;
+}
+
+int main( ) {
+ std::cout << "Enter some integers, separated by blanks!\n" ;
+ std::cout << "Enter e to end!\n" ;
+ std::vector<int> numbers {std::istream_iterator<int>{std::cin} ,
+ std::istream_iterator<int>{}} ;
+ int element_sum = std::accumulate( numbers.begin( ) , numbers.end( ) ,
+ 0 ) ;
+ std::vector<int> digitsums ;
+ for ( int i : numbers )
+ digitsums.push_back( digitsum( i ) ) ;
+ int total_digitsums = std::accumulate( digitsums.begin( ) ,
+ digitsums.end( ) , 0 ) ;
+ std::cout << std::abs( total_digitsums - element_sum) << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-261/ulrich-rieke/cpp/ch-2.cpp b/challenge-261/ulrich-rieke/cpp/ch-2.cpp
new file mode 100755
index 0000000000..e5a956a286
--- /dev/null
+++ b/challenge-261/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,35 @@
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <string>
+
+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 numberline ;
+ std::getline( std::cin , numberline ) ;
+ std::vector<std::string> innumbers { split( numberline , " " ) } ;
+ std::vector<int> numbers ;
+ for ( auto w : innumbers )
+ numbers.push_back( std::stoi( w ) ) ;
+ std::cout << "Enter a start number!\n" ;
+ int start ;
+ std::cin >> start ;
+ while ( std::find( numbers.begin( ) , numbers.end( ) , start ) !=
+ numbers.end( ) )
+ start *= 2 ;
+ std::cout << start << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-261/ulrich-rieke/haskell/ch-1.hs b/challenge-261/ulrich-rieke/haskell/ch-1.hs
new file mode 100755
index 0000000000..515d9bb0d0
--- /dev/null
+++ b/challenge-261/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,17 @@
+module Challenge261
+ where
+import Data.Char( digitToInt )
+
+solution :: [Int] -> Int
+solution list = abs ( elementsums - digitsums )
+ where
+ elementsums :: Int
+ elementsums = sum list
+ digitsums :: Int
+ digitsums = sum $ map ( sum . map digitToInt . show ) list
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some integers, separated by blanks!"
+ numbers <- getLine
+ print $ solution ( map read $ words numbers )
diff --git a/challenge-261/ulrich-rieke/haskell/ch-2.hs b/challenge-261/ulrich-rieke/haskell/ch-2.hs
new file mode 100755
index 0000000000..13f141fd25
--- /dev/null
+++ b/challenge-261/ulrich-rieke/haskell/ch-2.hs
@@ -0,0 +1,13 @@
+module Challenge261_2
+ where
+
+solution :: [Int] -> Int -> Int
+solution list start = until (\n -> not $ elem n list ) (* 2 ) start
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some numbers, separated by blanks!"
+ numberstrings <- getLine
+ putStrLn "Enter a start number!"
+ startline <- getLine
+ print $ solution ( map read $ words numberstrings ) ( read startline )
diff --git a/challenge-261/ulrich-rieke/perl/ch-1.pl b/challenge-261/ulrich-rieke/perl/ch-1.pl
new file mode 100755
index 0000000000..2239702a1c
--- /dev/null
+++ b/challenge-261/ulrich-rieke/perl/ch-1.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( sum ) ;
+
+say "Enter some integers, separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s+/ , $line ) ;
+my $element_sum = sum( @numbers) ;
+my $digit_sum = sum( map { sum( split( // , $_ )) } @numbers ) ;
+say abs( $element_sum - $digit_sum ) ;
diff --git a/challenge-261/ulrich-rieke/perl/ch-2.pl b/challenge-261/ulrich-rieke/perl/ch-2.pl
new file mode 100755
index 0000000000..40cbf5801d
--- /dev/null
+++ b/challenge-261/ulrich-rieke/perl/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( any ) ;
+
+say "Enter some integers, separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s+/ , $line ) ;
+say "Enter a start number!" ;
+my $start = <STDIN> ;