diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-06-21 19:53:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-21 19:53:45 +0100 |
| commit | 634bd41951fe59ea15b3fb7ace85fff33fe4b7ea (patch) | |
| tree | a38ead3fc27f81a0a74ed50fbfd5c8d72760cdcc | |
| parent | 81cfb6211946c15f45696f3102a57d3aede7a4c4 (diff) | |
| parent | 12a265d121dac360466a7d8e6109d5d4de1fbcbe (diff) | |
| download | perlweeklychallenge-club-634bd41951fe59ea15b3fb7ace85fff33fe4b7ea.tar.gz perlweeklychallenge-club-634bd41951fe59ea15b3fb7ace85fff33fe4b7ea.tar.bz2 perlweeklychallenge-club-634bd41951fe59ea15b3fb7ace85fff33fe4b7ea.zip | |
Merge pull request #6301 from Firedrake/rogerbw-challenge-170
Solutions for challenge #170
18 files changed, 1221 insertions, 0 deletions
diff --git a/challenge-170/roger-bell-west/javascript/ch-1.js b/challenge-170/roger-bell-west/javascript/ch-1.js new file mode 100755 index 0000000000..e593a64e8b --- /dev/null +++ b/challenge-170/roger-bell-west/javascript/ch-1.js @@ -0,0 +1,91 @@ +#! /usr/bin/node +function deepEqual(a,b) +{ + if( (typeof a == 'object' && a != null) && + (typeof b == 'object' && b != null) ) + { + var count = [0,0] + for( var key in a) count[0]++ + for( var key in b) count[1]++ + if( count[0]-count[1] != 0) {return false} + for( var key in a) + { + if(!(key in b) || !deepEqual(a[key],b[key])) {return false} + } + for( var key in b) + { + if(!(key in a) || !deepEqual(b[key],a[key])) {return false} + } + return true + } + else + { + return a === b + } +} + +function genprimes(mx) { + let primesh=new Set([2,3]) + for (let i = 6; i <= mx; i += 6) { + for (let j = i-1; j <= i+1; j += 2) { + if (j <= mx) { + primesh.add(j); + } + } + } + let q=[2,3,5,7]; + let p=q.shift(); + let mr=Math.floor(Math.sqrt(mx)); + while (p <= mr) { + if (primesh.has(p)) { + let i=p*p + for (let i=p*p; i <= mx; i += p) { + primesh.delete(i); + } + } + if (q.length < 2) { + q.push(q[q.length-1]+4); + q.push(q[q.length-1]+2); + } + p=q.shift(); + } + let primes=[...primesh]; + primes.sort(function(a,b) { + return a-b; + }); + return primes; +} + +function nthprimelimit(n) { + let m=15; + if (n >= 6) { + m=Math.floor(1+n*Math.log(n*Math.log(n))); + } + return m +} + +function primorial (ct) { + let o = [1] + for (let p of genprimes(nthprimelimit(ct-1))) { + o.push(o[o.length-1] * p) + if (o.length >= ct) { + break + } + } + return o +} + +if (deepEqual(primorial(5),[1, 2, 6, 30, 210])) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); + +if (deepEqual(primorial(10),[1, 2, 6, 30, 210, 2310, 30030, 510510, + 9699690, 223092870])) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); diff --git a/challenge-170/roger-bell-west/javascript/ch-2.js b/challenge-170/roger-bell-west/javascript/ch-2.js new file mode 100755 index 0000000000..fa60f0dccb --- /dev/null +++ b/challenge-170/roger-bell-west/javascript/ch-2.js @@ -0,0 +1,59 @@ +#! /usr/bin/node +function deepEqual(a,b) +{ + if( (typeof a == 'object' && a != null) && + (typeof b == 'object' && b != null) ) + { + var count = [0,0] + for( var key in a) count[0]++ + for( var key in b) count[1]++ + if( count[0]-count[1] != 0) {return false} + for( var key in a) + { + if(!(key in b) || !deepEqual(a[key],b[key])) {return false} + } + for( var key in b) + { + if(!(key in a) || !deepEqual(b[key],a[key])) {return false} + } + return true + } + else + { + return a === b + } +} + +function kronecker (a,b) { + let o = []; + let ax = a[0].length; + let ay = a.length; + let bx = b[0].length; + let by = b.length; + for (let y = 0; y < ay * by; y++) { + let byi = y % by; + let ayi = Math.floor(y/by); + let row = [] + for (let x = 0; x < ax * bx; x++) { + let bxi = x % bx; + let axi = Math.floor(x/bx); + row.push(a[ayi][axi] * b[byi][bxi]); + } + o.push(row) + } + return o +} + +if (deepEqual(kronecker([[1,2],[3,4]], + [[5,6],[7,8]]), + [ + [ 5, 6, 10, 12], + [ 7, 8, 14, 16], + [15, 18, 20, 24], + [21, 24, 28, 32] + ])) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); diff --git a/challenge-170/roger-bell-west/kotlin/ch-1.kt b/challenge-170/roger-bell-west/kotlin/ch-1.kt new file mode 100644 index 0000000000..c1c596b29c --- /dev/null +++ b/challenge-170/roger-bell-west/kotlin/ch-1.kt @@ -0,0 +1,70 @@ +import kotlin.math.* + +fun genprimes(mx: Int): ArrayList<Int> { + var primesh=mutableSetOf<Int>() + for (i in 2..3) { + primesh.add(i) + } + for (i in 6..mx+1 step 6) { + for (j in i-1..i+1 step 2) { + if (j <= mx) { + primesh.add(j) + } + } + } + var q=ArrayDeque(listOf(2,3,5,7)) + var p=q.removeFirst() + val mr=sqrt(mx.toDouble()).toInt() + while (p <= mr) { + if (primesh.contains(p)) { + for (i in p*p..mx step p) { + primesh.remove(i) + } + } + if (q.size < 2) { + q.add(q.last()+4) + q.add(q.last()+2) + } + p=q.removeFirst() + } + var primes=ArrayList(primesh.distinct()) + primes.sort() + return primes +} + +fun nthprimelimit(n: Int): Int { + var m=15 + if (n >= 6) { + val nn=n.toDouble() + m=1+(nn*ln(nn*ln(nn))).toInt() + } + return m +} + +fun primorial(ct: Int): MutableList<Int> { + var o = mutableListOf(1) + for (p in genprimes(nthprimelimit(ct-1))) { + o.add(o.lastOrNull()!! * p) + if (o.size >= ct) { + break + } + } + return o +} + +fun main() { + if (primorial(5) == listOf(1, 2, 6, 30, 210)) { + print("Pass") + } else { + print("FAIL") + } + print(" ") + + if (primorial(10) == listOf(1, 2, 6, 30, 210, 2310, 30030, 510510, + 9699690, 223092870)) { + print("Pass") + } else { + print("FAIL") + } + println("") +} diff --git a/challenge-170/roger-bell-west/kotlin/ch-2.kt b/challenge-170/roger-bell-west/kotlin/ch-2.kt new file mode 100644 index 0000000000..54868da2a2 --- /dev/null +++ b/challenge-170/roger-bell-west/kotlin/ch-2.kt @@ -0,0 +1,35 @@ +fun kronecker(a: ArrayList<ArrayList<Int>>, b: ArrayList<ArrayList<Int>>): ArrayList<ArrayList<Int>> { + var o = ArrayList<ArrayList<Int>>() + val ax = a[0].size + val ay = a.size + val bx = b[0].size + val bY = b.size + for (y in 0..ay*bY - 1) { + val byi = y % bY + val ayi = y / bY + var row = ArrayList<Int>() + for (x in 0..ax*bx - 1) { + val bxi = x % bx + val axi = x / bx + row.add(a[ayi][axi] * b[byi][bxi]) + } + o.add(row) + } + return o +} + +fun main() { + if (kronecker(arrayListOf(arrayListOf(1,2),arrayListOf(3,4)), + arrayListOf(arrayListOf(5,6),arrayListOf(7,8)) + ) == arrayListOf( + arrayListOf( 5, 6, 10, 12), + arrayListOf( 7, 8, 14, 16), + arrayListOf(15, 18, 20, 24), + arrayListOf(21, 24, 28, 32) + )) { + print("Pass") + } else { + print("FAIL") + } + println("") +} diff --git a/challenge-170/roger-bell-west/lua/ch-1.lua b/challenge-170/roger-bell-west/lua/ch-1.lua new file mode 100755 index 0000000000..23f67fab90 --- /dev/null +++ b/challenge-170/roger-bell-west/lua/ch-1.lua @@ -0,0 +1,98 @@ +#! /usr/bin/lua + +-- by Michael Anderson at +-- https://stackoverflow.com/questions/8722620/comparing-two-index-tables-by-index-value-in-lua +function recursive_compare(t1,t2) + -- Use usual comparison first. + if t1==t2 then return true end + -- We only support non-default behavior for tables + if (type(t1)~="table") then return false end + -- They better have the same metatables + local mt1 = getmetatable(t1) + local mt2 = getmetatable(t2) + if( not recursive_compare(mt1,mt2) ) then return false end + + -- Check each key-value pair + -- We have to do this both ways in case we miss some. + -- TODO: Could probably be smarter and not check those we've + -- already checked though! + for k1,v1 in pairs(t1) do + local v2 = t2[k1] + if( not recursive_compare(v1,v2) ) then return false end + end + for k2,v2 in pairs(t2) do + local v1 = t1[k2] + if( not recursive_compare(v1,v2) ) then return false end + end + + return true +end + +function genprimes(mx) + local primesh = {} + for i = 2, 3 do + primesh[i] = true + end + for i = 6, mx, 6 do + for j = i-1, i+1, 2 do + if j <= mx then + primesh[j]=true + end + end + end + local q={2,3,5,7} + local p=table.remove(q,1) + local mr=math.floor(math.sqrt(mx)) + while p <= mr do + if primesh[p] ~= nil then + for i = p*p,mx,p do + primesh[i] = nil + end + end + if #q < 2 then + table.insert(q,q[#q]+4) + table.insert(q,q[#q]+2) + end + p=table.remove(q,1) + end + local primes = {} + for k,v in pairs(primesh) do + table.insert(primes,k) + end + table.sort(primes) + return primes +end + +function nthprimelimit(n) + local m=15 + if n >= 6 then + m=1+n*math.log(n*math.log(n)) + end + return m +end + +function primorial(ct) + local o={1} + for k,p in pairs(genprimes(nthprimelimit(ct-1))) do + table.insert(o,o[#o] * p) + if #o >= ct then + break + end + end + return o +end + +if recursive_compare(primorial(5), {1, 2, 6, 30, 210}) then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if recursive_compare(primorial(10), {1, 2, 6, 30, 210, 2310, 30030, + 510510, 9699690, 223092870}) then + io.write("Pass") +else + io.write("FAIL") +end +print("") diff --git a/challenge-170/roger-bell-west/lua/ch-2.lua b/challenge-170/roger-bell-west/lua/ch-2.lua new file mode 100755 index 0000000000..2a77dabebe --- /dev/null +++ b/challenge-170/roger-bell-west/lua/ch-2.lua @@ -0,0 +1,65 @@ +#! /usr/bin/lua + +-- by Michael Anderson at +-- https://stackoverflow.com/questions/8722620/comparing-two-index-tables-by-index-value-in-lua +function recursive_compare(t1,t2) + -- Use usual comparison first. + if t1==t2 then return true end + -- We only support non-default behavior for tables + if (type(t1)~="table") then return false end + -- They better have the same metatables + local mt1 = getmetatable(t1) + local mt2 = getmetatable(t2) + if( not recursive_compare(mt1,mt2) ) then return false end + + -- Check each key-value pair + -- We have to do this both ways in case we miss some. + -- TODO: Could probably be smarter and not check those we've + -- already checked though! + for k1,v1 in pairs(t1) do + local v2 = t2[k1] + if( not recursive_compare(v1,v2) ) then return false end + end + for k2,v2 in pairs(t2) do + local v1 = t1[k2] + if( not recursive_compare(v1,v2) ) then return false end + end + + return true +end + +function kronecker(a,b) + local o = {} + local ax = #a[1] + local ay = #a + local bx = #b[1] + local by = #b + for y = 0, ay * by - 1 do + local byi = y % by + local ayi = math.floor(y / by) + local row = {} + for x = 0, ax * bx - 1 do + local bxi = x % bx + local axi = math.floor(x / bx) + table.insert(row,a[ayi+1][axi+1] * b[byi+1][bxi+1]) + end + table.insert(o,row) + end + return o +end + +if recursive_compare(kronecker( + {{1,2},{3,4}}, + {{5,6},{7,8}} + ), + { + { 5, 6, 10, 12}, + { 7, 8, 14, 16}, + {15, 18, 20, 24}, + {21, 24, 28, 32} + }) then + io.write("Pass") +else + io.write("FAIL") +end +print("") diff --git a/challenge-170/roger-bell-west/perl/ch-1.pl b/challenge-170/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..ac39732f0c --- /dev/null +++ b/challenge-170/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,35 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use experimental 'signatures'; + +use Test::More tests => 2; +use Math::Prime::Util qw(next_prime); + +is_deeply(primorial(5), + [1, 2, 6, 30, 210], + 'example 1'); + +is_deeply(primorial(10), + [1, 2, 6, 30, 210, 2310, 30030, 510510, 9699690, 223092870], + 'example 2'); + +sub nthprimelimit { + my $n=shift; + my $m=15; + if ($n >= 6) { + $m=int(1+$n*log($n*log($n))); + } + return $m; +} + +sub primorial($ct) { + my @o = (1); + my $lp = 1; + while (scalar @o < $ct) { + $lp = next_prime($lp); + push @o,$o[-1] * $lp; + } + return \@o; +} diff --git a/challenge-170/roger-bell-west/perl/ch-2.pl b/challenge-170/roger-bell-west/perl/ch-2.pl new file mode 100755 index 0000000000..6fd7a0ea2c --- /dev/null +++ b/challenge-170/roger-bell-west/perl/ch-2.pl @@ -0,0 +1,37 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use experimental 'signatures'; + +use Test::More tests => 1; + +is_deeply(kronecker([[1,2],[3,4]], + [[5,6],[7,8]]), + [ + [ 5, 6, 10, 12], + [ 7, 8, 14, 16], + [15, 18, 20, 24], + [21, 24, 28, 32] + ], + 'example 1'); + +sub kronecker($a,$b) { + my @o; + my $ax = scalar @{$a->[0]}; + my $ay = scalar @{$a}; + my $bx = scalar @{$b->[0]}; + my $by = scalar @{$b}; + foreach my $y (0..$ay*$by-1) { + my $byi = $y % $by; + my $ayi = int($y / $by); + my @row; + foreach my $x (0..$ax*$bx-1) { + my $bxi = $x % $bx; + my $axi = int($x / $bx); + push @row,$a->[$ayi][$axi] * $b->[$byi][$bxi]; + } + push @o,\@row; + } + return \@o; +} diff --git a/challenge-170/roger-bell-west/postscript/ch-1.ps b/challenge-170/roger-bell-west/postscript/ch-1.ps new file mode 100644 index 0000000000..b3be9c1179 --- /dev/null +++ b/challenge-170/roger-bell-west/postscript/ch-1.ps @@ -0,0 +1,248 @@ +%!PS + +% begin included library code + +/test.start { + print (:) print + /test.pass 0 def + /test.count 0 def +} bind def + +/test.end { + ( ) print + test.count 0 gt { + (Passed ) print + test.pass (...) cvs print + (/) print + test.count (...) cvs print + ( \() print + test.pass 100 mul test.count idiv (...) cvs print + (%\)) print + (\r\n) print + } if +} bind def + +/apush { apush.right } bind def + + +/keys { % dict -> array of dict keys + [ exch + { + pop + } forall + ] +} bind def + +/test { + /test.count test.count 1 add def + { + /test.pass test.pass 1 add def + } { + ( ) print + test.count (....) cvs print + (-fail) print + } ifelse +} bind def + +/apush.right { % [a b] c -> [a b c] + exch + [ exch aload length 2 add -1 roll ] +} bind def + +/quicksort.main { % lo hi -> (null) + 3 dict begin + /hi exch def + /lo exch def + /xit false def + lo 0 lt { + /xit true def + } if + hi 0 lt { + /xit true def + } if + lo hi ge { + /xit true def + } if + xit not { + /p quicksort.partition def + lo p quicksort.main + p 1 add hi quicksort.main + } if + end +} bind def + +/quicksort.partition { + 3 dict begin + /pivot arr hi lo add 2 idiv get def + /i lo 1 sub def + /j hi 1 add def + { + { + /i i 1 add def + arr i get pivot ge { + exit + } if + } loop + { + /j j 1 sub def + arr j get pivot le { + exit + } if + } loop + i j ge { + j + exit + } if + i j quicksort.swap + } loop + end +} bind def + +/quicksort { % [ a c b ] -> [ a b c ] + 1 dict begin + /arr exch def + 0 arr length 1 sub quicksort.main + arr + end +} bind def + +/nthprimelimit { + 2 dict begin + /n exch def + /m 15 def + n 6 ge { + /m n ln n mul ln n mul 1 add cvi def + } if + m + end +} bind def + +/deepeq { + 2 dict begin + /a exch def + /b exch def + a type b type eq { + a type /dicttype eq { + a length b length eq { + << + a { + pop + true + } forall + b { + pop + true + } forall + >> + true exch + { + pop + dup a exch known { + dup b exch known { + dup a exch get exch b exch get deepeq not { + pop false + } if + } { + false + } ifelse + } { + false + } ifelse + } forall + } { + false + } ifelse + } { + a type dup /arraytype eq exch /stringtype eq or { + a length b length eq { + true + 0 1 a length 1 sub { + dup a exch get exch b exch get deepeq not { + pop false + exit + } if + } for + } { + false + } ifelse + } { + a b eq + } ifelse + } ifelse + } { + false + } ifelse + end +} bind def + +/genprimes { + /mx exch def + /primesh mx dict def + 2 1 3 { + primesh exch true put + } for + 6 6 mx 1 add { + dup 1 sub exch 1 add 2 exch { + dup mx le { + primesh exch true put + } { + pop + } ifelse + } for + } for + /q [ 3 5 7 ] def + /qi 0 def + /p 2 def + /mr mx sqrt cvi def + { + p mr le not { + exit + } if + primesh p known { + p dup mul p mx { + primesh exch undef + } for + } if + q length qi sub 2 le { + /q q q q length 1 sub get 4 add apush def + /q q q q length 1 sub get 2 add apush def + } if + /p q qi get def + /qi qi 1 add def + } loop + primesh keys +} bind def + +/quicksort.swap { + 2 dict begin + /bi exch def + /ai exch def + arr ai get + arr bi get + arr exch ai exch put + arr exch bi exch put + end +} bind def + +% end included library code + +/primorial { + 2 dict begin + /ct exch def + /o [ 1 ] def + ct 1 sub nthprimelimit genprimes quicksort { + o o length 1 sub get mul + o exch apush /o exch def + o length ct ge { + exit + } if + } forall + o + end +} bind def + +(primorial) test.start +5 primorial [ 1 2 6 30 210 ] deepeq test +10 primorial [ 1 2 6 30 210 2310 30030 510510 9699690 223092870 ] +deepeq test +test.end diff --git a/challenge-170/roger-bell-west/postscript/ch-2.ps b/challenge-170/roger-bell-west/postscript/ch-2.ps new file mode 100644 index 0000000000..8cba5763ec --- /dev/null +++ b/challenge-170/roger-bell-west/postscript/ch-2.ps @@ -0,0 +1,128 @@ +%!PS + +% begin included library code + +/test.end { + ( ) print + test.count 0 gt { + (Passed ) print + test.pass (...) cvs print + (/) print + test.count (...) cvs print + ( \() print + test.pass 100 mul test.count idiv (...) cvs print + (%\)) print + (\r\n) print + } if +} bind def + +/test { + /test.count test.count 1 add def + { + /test.pass test.pass 1 add def + } { + ( ) print + test.count (....) cvs print + (-fail) print + } ifelse +} bind def + +/test.start { + print (:) print + /test.pass 0 def + /test.count 0 def +} bind def + +/deepeq { + 2 dict begin + /a exch def + /b exch def + a type b type eq { + a type /dicttype eq { + a length b length eq { + << + a { + pop + true + } forall + b { + pop + true + } forall + >> + true exch + { + pop + dup a exch known { + dup b exch known { + dup a exch get exch b exch get deepeq not { + pop false + } if + } { + false + } ifelse + } { + false + } ifelse + } forall + } { + false + } ifelse + } { + a type dup /arraytype eq exch /stringtype eq or { + a length b length eq { + true + 0 1 a length 1 sub { + dup a exch get exch b exch get deepeq not { + pop false + exit + } if + } for + } { + false + } ifelse + } { + a b eq + } ifelse + } ifelse + } { + false + } ifelse + end +} bind def + +% end included library code + +/kronecker { + 12 dict begin + /b exch def + /a exch def + /ax a 0 get length def + /ay a length def + /bx b 0 get length def + /by b length def + [ + 0 1 ay by mul 1 sub { + /y exch def + /byi y by mod def + /ayi y by idiv def + [ + 0 1 ax bx mul 1 sub { + /x exch def + /bxi x bx mod def + /axi x bx idiv def + a ayi get axi get b byi get bxi get mul + } for + ] + } for + ] + end +} bind def + +(kronecker) test.start +[ [1 2] [3 4] ] [ [5 6] [7 8] ] kronecker +[ [ 5 6 10 12] + [ 7 8 14 16] + [15 18 20 24] + [21 24 28 32] ] deepeq test +test.end diff --git a/challenge-170/roger-bell-west/python/ch-1.py b/challenge-170/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..3a4333850a --- /dev/null +++ b/challenge-170/roger-bell-west/python/ch-1.py @@ -0,0 +1,54 @@ +#! /usr/bin/python3 + +import unittest + +from math import sqrt,floor,log +from collections import deque + +def genprimes(mx): + primesh=set(range(2,4)) + for i in range(6,mx+2,6): + for j in range(i-1,i+2,2): + if j <= mx: + primesh.add(j) + q=deque([2,3,5,7]) + p=q.popleft() + mr=floor(sqrt(mx)) + while p <= mr: + if p in primesh: + for i in range(p*p,mx+1,p): + primesh.discard(i) + if len(q) < 2: + q.append(q[-1]+4) + q.append(q[-1]+2) + p=q.popleft() + primes=list(primesh) + primes.sort() + return primes + +def nthprimelimit(n): + m=15 + if n >= 6: + m=floor(1+n*log(n*log(n))) + return m + +def primorial(ct): + o = [1] + for p in genprimes(nthprimelimit(ct-1)): + o.append(o[-1] * p) + if len(o) >= ct: + break + return o + +class TestPrimorial(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(primorial(5), + [1, 2, 6, 30, 210],'example 1') + + def test_ex2(self): + self.assertEqual(primorial(10), + [1, 2, 6, 30, 210, 2310, 30030, 510510, + 9699690, 223092870],'example 1') + +unittest.main() diff --git a/challenge-170/roger-bell-west/python/ch-2.py b/challenge-170/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..810be40488 --- /dev/null +++ b/challenge-170/roger-bell-west/python/ch-2.py @@ -0,0 +1,32 @@ +#! /usr/bin/python3 + +import unittest + +def kronecker(a,b): + o = [] + ax = len(a[0]) + ay = len(a) + bx = len(b[0]) + by = len(b) + for y in range(ay * by): + byi = y % by + ayi = y // by + row = [] + for x in range(ax * bx): + bxi = x % bx + axi = x // bx + row.append(a[ayi][axi] * b[byi][bxi]) + o.append(row) + return o + +class TestKronecker(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(kronecker([[1,2],[3,4]], + [[5,6],[7,8]]), + [[ 5, 6, 10, 12], + [ 7, 8, 14, 16], + [15, 18, 20, 24], + [21, 24, 28, 32]],'example 1') + +unittest.main() diff --git a/challenge-170/roger-bell-west/raku/ch-1.p6 b/challenge-170/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..3413da3006 --- /dev/null +++ b/challenge-170/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,65 @@ +#! /usr/bin/perl6 + +use Test; + +plan 2; + +is-deeply(primorial(5), + [1, 2, 6, 30, 210], + 'example 1'); + +is-deeply(primorial(10), + [1, 2, 6, 30, 210, 2310, 30030, 510510, 9699690, 223092870], + 'example 2'); + +sub genprimes($mx) { + my @primes; + { + my $primesh=(2,3).SetHash; + loop (my $i=6;$i <= $mx+1; $i += 6) { + for ($i-1,$i+1) -> $j { + if ($j <= $mx) { + $primesh{$j}=True; |
