From 4f1ac3bf456237ac35666981779c293da0810faf Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Mon, 5 Jul 2021 22:51:20 +0800 Subject: challenge 120, raku solutions --- challenge-120/feng-chang/raku/ch-1.raku | 5 +++++ challenge-120/feng-chang/raku/ch-2.raku | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100755 challenge-120/feng-chang/raku/ch-1.raku create mode 100755 challenge-120/feng-chang/raku/ch-2.raku diff --git a/challenge-120/feng-chang/raku/ch-1.raku b/challenge-120/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..0f2bbaee1d --- /dev/null +++ b/challenge-120/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(UInt:D $N where * ≤ 255) { + put (($N +& 85) +< 1) +| (($N +& 170) +> 1); +} diff --git a/challenge-120/feng-chang/raku/ch-2.raku b/challenge-120/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..bbdc79ab09 --- /dev/null +++ b/challenge-120/feng-chang/raku/ch-2.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +sub MAIN(Str:D $T) { + $T ~~ m/^ (\d\d) ':' (\d\d) $/; + put abs(($0 % 12) * 30 - ($1 % 60) * 5.5); +} -- cgit From 26daa77158c34b6edecf059cd69a6f754310589e Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Wed, 7 Jul 2021 19:09:10 +0800 Subject: challenge 118, raku solutions --- challenge-119/feng-chang/raku/ch-1.raku | 5 +++++ challenge-119/feng-chang/raku/ch-2.raku | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100755 challenge-119/feng-chang/raku/ch-1.raku create mode 100755 challenge-119/feng-chang/raku/ch-2.raku diff --git a/challenge-119/feng-chang/raku/ch-1.raku b/challenge-119/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..5d2c207f55 --- /dev/null +++ b/challenge-119/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(UInt:D $N where * ≤ 255) { + put $N.fmt('%02x').comb.reverse.join.parse-base(16); +} diff --git a/challenge-119/feng-chang/raku/ch-2.raku b/challenge-119/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..28cbbbaa08 --- /dev/null +++ b/challenge-119/feng-chang/raku/ch-2.raku @@ -0,0 +1,12 @@ +#!/bin/env raku + +sub MAIN(UInt:D $N where $N > 0) { + my Seq $trin = gather for 1..∞ -> $i { + my $n = $i.base(4); + next if $n ~~ m/0/; + next if $n ~~ m/11/; + take $n; + } + + put $trin[$N - 1]; +} -- cgit From 506a04ba5a638ccabdd683bf6b3460a23b98b415 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Mon, 19 Jul 2021 18:51:05 +0800 Subject: challenge 121/122, Raku solutions --- challenge-121/feng-chang/raku/ch-1.raku | 5 +++++ challenge-121/feng-chang/raku/ch-2.raku | 25 +++++++++++++++++++++++++ challenge-121/feng-chang/raku/d02.txt | 4 ++++ challenge-122/feng-chang/raku/ch-1.raku | 5 +++++ challenge-122/feng-chang/raku/ch-2.raku | 10 ++++++++++ 5 files changed, 49 insertions(+) create mode 100755 challenge-121/feng-chang/raku/ch-1.raku create mode 100755 challenge-121/feng-chang/raku/ch-2.raku create mode 100644 challenge-121/feng-chang/raku/d02.txt create mode 100755 challenge-122/feng-chang/raku/ch-1.raku create mode 100755 challenge-122/feng-chang/raku/ch-2.raku diff --git a/challenge-121/feng-chang/raku/ch-1.raku b/challenge-121/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..01e14e1b19 --- /dev/null +++ b/challenge-121/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(UInt:D $m where 0 ≤ * ≤ 255, UInt:D $n where 1 ≤ * ≤ 8) { + put $m +^ (1 +< ($n - 1)); +} diff --git a/challenge-121/feng-chang/raku/ch-2.raku b/challenge-121/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..cde0da4f14 --- /dev/null +++ b/challenge-121/feng-chang/raku/ch-2.raku @@ -0,0 +1,25 @@ +#!/bin/env raku + +my $shortest-length; +my Array $shortest-path; + +sub distance(Array:D $TS, List:D $path) { + my Array:D $p = [0, |$path, 0]; + my $dist = [+] (^$TS.elems).map({ $TS[$p[$_];$p[$_+1]] }); + if $dist < $shortest-length { + $shortest-length = $dist; + $shortest-path = $p; + } + + $dist +} + +sub MAIN(Str:D $f where *.IO.e) { + my Array $TS .= new; + $f.IO.lines.map({ $TS.push($_.words».UInt.Array) }); + + $shortest-length = [+] $TS».max; + + put (1..^$TS.elems).permutations.map({ distance($TS, $_) }).min; + put $shortest-path.gist; +} diff --git a/challenge-121/feng-chang/raku/d02.txt b/challenge-121/feng-chang/raku/d02.txt new file mode 100644 index 0000000000..a389324b02 --- /dev/null +++ b/challenge-121/feng-chang/raku/d02.txt @@ -0,0 +1,4 @@ +0 5 2 7 +5 0 5 3 +3 1 0 6 +4 5 4 0 diff --git a/challenge-122/feng-chang/raku/ch-1.raku b/challenge-122/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..0e04b73ce8 --- /dev/null +++ b/challenge-122/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(*@N) { + put (^@N.elems).map({ @N[0..$_].sum / ($_+1) }); +} diff --git a/challenge-122/feng-chang/raku/ch-2.raku b/challenge-122/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..f2a11cd67e --- /dev/null +++ b/challenge-122/feng-chang/raku/ch-2.raku @@ -0,0 +1,10 @@ +#!/bin/env raku + +sub score(UInt:D $N, Array:D $s) { + put $s if $N == 0; + score($N - 1, [|$s, 1]) if $N ≥ 1; + score($N - 2, [|$s, 2]) if $N ≥ 2; + score($N - 3, [|$s, 3]) if $N ≥ 3; +} + +sub MAIN(UInt:D $N) { score($N, []) } -- cgit From 2493f501976b93d1b918a680ed2fe60bad58d883 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Tue, 27 Jul 2021 14:37:47 +0800 Subject: Challenge 123, Raku solutions --- challenge-123/feng-chang/raku/ch-1.raku | 16 ++++++++++++++++ challenge-123/feng-chang/raku/ch-2.raku | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 challenge-123/feng-chang/raku/ch-1.raku create mode 100755 challenge-123/feng-chang/raku/ch-2.raku diff --git a/challenge-123/feng-chang/raku/ch-1.raku b/challenge-123/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..d738e1cb39 --- /dev/null +++ b/challenge-123/feng-chang/raku/ch-1.raku @@ -0,0 +1,16 @@ +#!/bin/env raku + +my method is-ugly(Int:D $n: --> Bool:D) { + my UInt $m = $n; + + $m div= 2 while $m %% 2; + $m div= 3 while $m %% 3; + $m div= 5 while $m %% 5; + + so $m == 1 +} + +sub MAIN(UInt:D $n where * > 0) { + my @uglies = (1..∞).grep(*.&is-ugly); + put @uglies[$n-1]; +} diff --git a/challenge-123/feng-chang/raku/ch-2.raku b/challenge-123/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..30e459d0b4 --- /dev/null +++ b/challenge-123/feng-chang/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/bin/env raku + +sub dist2(Int:D \x1, Int:D \y1, Int:D \x2, Int:D \y2 --> UInt:D) { + (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) +} + +sub is-square( + Int:D \x1, Int:D \y1, + Int:D \x2, Int:D \y2, + Int:D \x3, Int:D \y3, + Int:D \x4, Int:D \y4 +--> Bool:D) { + [==] dist2(x1,y1,x2,y2), dist2(x2,y2,x3,y3), dist2(x3,y3,x4,y4), dist2(x4,y4,x1,y1) +} + +sub MAIN(*@N where *.elems == 8) { + put + [or] (1..3).permutations.map({ is-square( + @N[0], @N[1], + @N[.[0]*2], @N[.[0]*2+1], + @N[.[1]*2], @N[.[1]*2+1], + @N[.[2]*2], @N[.[2]*2+1] + ) }); +} -- cgit From c728f4162f1bdac42fe8e07eba1dcc4fb92d518b Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Thu, 5 Aug 2021 14:35:32 +0800 Subject: challenge #123, raku solutions --- challenge-124/feng-chang/raku/ch-1.raku | 9 +++++++++ challenge-124/feng-chang/raku/ch-2.raku | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 challenge-124/feng-chang/raku/ch-1.raku create mode 100755 challenge-124/feng-chang/raku/ch-2.raku diff --git a/challenge-124/feng-chang/raku/ch-1.raku b/challenge-124/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..b4523b9220 --- /dev/null +++ b/challenge-124/feng-chang/raku/ch-1.raku @@ -0,0 +1,9 @@ +#!/bin/env raku + +for '14322222341000100'.comb».UInt -> $c { + given $c { + when 0 { put ' ^' } + when 1 { put ' ^^^^^' } + default { put ' ' x ($c - 2), '^', ' ' x (13 - $c * 2), '^' } + } +} diff --git a/challenge-124/feng-chang/raku/ch-2.raku b/challenge-124/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..3a0d747519 --- /dev/null +++ b/challenge-124/feng-chang/raku/ch-2.raku @@ -0,0 +1,17 @@ +#!/bin/env raku + +sub MAIN(*@N) { + my UInt $num = @N.elems div 2; + my Int $sum = @N.sum; + my UInt $min = @N.combinations($num).map({ abs($sum - 2 * $_.sum) }).min; + + @N.combinations($num).map({ + if abs($sum - 2 * $_.sum) == $min { + put $_.join(' '); + put (@N (-) $_).keys.join(' '); + put ' = ' x 3; + } + }); +} + +# todo: when size is even, output should be cut to half -- cgit From 2f49bb6081fe7aceecc37b213a1e9d6b6e802ca2 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Fri, 3 Sep 2021 11:20:46 +0800 Subject: 提交本地修改 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challenge-126/feng-chang/raku/ch-1.raku | 5 +++++ challenge-126/feng-chang/raku/ch-2.raku | 22 ++++++++++++++++++++++ challenge-126/feng-chang/raku/input.txt | 5 +++++ 3 files changed, 32 insertions(+) create mode 100755 challenge-126/feng-chang/raku/ch-1.raku create mode 100755 challenge-126/feng-chang/raku/ch-2.raku create mode 100644 challenge-126/feng-chang/raku/input.txt diff --git a/challenge-126/feng-chang/raku/ch-1.raku b/challenge-126/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..aa39eff4cb --- /dev/null +++ b/challenge-126/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(UInt:D $N) { + put (2..$N).grep(!*.comb.grep(1)).elems; +} diff --git a/challenge-126/feng-chang/raku/ch-2.raku b/challenge-126/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..e1dfc70f6e --- /dev/null +++ b/challenge-126/feng-chang/raku/ch-2.raku @@ -0,0 +1,22 @@ +#!/bin/env raku + +sub is-mine(Array:D $game, Int:D $row, Int:D $col, UInt:D $max-row, UInt:D $max-col --> Bool:D) { + return False unless 0 ≤ $row < $max-row; + return False unless 0 ≤ $col < $max-col; + $game[$row;$col] eq 'x' +} + +sub neibours(Array:D $game, UInt:D $row, UInt:D $col --> Str:D) { + $game[$row;$col] eq 'x' ?? 'x' !! ( + ( 1, -1), ( 1, 0), ( 1, 1), + ( 0, -1), ( 0, 1), + (-1, -1), (-1, 0), (-1, 1) + ).map({ is-mine($game, $row + .[0], $col + .[1], $game.elems, $game[0].elems) }).grep(?*).elems.Str +} + +sub MAIN(Str:D $f where $f.IO.e = 'input.txt') { + my Array $game = $f.IO.lines».comb.Array; + for ^$game.elems -> $row { + put (^$game[0].elems).map({ neibours($game, $row, .[0]) }).join(' '); + } +} diff --git a/challenge-126/feng-chang/raku/input.txt b/challenge-126/feng-chang/raku/input.txt new file mode 100644 index 0000000000..c7dd9f6980 --- /dev/null +++ b/challenge-126/feng-chang/raku/input.txt @@ -0,0 +1,5 @@ +x***x*xxxx +*********x +****x*x*x* +***xx***** +x***x****x -- cgit From a9b3cf3285adb7126b920a6fdc4315ac3ba6ddec Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Sat, 9 Oct 2021 18:27:06 +0800 Subject: challenge 133, raku solutions --- challenge-133/feng-chang/raku/ch-1.raku | 17 +++++++++++++++++ challenge-133/feng-chang/raku/ch-2.raku | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 challenge-133/feng-chang/raku/ch-1.raku create mode 100755 challenge-133/feng-chang/raku/ch-2.raku diff --git a/challenge-133/feng-chang/raku/ch-1.raku b/challenge-133/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..1322a40a06 --- /dev/null +++ b/challenge-133/feng-chang/raku/ch-1.raku @@ -0,0 +1,17 @@ +#!/bin/env raku + +my method sqrt(UInt:D \N: --> UInt:D) { + my UInt $m; + my UInt $n = N; + + repeat { + $m = $n; + $n = ($m + N div $m) div 2; + } while $n < $m; + + $m +} + +sub MAIN(UInt:D \N where * > 0) { + put N.&sqrt; +} diff --git a/challenge-133/feng-chang/raku/ch-2.raku b/challenge-133/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..0f63b31841 --- /dev/null +++ b/challenge-133/feng-chang/raku/ch-2.raku @@ -0,0 +1,28 @@ +#!/bin/env raku + +sub facts(UInt:D \N where * > 1 --> Hash:D) { + my Int $m = N; + my Hash $F; + + for (^∞).grep: *.is-prime -> $p { + while ($m %% $p) { + ++$F{$p}; + $m div= $p; + } + + last if $m < $p * $p; + + LAST { ++$F{$m} if $m > 1 } + } + + $F +} + +sub is-smith-number(UInt:D \N --> Bool:D) { + return False if N.is-prime; + + my Hash $F = facts(N); + N.comb.sum == $F.keys.map({ $_.comb.sum * $F{$_} }).sum +} + +put (2..∞).grep({ is-smith-number($_) })[^10]; -- cgit From 1380439dbe2f374f3d7f3644570e80cf44eda5a9 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Mon, 11 Oct 2021 18:23:06 +0800 Subject: challenge 134, raku solutions --- challenge-134/feng-chang/raku/ch-1.raku | 3 +++ challenge-134/feng-chang/raku/ch-2.raku | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 challenge-134/feng-chang/raku/ch-1.raku create mode 100755 challenge-134/feng-chang/raku/ch-2.raku diff --git a/challenge-134/feng-chang/raku/ch-1.raku b/challenge-134/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..2808b4aa92 --- /dev/null +++ b/challenge-134/feng-chang/raku/ch-1.raku @@ -0,0 +1,3 @@ +#!/bin/env raku + +put (1_023_000_000 .. ∞).grep(*.comb.sort.unique.elems == 10)[^10]; diff --git a/challenge-134/feng-chang/raku/ch-2.raku b/challenge-134/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..052753ad39 --- /dev/null +++ b/challenge-134/feng-chang/raku/ch-2.raku @@ -0,0 +1,18 @@ +#!/bin/env raku + +sub MAIN(UInt:D \m, UInt:D \n) { + my @widths = (1..n)».&{ $_*m }».chars; + + put 'x'.fmt("%{ m.chars }s"), + ' |', + (1..n)».&{ $_.fmt(" %{ @widths[$_-1] }d") }.join; + put '-' x m.chars, + '-+', + (1..n)».&{ '-' x (@widths[$_-1] + 1) }.join; + + for 1..m -> $row { + put $row.fmt("%{ m.chars }d"), + ' |', + (1..n)».&{ ($_*$row).fmt(" %{ @widths[$_-1] }d") }.join; + } +} -- cgit From 1c423f3fee1b532ca610704ac3596e0ae1eeb912 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Mon, 11 Oct 2021 18:27:03 +0800 Subject: optimize "-" count --- challenge-134/feng-chang/raku/ch-2.raku | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-134/feng-chang/raku/ch-2.raku b/challenge-134/feng-chang/raku/ch-2.raku index 052753ad39..46a7e40b52 100755 --- a/challenge-134/feng-chang/raku/ch-2.raku +++ b/challenge-134/feng-chang/raku/ch-2.raku @@ -7,8 +7,8 @@ sub MAIN(UInt:D \m, UInt:D \n) { ' |', (1..n)».&{ $_.fmt(" %{ @widths[$_-1] }d") }.join; put '-' x m.chars, - '-+', - (1..n)».&{ '-' x (@widths[$_-1] + 1) }.join; + '-+', + '-' x (@widths.sum + n); for 1..m -> $row { put $row.fmt("%{ m.chars }d"), -- cgit From ded1adead24d65f5ba5de3c51476467b98b87253 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Tue, 12 Oct 2021 10:30:03 +0800 Subject: add more output --- challenge-134/feng-chang/raku/ch-2.raku | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/challenge-134/feng-chang/raku/ch-2.raku b/challenge-134/feng-chang/raku/ch-2.raku index 46a7e40b52..9e565720a9 100755 --- a/challenge-134/feng-chang/raku/ch-2.raku +++ b/challenge-134/feng-chang/raku/ch-2.raku @@ -2,6 +2,7 @@ sub MAIN(UInt:D \m, UInt:D \n) { my @widths = (1..n)».&{ $_*m }».chars; + my %terms; put 'x'.fmt("%{ m.chars }s"), ' |', @@ -13,6 +14,9 @@ sub MAIN(UInt:D \m, UInt:D \n) { for 1..m -> $row { put $row.fmt("%{ m.chars }d"), ' |', - (1..n)».&{ ($_*$row).fmt(" %{ @widths[$_-1] }d") }.join; + (1..n)».&{ my $i = $_*$row; ++%terms{$i}; $i.fmt(" %{ @widths[$_-1] }d") }.join; } + + put "\nDistinct Terms: ", %terms.keys».Int.sort.join(', '); + put 'Count: ', %terms.keys.elems; } -- cgit From 72f7e048afc69c0f2a596963e1ed6e274688a4f5 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Tue, 19 Oct 2021 19:35:54 +0800 Subject: challenge 135, raku solutions --- challenge-135/feng-chang/raku/ch-1.raku | 15 +++++++++++++++ challenge-135/feng-chang/raku/ch-2.raku | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 challenge-135/feng-chang/raku/ch-1.raku create mode 100755 challenge-135/feng-chang/raku/ch-2.raku diff --git a/challenge-135/feng-chang/raku/ch-1.raku b/challenge-135/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..4cc6c2919c --- /dev/null +++ b/challenge-135/feng-chang/raku/ch-1.raku @@ -0,0 +1,15 @@ +#!/bin/env raku + +=begin usage + + ./ch-1.raku -- -1234 + +=end usage + +sub MAIN(Int:D $N) { + given abs($N) { + when $_.chars %% 2 { put 'even number of digits'; exit } + when $_.chars < 3 { put 'too short'; exit } + default { put $_.substr($_.chars div 2 - 1, 3) } + } +} diff --git a/challenge-135/feng-chang/raku/ch-2.raku b/challenge-135/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..bc0c1f3da3 --- /dev/null +++ b/challenge-135/feng-chang/raku/ch-2.raku @@ -0,0 +1,19 @@ +#!/bin/env raku + +my method digit-value(Str:D $d where *.chars == 1 :) { + return $d.Int if '0' le $d le '9'; + return $d.ord - 'A'.ord if 'A' le $d le 'Z'; + die 'wrong digit: ', $d; +} + +sub check-digit(Str:D $sedol where *.chars == 6 --> UInt:D) { + state @weights = 1, 3, 1, 7, 3, 9, 1; + my @digits = $sedol.comb; + + 10 - (^6)».&{ @digits[$_].&digit-value * @weights[$_] }.sum % 10 +} + +sub MAIN(Str:D $S where *.chars == 7) { + my Str $s = uc($S); + put +so check-digit($s.substr(0, 6)) == $s.substr(6, 1).Int; +} -- cgit From bd9970453af9d7b5feca8a2be7646c30b358b1a5 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Wed, 20 Oct 2021 13:30:06 +0800 Subject: challenge 132, task #1, raku solution --- challenge-132/feng-chang/raku/ch-1.raku | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 challenge-132/feng-chang/raku/ch-1.raku diff --git a/challenge-132/feng-chang/raku/ch-1.raku b/challenge-132/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..cfdc079760 --- /dev/null +++ b/challenge-132/feng-chang/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/bin/env raku + +my method dstr(Date:D $dt: --> Str:D) { + $dt.Str.trans('-' => '/') +} + +sub MAIN(Str:D $birth-date-str) { + my Date \birth-date = $birth-date-str.trans('/' => '-').Date; + my UInt \age = now.Date - birth-date; + put "{ (birth-date - age).&dstr }, { (now.Date + age).&dstr }"; +} -- cgit From fb866d6d23493558f190fcdbd9a4ec165a6c1f98 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Wed, 20 Oct 2021 15:04:56 +0800 Subject: challenge 128, raku solutions --- challenge-128/feng-chang/raku/ch-1.raku | 17 +++++++++++++++++ challenge-128/feng-chang/raku/ch-2.raku | 22 ++++++++++++++++++++++ challenge-128/feng-chang/raku/in02.txt | 3 +++ challenge-128/feng-chang/raku/input.txt | 3 +++ challenge-128/feng-chang/raku/times.txt | 2 ++ challenge-128/feng-chang/raku/tm02.txt | 2 ++ 6 files changed, 49 insertions(+) create mode 100755 challenge-128/feng-chang/raku/ch-1.raku create mode 100755 challenge-128/feng-chang/raku/ch-2.raku create mode 100644 challenge-128/feng-chang/raku/in02.txt create mode 100644 challenge-128/feng-chang/raku/input.txt create mode 100644 challenge-128/feng-chang/raku/times.txt create mode 100644 challenge-128/feng-chang/raku/tm02.txt diff --git a/challenge-128/feng-chang/raku/ch-1.raku b/challenge-128/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..367dbb470d --- /dev/null +++ b/challenge-128/feng-chang/raku/ch-1.raku @@ -0,0 +1,17 @@ +#!/bin/env raku + +my method mat-size(List:D $coords where *.elems() == 4: --> UInt:D) { + ($coords[2] - $coords[0] + 1) * ($coords[3] - $coords[1] + 1) +} + +sub MAIN(Str:D $f where *.IO.e = 'input.txt') { + my Array @mat .= push($_.comb.Array) for $f.IO.lines; + + my @A = (^@mat.elems X ^@mat[0].elems X ^@mat.elems X ^@mat[0].elems) + .grep({ .[2] > .[0] and .[3] > .[1] }) + .grep({ @mat[.[0] .. .[2]; .[1] .. .[3]].all == 0 }); + my $max-size = @A.map(*.&mat-size).max; + + put "max size: $max-size"; + put @A.grep(*.&mat-size == $max-size).join("\n"); +} diff --git a/challenge-128/feng-chang/raku/ch-2.raku b/challenge-128/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..1050c46bfc --- /dev/null +++ b/challenge-128/feng-chang/raku/ch-2.raku @@ -0,0 +1,22 @@ +#!/bin/env raku + +subset TimeStr of Str where { $^s.match(/^ \d\d ':' \d\d $/) }; + +my method mytime(TimeStr:D $t: --> DateTime:D) { + state Date $date = Date.new(now); + my ($hour, $minute) = $t.split(':'); + + DateTime.new(:$date, :$hour, :$minute) +} + +sub MAIN(Str:D $f where *.IO.e = 'times.txt') { + my @lines = $f.IO.lines; + my @arrivals = @lines[0].words».&mytime; + my @departures = @lines[1].words».&mytime; + + (|@arrivals, |@departures).map(-> $t { + (^@arrivals).grep(-> $i { + @arrivals[$i] ≤ $t ≤ @departures[$i] + }).elems + }).max.put; +} diff --git a/challenge-128/feng-chang/raku/in02.txt b/challenge-128/feng-chang/raku/in02.txt new file mode 100644 index 0000000000..f8c64d269a --- /dev/null +++ b/challenge-128/feng-chang/raku/in02.txt @@ -0,0 +1,3 @@ +0011 +0001 +0010 diff --git a/challenge-128/feng-chang/raku/input.txt b/challenge-128/feng-chang/raku/input.txt new file mode 100644 index 0000000000..11c961ce70 --- /dev/null +++ b/challenge-128/feng-chang/raku/input.txt @@ -0,0 +1,3 @@ +100010 +110001 +100000 diff --git a/challenge-128/feng-chang/raku/times.txt b/challenge-128/feng-chang/raku/times.txt new file mode 100644 index 0000000000..3bdd72d4d3 --- /dev/null +++ b/challenge-128/feng-chang/raku/times.txt @@ -0,0 +1,2 @@ +11:20 14:30 +11:50 15:00 diff --git a/challenge-128/feng-chang/raku/tm02.txt b/challenge-128/feng-chang/raku/tm02.txt new file mode 100644 index 0000000000..a8ce4a8d1d --- /dev/null +++ b/challenge-128/feng-chang/raku/tm02.txt @@ -0,0 +1,2 @@ +10:20 11:00 11:10 12:20 16:20 19:00 +10:30 13:20 12:40 12:50 20:20 21:20 -- cgit From 6feeaa5f2efa5e3a0e27aa9610f0f686ea7c34a8 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Tue, 26 Oct 2021 15:20:25 +0800 Subject: challenge 136, raku solutions --- challenge-136/feng-chang/raku/ch-1.raku | 9 +++++++++ challenge-136/feng-chang/raku/ch-2.raku | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100755 challenge-136/feng-chang/raku/ch-1.raku create mode 100755 challenge-136/feng-chang/raku/ch-2.raku diff --git a/challenge-136/feng-chang/raku/ch-1.raku b/challenge-136/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..c1cc9c1c7e --- /dev/null +++ b/challenge-136/feng-chang/raku/ch-1.raku @@ -0,0 +1,9 @@ +#!/bin/env raku + +multi sub is-two-friendly(0) { True } +multi sub is-two-friendly(2) { True } +multi sub is-two-friendly(UInt:D \n) { n %% 2 and is-two-friendly(n div 2) } + +sub MAIN(UInt:D \m, UInt:D \n) { + put +is-two-friendly(m gcd n); +} diff --git a/challenge-136/feng-chang/raku/ch-2.raku b/challenge-136/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..418370329a --- /dev/null +++ b/challenge-136/feng-chang/raku/ch-2.raku @@ -0,0 +1,11 @@ +#!/bin/env raku + +my @fibo = 1, 2, * + * ... *; + +sub fibo-floor(UInt:D \n --> UInt:D) { + (^n).grep({ @fibo[$_] ≤ n }).max +} + +sub MAIN(UInt:D \n) { + put @fibo[0 .. fibo-floor(n)].combinations.grep(*.sum == n).elems; +} -- cgit From 543bce7e79f1e0c39b2755dd52962b409c7c15d0 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Mon, 1 Nov 2021 16:40:13 +0800 Subject: challenge 137, raku solutions --- challenge-137/feng-chang/raku/ch-1.raku | 7 +++++++ challenge-137/feng-chang/raku/ch-2.raku | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 challenge-137/feng-chang/raku/ch-1.raku create mode 100755 challenge-137/feng-chang/raku/ch-2.raku diff --git a/challenge-137/feng-chang/raku/ch-1.raku b/challenge-137/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..b0de7b2725 --- /dev/null +++ b/challenge-137/feng-chang/raku/ch-1.raku @@ -0,0 +1,7 @@ +#!/bin/env raku + +put (1900..2100) + .grep({ Date("$_-12-31").week[1] == 53 }) + .rotor(5, :partial) + .map({ $_.join(', ') }) + .join(",\n"); diff --git a/challenge-137/feng-chang/raku/ch-2.raku b/challenge-137/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..7239d2cdb2 --- /dev/null +++ b/challenge-137/feng-chang/raku/ch-2.raku @@ -0,0 +1,21 @@ +#!/bin/env raku + +sub is-palindrome(UInt:D $n --> Bool:D) { $n.flip == $n } + +sub is-lynchel(UInt:D $n --> Bool:D) { + my UInt $m = $n; + my UInt $cnt; + + repeat { + return False if is-palindrome($m); + + $m += $m.flip; + ++$cnt; + } while $cnt < 500; + + ! is-palindrome($m) +} + +sub MAIN(UInt:D $n) { + put +is-lynchel($n); +} -- cgit From cbcf71957305d112b5a00d20ea40de4b8917984f Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Fri, 12 Nov 2021 19:41:05 +0800 Subject: challenge #137 #138, raku solutions --- challenge-118/feng-chang/raku/ch-1.raku | 6 +++ challenge-118/feng-chang/raku/ch-2.raku | 71 +++++++++++++++++++++++++++++++++ challenge-137/feng-chang/perl/ch-1.pl | 12 ++++++ challenge-138/feng-chang/raku/ch-1.raku | 5 +++ challenge-138/feng-chang/raku/ch-2.raku | 23 +++++++++++ 5 files changed, 117 insertions(+) create mode 100755 challenge-118/feng-chang/raku/ch-1.raku create mode 100755 challenge-118/feng-chang/raku/ch-2.raku create mode 100755 challenge-137/feng-chang/perl/ch-1.pl create mode 100755 challenge-138/feng-chang/raku/ch-1.raku create mode 100755 challenge-138/feng-chang/raku/ch-2.raku diff --git a/challenge-118/feng-chang/raku/ch-1.raku b/challenge-118/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..403b9cf5d6 --- /dev/null +++ b/challenge-118/feng-chang/raku/ch-1.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +sub MAIN(UInt:D $n) { + my Str $s = $n.base(2); + put +($s.flip eq $s); +} diff --git a/challenge-118/feng-chang/raku/ch-2.raku b/challenge-118/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..863ebee873 --- /dev/null +++ b/challenge-118/feng-chang/raku/ch-2.raku @@ -0,0 +1,71 @@ +#!/bin/env raku + +=begin puzzle + a b c d e f g h + 8 N * * * * * * * 8 + 7 * * * * * * * * 7 + 6 * * * * x * * * 6 + 5 * * * * * * * * 5 + 4 * * x * * * * * 4 + 3 * x * * * * * * 3 + 2 x x * * * * * * 2 + 1 * x * * * * * * 1 + a b c d e f g h + + 0 1 2 3 4 5 6 7 + 0 N * * * * * * * + 1 * * * * * * * * + 2 * * * * x * * * + 3 * * * * * * * * + 4 * * x * * * * * + 5 * x * * * * * * + 6 x x * * * * * * + 7 * x * * * * * * +=end puzzle + +my UInt $least-steps = 128; + +sub score(Array:D $pos, Set:D $targets, Set:D $unreached, Array:D $path --> UInt:D) { + my UInt $score = 10; + $score -= $path.grep($pos).elems; + if $pos (elem) $unreached { + ++$score; + ++$score if $pos (elem) $targets; + } + + $score +} + +sub walk(Array:D $pos, Set:D $targets, Set:D $unreached, Array:D $path) { + return if $path.elems > $least-steps; + + if $targets.keys == 0 { + put "{ $path.elems } steps: { $path.gist }"; + $least-steps = $path.elems if $path.elems < $least-steps; + return; + } + + my @candidates = gather + for (1,2), (1,-2), (-1,2), (-1,-2), (2,1), (2,-1), (-2,1), (-2,-1) -> ($r, $c) { + #put "«$r $c»"; + my Int $row = $pos[0] + $r; + next if $row < 0 or $row > 7; + my Int $col = $pos[1] + $c; + next if $col < 0 or $col > 7; + take [$row, $col].item; + } + my @score = @candidates.map({ score($_, $targets, $unreached, $path) }); + (^@candidates.elems).sort(??); + 排序怪怪的??? + + my Array $new-pos = ($row, $col).Array; + put "new pos { $new-pos.gist }"; + + my Array $new-path = $path.deepmap(*.clone); + $new-path.push($new-pos); + + walk($new-pos, $targets (-) ($new-pos).Set, $new-path); + } +} + +walk([0, 0], ([2,4], [4,2], [5,1], [6,0], [6,1], [7,1]).Set, ([0, 0].item).Array); diff --git a/challenge-137/feng-chang/perl/ch-1.pl b/challenge-137/feng-chang/perl/ch-1.pl new file mode 100755 index 0000000000..c4fdf11502 --- /dev/null +++ b/challenge-137/feng-chang/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/bin/env perl + +use Date::Manip; + +my @years = grep { UnixDate("$_-12-31", '%W') == 53 } 1900..2100; + +my $first = 1; +while (@years) { + $first ? $first = 0 : print ",\n"; + print join ', ', splice @years, 0, 5; +} +print "\n"; diff --git a/challenge-138/feng-chang/raku/ch-1.raku b/challenge-138/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..77b9791438 --- /dev/null +++ b/challenge-138/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(UInt:D $year where 1000 ≤ * ≤ 9999) { + put ("$year-01-01".Date .. "$year-12-31".Date)».day-of-week.grep(0 < * < 6).elems; +} diff --git a/challenge-138/feng-chang/raku/ch-2.raku b/challenge-138/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..a342d06c1c --- /dev/null +++ b/challenge-138/feng-chang/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/bin/env raku + +sub combo(UInt:D $N, UInt:D $pat --> Array:D) { + my @digits = $N.comb».UInt; + my UInt $n = @digits.shift; + my @splits; + + for @digits Z $pat.fmt('%0' ~ $N.chars-1 ~ 'b').comb».UInt -> ($d, $j) { + if ?$j { + @splits.push($n); + $n = $d; + } else { + $n = $n*10 + $d; + } + } + @splits.push($n); + + @splits +} + +sub MAIN(UInt:D $N) { + put +((1 .. 2**($N.chars-1)-1).grep({ combo($N, $_).sum == sqrt($N) }).elems > 0); +} -- cgit From a35c10af3462d9079516a3ccca8c8c95c88c89df Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Mon, 15 Nov 2021 18:28:46 +0800 Subject: Challenge #139, Raku solutions --- challenge-139/feng-chang/raku/ch-1.raku | 5 +++++ challenge-139/feng-chang/raku/ch-2.raku | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100755 challenge-139/feng-chang/raku/ch-1.raku create mode 100755 challenge-139/feng-chang/raku/ch-2.raku diff --git a/challenge-139/feng-chang/raku/ch-1.raku b/challenge-139/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..b29a51486c --- /dev/null +++ b/challenge-139/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +sub MAIN(*@nums where .all ~~ Int) { + put + [<] @nums; +} diff --git a/challenge-139/feng-chang/raku/ch-2.raku b/challenge-139/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..36754cb708 --- /dev/null +++ b/challenge-139/feng-chang/raku/ch-2.raku @@ -0,0 +1,10 @@ +#!/bin/env raku + +put (1..∞).grep({ is-long-prime($_) })[^10]; + +sub is-long-prime(UInt:D $p --> Bool:D) { + return False unless $p.is-prime; + return False if $p < 3; + return False if (1 .. $p-2).map(9 x *).grep(* %% $p); + return (9 x $p-1) %% $p; +} -- cgit From 83b91177f7b1aced78863b336bd236a40f7e1aef Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 15 Nov 2021 19:39:28 +0100 Subject: Tests for week 139 --- challenge-139/abigail/t/ctest.ini | 11 +++++++++++ challenge-139/abigail/t/input-1-1 | 2 ++ challenge-139/abigail/t/input-2-1 | 0 challenge-139/abigail/t/output-1-1.exp | 2 ++ challenge-139/abigail/t/output-2-1.exp | 5 +++++ 5 files changed, 20 insertions(+) create mode 100644 challenge-139/abigail/t/ctest.ini create mode 100644 challenge-139/abigail/t/input-1-1 create mode 100644 challenge-139/abigail/t/input-2-1 create mode 100644 challenge-139/abigail/t/output-1-1.exp create mode 100644 challenge-139/abigail/t/output-2-1.exp diff --git a/challenge-139/abigail/t/ctest.ini b/challenge-139/abigail/t/ctest.ini new file mode 100644 index 0000000000..01d41b9c6f --- /dev/null +++ b/challenge-139/abigail/t/ctest.ini @@ -0,0 +1,11 @@ +# +# Configuration file for running tests, using ctest. +# See https://github.com/Abigail/Misc/blob/master/ctest +# + +[names] +1-1 = Given examples +2-1 = Fixed output + +[2-1] +no_input = 1 diff --git a/challenge-139/abigail/t/input-1-1 b/challenge-139/abigail/t/input-1-1 new file mode 100644 index 0000000000..8af9f0fa85 --- /dev/null +++ b/challenge-139/abigail/t/input-1-1 @@ -0,0 +1,2 @@ +1 2 3 4 5 +1 3 2 4 5 diff --git a/challenge-139/abigail/t/input-2-1 b/challenge-139/abigail/t/input-2-1 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-139/abigail/t/output-1-1.exp b/challenge-139/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..b261da18d5 --- /dev/null +++ b/challenge-139/abigail/t/output-1-1.exp @@ -0,0 +1,2 @@ +1 +0 diff --git a/challenge-139/abigail/t/output-2-1.exp b/challenge-139/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..30d54fc879 --- /dev/null +++ b/challenge-139/abigail/t/output-2-1.exp @@ -0,0 +1,5 @@ +7 +17 +19 +23 +29 -- cgit From 470f4f134166a0d88b4800b54c5e13510e4dfa50 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Tue, 16 Nov 2021 19:08:18 -0600 Subject: Add solutions to PWC139 --- challenge-139/wlmb/blog.txt | 1 + challenge-139/wlmb/perl/ch-1.pl | 12 ++++++++++++ challenge-139/wlmb/perl/ch-2.pl | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 challenge-139/wlmb/blog.txt create mode 100755 challenge-139/wlmb/perl/ch-1.pl create mode 100755 challenge-139/wlmb/perl/ch-2.pl diff --git a/challenge-139/wlmb/blog.txt b/challenge-139/wlmb/blog.txt new file mode 100644 index 0000000000..cb8992e369 --- /dev/null +++ b/challenge-139/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2021/11/16/PWC139/ diff --git a/challenge-139/wlmb/perl/ch-1.pl b/challenge-139/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..5610caae31 --- /dev/null +++ b/challenge-139/wlmb/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +# Perl weekly challenge 139 +# Task 1: JortSort +# +# See https://wlmb.github.io/2021/11/16/PWC139/#task-1-jortsort +use v5.12; +use warnings; +use List::Util qw(none); +say "Input: (", (join " ",@ARGV), ")"; +my $x; # previous element +my $y=shift @ARGV; # current element +say "Output: ", (none {($x,$y)=($y,$_); $x>$y}@ARGV)?1:0; diff --git a/challenge-139/wlmb/perl/ch-2.pl b/challenge-139/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..7776cb696c --- /dev/null +++ b/challenge-139/wlmb/perl/ch-2.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +# Perl weekly challenge 139 +# Task 2: Long Primes +# +# See https://wlmb.github.io/2021/11/16/PWC139/#task-2-long-primes +use v5.12; +use warnings; +use bignum; +use Math::Prime::Util qw(next_prime); +use List::Util qw(first); +use Text::Wrap qw(wrap $columns $break); +$columns=62; +$break=qr/\s|_/; +my $max_count=shift @ARGV//5; # get number of long primes from command line +my $prime=2; #current prime (will skip '2') +my $count=0; +my @lines; +while($count<$max_count){ + $prime=next_prime($prime); + my $length=$prime-1; # expected length of large cycle + Math::BigFloat->accuracy(3.5*$length); # allow 3+ repetitions + my @groups= grep {$_} split /(\d{$length})/, 1./$prime; # groups of digits + pop @groups; # throw away last (guard) repetition (posibly inexact) + ++$count, push @lines, + "$count-th long prime is $prime", + " as 1/$prime = " . shift(@groups) . join "_", @groups,"..." + if (first # if cycle doesn't stop early + {my $x=10**$_%$prime; $x==1||$x==0} + (1..$prime-1)) + == $prime-1 +} +say wrap("", " _", $_) for @lines; -- cgit From 60f80adda58560bfabecf16e825058b2ac227c42 Mon Sep 17 00:00:00 2001 From: James Smith Date: Wed, 17 Nov 2021 10:38:10 +0000 Subject: Update README.md --- challenge-139/james-smith/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/challenge-139/james-smith/README.md b/challenge-139/james-smith/README.md index b1e418d85e..12cbf5c99d 100644 --- a/challenge-139/james-smith/README.md +++ b/challenge-139/james-smith/README.md @@ -26,7 +26,7 @@ This challenge is relatively easy - to see if the list of numbers if monotonical * Otherwise we set previous number `$p` to the current number and continue * If we get to the end of the list then the list is sorted and we return `1`. -``` +```perl sub in_order { my $p = shift; ($p>$_) ? (return 0) : ($p=$_) for @_; @@ -38,7 +38,7 @@ sub in_order { * We can rewrite the `if( $x ) { y } else { z }` and `($x) ? (y) : (z)`. Why is this useful - well we can then use the brace less postfix `for` for the loop rather than having to use braces. This means the loop becomes 1 line, rather than the longer 7 line version using K&R braces. If you don't cuddle your braces it is even longer! -``` +```perl for (@_) { if( $p>$_ ) { return 0; @@ -50,7 +50,7 @@ sub in_order { Admittedly there is an intermediate version... That uses the exit early approach.. -``` +```perl for (@_) { return 0 if $p>$_; $p = $_; @@ -74,7 +74,7 @@ Now we don't require the actual part of the number repeats which makes the funct This gives us the function below to get the length of the recurring sequence. -``` +```perl sub rec_len { my( $D, $N, $s ) = ( shift, 1, '' ); ( $s, $N ) = ( $s.int($N/$D), ($N%$D).0 ) for 0 .. 2*$D; @@ -89,7 +89,7 @@ So now we have this function we can look at computing the long primes. We know t Therefore we loop through all the odd numbers checking to see if the number is a prime, if it is we then check for the property that the recurring sequence has `$p-1` digits. -``` +```perl my( $N, @primes, @long_primes ) = ( $ARGV[0]||5 ); O: for( my $p=3; @long_primes<$N; $p+=2 ) { -- cgit From f7a7cad2998ddcb34ccb46744c065fd32f25c9e6 Mon Sep 17 00:00:00 2001 From: Steven Wilson Date: Wed, 17 Nov 2021 10:38:29 +0000 Subject: add solution week 139 task 1 in perl --- challenge-139/steven-wilson/perl/ch-1.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 challenge-139/steven-wilson/perl/ch-1.pl diff --git a/challenge-139/steven-wilson/perl/ch-1.pl b/challenge-139/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..6178a43412 --- /dev/null +++ b/challenge-139/steven-wilson/perl/ch-1.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +# Week 139 Task 1 +# JortSort + +use strict; +use warnings; +use feature qw/ say /; +use Test::More; + +my @input1_t = qw/ 1 2 3 4 5 /; +my @input2_t = qw/ 1 3 2 4 5 /; +ok( jortsort( \@input1_t ) == 1, "Sorted" ); +ok( jortsort( \@input2_t ) == 0, "Unsorted" ); +done_testing(); + +sub jortsort { + my $input_ref = shift; + my @input = @{$input_ref}; + my @sorted_input = sort @input; + my $length = scalar @input; + my $sorted = 1; + for ( my $index = 0; $index < $length; $index++ ) { + if ( $input[$index] != $sorted_input[$index] ) { + $sorted = 0; + last; + } + } + return $sorted; +} -- cgit From 3fd6c833bfe376d1afe45be35dc455c1eb9328fb Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 17 Nov 2021 12:33:24 +0000 Subject: - Added solution by Niels van Dijke. --- stats/pwc-current.json | 162 ++--- stats/pwc-language-breakdown-summary.json | 76 +-- stats/pwc-language-breakdown.json | 1006 ++++++++++++++--------------- stats/pwc-leaders.json | 362 +++++------ stats/pwc-summary-1-30.json | 36 +- stats/pwc-summary-121-150.json | 120 ++-- stats/pwc-summary-151-180.json | 48 +- stats/pwc-summary-181-210.json | 32 +- stats/pwc-summary-211-240.json | 112 ++-- stats/pwc-summary-241-270.json | 70 +- stats/pwc-summary-31-60.json | 32 +- stats/pwc-summary-61-90.json | 116 ++-- stats/pwc-summary-91-120.json | 120 ++-- stats/pwc-summary.json | 42 +- 14 files changed, 1167 insertions(+), 1167 deletions(-) diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 317f28f9ec..e8c2c646d6 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,24 +1,45 @@ { - "chart" : { - "type" : "column" + "xAxis" : { + "type" : "category" + }, + "title" : { + "text" : "The Weekly Challenge - 139" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "legend" : { + "enabled" : 0 + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } }, "series" : [ { + "colorByPoint" : 1, "data" : [ { - "drilldown" : "Andrew Shitov", "y" : 1, - "name" : "Andrew Shitov" + "name" : "Andrew Shitov", + "drilldown" : "Andrew Shitov" }, { "drilldown" : "Cheok-Yin Fung", - "y" : 2, - "name" : "Cheok-Yin Fung" + "name" : "Cheok-Yin Fung", + "y" : 2 }, { - "name" : "Cristina Heredia", + "drilldown" : "Cristina Heredia", "y" : 1, - "drilldown" : "Cristina Heredia" + "name" : "Cristina Heredia" }, { "name" : "Dave Jacoby", @@ -32,28 +53,28 @@ }, { "drilldown" : "James Smith", - "y" : 3, - "name" : "James Smith" + "name" : "James Smith", + "y" : 3 }, { - "drilldown" : "Luca Ferrari", + "y" : 6, "name" : "Luca Ferrari", - "y" : 6 + "drilldown" : "Luca Ferrari" }, { - "drilldown" : "Mark Anderson", + "y" : 2, "name" : "Mark Anderson", - "y" : 2 + "drilldown" : "Mark Anderson" }, { - "drilldown" : "Niels van Dijke", "name" : "Niels van Dijke", - "y" : 1 + "y" : 2, + "drilldown" : "Niels van Dijke" }, { - "y" : 1, + "drilldown" : "Olivier Delouya", "name" : "Olivier Delouya", - "drilldown" : "Olivier Delouya" + "y" : 1 }, { "drilldown" : "Paulo Custodio", @@ -67,39 +88,18 @@ }, { "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West", - "y" : 4 + "y" : 4, + "name" : "Roger Bell_West" }, { - "y" : 4, "name" : "Ulrich Rieke", + "y" : 4, "drilldown" : "Ulrich Rieke" } ], - "colorByPoint" : 1, "name" : "The Weekly Challenge - 139" } ], - "tooltip" : { - "pointFormat" : "{point.name}: {point.y:f}
", - "headerFormat" : "{series.name}
", - "followPointer" : 1 - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 - } - }, - "legend" : { - "enabled" : 0 - }, - "subtitle" : { - "text" : "[Champions: 14] Last updated at 2021-11-16 21:07:22 GMT" - }, "drilldown" : { "series" : [ { @@ -113,26 +113,28 @@ "name" : "Andrew Shitov" }, { - "id" : "Cheok-Yin Fung", - "name" : "Cheok-Yin Fung", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Cheok-Yin Fung", + "id" : "Cheok-Yin Fung" }, { - "name" : "Cristina Heredia", - "id" : "Cristina Heredia", "data" : [ [ "Perl", 1 ] - ] + ], + "id" : "Cristina Heredia", + "name" : "Cristina Heredia" }, { + "name" : "Dave Jacoby", + "id" : "Dave Jacoby", "data" : [ [ "Perl", @@ -142,9 +144,7 @@ "Blog", 1 ] - ], - "name" : "Dave Jacoby", - "id" : "Dave Jacoby" + ] }, { "data" : [ @@ -153,10 +153,12 @@ 2 ] ], - "id" : "E. Choroba", - "name" : "E. Choroba" + "name" : "E. Choroba", + "id" : "E. Choroba" }, { + "name" : "James Smith", + "id" : "James Smith", "data" : [ [ "Perl", @@ -166,9 +168,7 @@ "Blog", 1 ] - ], - "name" : "James Smith", - "id" : "James Smith" + ] }, { "name" : "Luca Ferrari", @@ -185,28 +185,28 @@ ] }, { - "name" : "Mark Anderson", - "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "name" : "Mark Anderson", + "id" : "Mark Anderson" }, { - "name" : "Niels van Dijke", "id" : "Niels van Dijke", + "name" : "Niels van Dijke", "data" : [ [ "Perl", - 1 + 2 ] ] }, { - "name" : "Olivier Delouya", "id" : "Olivier Delouya", + "name" : "Olivier Delouya", "data" : [ [ "Perl", @@ -215,14 +215,14 @@ ] }, { + "name" : "Paulo Custodio", + "id" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] - ], - "name" : "Paulo Custodio", - "id" : "Paulo Custodio" + ] }, { "data" : [ @@ -231,12 +231,10 @@ 2 ] ], - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" }, { - "id" : "Roger Bell_West", - "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -246,9 +244,13 @@ "Raku", 2 ] - ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" }, { + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -258,21 +260,19 @@ "Raku", 2 ] - ], - "name" : "Ulrich Rieke", - "id" : "Ulrich Rieke" + ] } ] }, - "xAxis" : { - "type" : "category" + "tooltip" : { + "headerFormat" : "{series.name}
", + "followPointer" : 1, + "pointFormat" : "{point.name}: {point.y:f}
" }, - "title" : { - "text" : "The Weekly Challenge - 139" + "chart" : { + "type" : "column" }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } + "subtitle" : { + "text" : "[Champions: 14] Last updated at 2021-11-17 12:12:00 GMT" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 2c9d3385ef..c1db5d038d 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,24 +1,27 @@ { - "tooltip" : { - "pointFormat" : "{point.y:.0f}" + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + } + } }, - "chart" : { - "type" : "column" + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2021]" + }, + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } + }, + "legend" : { + "enabled" : "false" }, "series" : [ { - "dataLabels" : { - "rotation" : -90, - "align" : "right", - "format" : "{point.y:.0f}", - "y" : 10, - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" - }, - "color" : "#FFFFFF", - "enabled" : "true" - }, "name" : "Contributions", "data" : [ [ @@ -27,37 +30,34 @@ ], [ "Perl", - 6662 + 6663 ], [ "Raku", 4029 ] - ] + ], + "dataLabels" : { + "enabled" : "true", + "align" : "right", + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + }, + "rotation" : -90, + "color" : "#FFFFFF", + "y" : 10, + "format" : "{point.y:.0f}" + } } ], - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2021]" - }, - "xAxis" : { - "labels" : { - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" - } - }, - "type" : "category" + "tooltip" : { + "pointFormat" : "{point.y:.0f}" }, "subtitle" : { - "text" : "Last updated at 2021-11-16 21:07:22 GMT" + "text" : "Last updated at 2021-11-17 12:12:00 GMT" }, - "legend" : { - "enabled" : "false" + "chart" : { + "type" : "column" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 1e21c0c3eb..ec16365ed9 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,54 +1,86 @@ { + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "title" : { + "text" : "The Weekly Challenge Language" + }, + "xAxis" : { + "type" : "category" + }, + "tooltip" : { + "pointFormat" : "Challenge {point.name}: {point.y:f}
", + "followPointer" : "true", + "headerFormat" : "" + }, + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2021-11-17 12:12:00 GMT" + }, "chart" : { "type" : "column" }, + "legend" : { + "enabled" : "false" + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 + } + }, "series" : [ { "name" : "The Weekly Challenge Languages", + "colorByPoint" : "true", "data" : [ { - "y" : 161, "name" : "#001", + "y" : 161, "drilldown" : "001" }, { "drilldown" : "002", - "name" : "#002", - "y" : 125 + "y" : 125, + "name" : "#002" }, { "drilldown" : "003", - "y" : 83, - "name" : "#003" + "name" : "#003", + "y" : 83 }, { - "name" : "#004", + "drilldown" : "004", "y" : 99, - "drilldown" : "004" + "name" : "#004" }, { "drilldown" : "005", - "name" : "#005", - "y" : 78 + "y" : 78, + "name" : "#005" }, { - "drilldown" : "006", "y" : 58, - "name" : "#006" + "name" : "#006", + "drilldown" : "006" }, { + "drilldown" : "007", "name" : "#007", - "y" : 64, - "drilldown" : "007" + "y" : 64 }, { - "drilldown" : "008", + "y" : 78, "name" : "#008", - "y" : 78 + "drilldown" : "008" }, { - "name" : "#009", "y" : 76, + "name" : "#009", "drilldown" : "009" }, { @@ -73,33 +105,33 @@ }, { "drilldown" : "014", - "y" : 101, - "name" : "#014" + "name" : "#014", + "y" : 101 }, { + "drilldown" : "015", "name" : "#015", - "y" : 99, - "drilldown" : "015" + "y" : 99 }, { "drilldown" : "016", - "name" : "#016", - "y" : 71 + "y" : 71, + "name" : "#016" }, { - "y" : 84, + "drilldown" : "017", "name" : "#017", - "drilldown" : "017" + "y" : 84 }, { "drilldown" : "018", - "y" : 81, - "name" : "#018" + "name" : "#018", + "y" : 81 }, { + "drilldown" : "019", "name" : "#019", - "y" : 103, - "drilldown" : "019" + "y" : 103 }, { "drilldown" : "020", @@ -107,39 +139,39 @@ "y" : 101 }, { - "drilldown" : "021", + "name" : "#021", "y" : 72, - "name" : "#021" + "drilldown" : "021" }, { + "drilldown" : "022", "y" : 68, - "name" : "#022", - "drilldown" : "022" + "name" : "#022" }, { - "y" : 97, "name" : "#023", + "y" : 97, "drilldown" : "023" }, { - "name" : "#024", "y" : 75, + "name" : "#024", "drilldown" : "024" }, { + "drilldown" : "025", "name" : "#025", - "y" : 59, - "drilldown" : "025" + "y" : 59 }, { "drilldown" : "026", - "y" : 74, - "name" : "#026" + "name" : "#026", + "y" : 74 }, { - "drilldown" : "027", + "name" : "#027", "y" : 60, - "name" : "#027" + "drilldown" : "027" }, { "name" : "#028", @@ -147,34 +179,34 @@ "drilldown" : "028" }, { - "drilldown" : "029", "y" : 79, - "name" : "#029" + "name" : "#029", + "drilldown" : "029" }, { - "drilldown" : "030", + "name" : "#030", "y" : 117, - "name" : "#030" + "drilldown" : "030" }, { "drilldown" : "031", - "name" : "#031", - "y" : 89 + "y" : 89, + "name" : "#031" }, { - "name" : "#032", "y" : 94, + "name" : "#032", "drilldown" : "032" }, { + "drilldown" : "033", "name" : "#033", - "y" : 110, - "drilldown" : "033" + "y" : 110 }, { "drilldown" : "034", - "name" : "#034", - "y" : 64 + "y" : 64, + "name" : "#034" }, { "name" : "#035", @@ -182,14 +214,14 @@ "drilldown" : "035" }, { - "drilldown" : "036", + "y" : 68, "name" : "#036", - "y" : 68 + "drilldown" : "036" }, { - "name" : "#037", + "drilldown" : "037", "y" : 67, - "drilldown" : "037" + "name" : "#037" }, { "drilldown" : "038", @@ -197,34 +229,34 @@ "name" : "#038" }, { - "y" : 62, + "drilldown" : "039", "name" : "#039", - "drilldown" : "039" + "y" : 62 }, { "drilldown" : "040", - "name" : "#040", - "y" : 73 + "y" : 73, + "name" : "#040" }, { - "drilldown" : "041", "y" : 76, - "name" : "#041" + "name" : "#041", + "drilldown" : "041" }, { - "drilldown" : "042", "name" : "#042", - "y" : 92 + "y" : 92, + "drilldown" : "042" }, { - "drilldown" : "043", + "y" : 68, "name" : "#043", - "y" : 68 + "drilldown" : "043" }, { - "y" : 85, + "drilldown" : "044", "name" : "#044", - "drilldown" : "044" + "y" : 85 }, { "drilldown" : "045", @@ -232,69 +264,69 @@ "y" : 96 }, { + "drilldown" : "046", "name" : "#046", - "y" : 87, - "drilldown" : "046" + "y" : 87 }, { - "y" : 84, + "drilldown" : "047", "name" : "#047", - "drilldown" : "047" + "y" : 84 }, { + "drilldown" : "048", "y" : 108, - "name" : "#048", - "drilldown" : "048" + "name" : "#048" }, { - "drilldown" : "049", + "name" : "#049", "y" : 89, - "name" : "#049" + "drilldown" : "049" }, { - "y" : 98, + "drilldown" : "050", "name" : "#050", - "drilldown" : "050" + "y" : 98 }, { - "y" : 89, + "drilldown" : "051", "name" : "#051", - "drilldown" : "051" + "y" : 89 }, { - "y" : 91, + "drilldown" : "052", "name" : "#052", - "drilldown" : "052" + "y" : 91 }, { - "y" : 101, + "drilldown" : "053", "name" : "#053", - "drilldown" : "053" + "y" : 101 }, { - "drilldown" : "054", + "y" : 103, "name" : "#054", - "y" : 103 + "drilldown" : "054" }, { + "drilldown" : "055", "name" : "#055", - "y" : 88, - "drilldown" : "055" + "y" : 88 }, { - "drilldown" : "056", "y" : 95, - "name" : "#056" + "name" : "#056", + "drilldown" : "056" }, { - "drilldown" : "057", + "name" : "#057", "y" : 80, - "name" : "#057" + "drilldown" : "057" }, { + "drilldown" : "058", "name" : "#058", - "y" : 69, - "drilldown" : "058" + "y" : 69 }, { "name" : "#059", @@ -302,13 +334,13 @@ "drilldown" : "059" }, { - "drilldown" : "060", + "name" : "#060", "y" : 85, - "name" : "#060" + "drilldown" : "060" }, { - "name" : "#061", "y" : 81, + "name" : "#061", "drilldown" : "061" }, { @@ -322,9 +354,9 @@ "name" : "#063" }, { - "drilldown" : "064", + "y" : 80, "name" : "#064", - "y" : 80 + "drilldown" : "064" }, { "drilldown" : "065", @@ -332,24 +364,24 @@ "y" : 73 }, { - "drilldown" : "066", "y" : 84, - "name" : "#066" + "name" : "#066", + "drilldown" : "066" }, { - "y" : 90, "name" : "#067", + "y" : 90, "drilldown" : "067" }, { - "drilldown" : "068", "y" : 75, - "name" : "#068" + "name" : "#068", + "drilldown" : "068" }, { + "drilldown" : "069", "y" : 83, - "name" : "#069", - "drilldown" : "069" + "name" : "#069" }, { "y" : 93, @@ -367,13 +399,13 @@ "drilldown" : "072" }, { - "drilldown" : "073", "y" : 110, - "name" : "#073" + "name" : "#073", + "drilldown" : "073" }, { - "y" : 115, "name" : "#074", + "y" : 115, "drilldown" : "074" }, { @@ -382,24 +414,24 @@ "name" : "#075" }, { - "drilldown" : "076", "name" : "#076", - "y" : 99 + "y" : 99, + "drilldown" : "076" }, { "drilldown" : "077", - "y" : 98,