From 843ae71ccbb7fa04ed6516ffac85c8fabbbc30b2 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Wed, 19 Jan 2022 12:38:11 +0100 Subject: gitignore --- .gitignore | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/.gitignore b/.gitignore index ba8194b15c..722d5e71d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1 @@ -.idea -.precomp/ -.DS_Store -.vstags .vscode -.*.swp -*~ -*.class -*.exe -*.o -*.obj -*.ali -*.bak -ch-1 -ch-2 -ch_1 -ch_2 -go.mod -go.sum -tags - -# Rust languageoutput directory -target/ -- cgit From b3dbe594ff98914d6e75cc8e6cc9f59afa9f7101 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 24 Jan 2022 07:38:28 +0000 Subject: Challenge 149 Solutions (Raku) --- challenge-149/mark-anderson/raku/ch-1.raku | 15 +++++++++++++++ challenge-149/mark-anderson/raku/ch-2.raku | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 challenge-149/mark-anderson/raku/ch-1.raku create mode 100644 challenge-149/mark-anderson/raku/ch-2.raku diff --git a/challenge-149/mark-anderson/raku/ch-1.raku b/challenge-149/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..7d595e5fe2 --- /dev/null +++ b/challenge-149/mark-anderson/raku/ch-1.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + +use Test; + +is-deeply fibonacci-digit-sum(20), +(0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44); + +is fibonacci-digit-sum(10000).tail, 98809; + +sub fibonacci-digit-sum(\n) +{ + my @fib = 0, 1, * + * ... 55; # good enough for numbers <= 9,999,991 + + (^Inf).grep({ .comb.sum (elem) @fib })[^n]; +} diff --git a/challenge-149/mark-anderson/raku/ch-2.raku b/challenge-149/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..4812afcd34 --- /dev/null +++ b/challenge-149/mark-anderson/raku/ch-2.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +use Test; + +is largest-square(2), '1'; +is largest-square(4), '3201'; +is largest-square(10), '9814072356'; +is largest-square(12), 'B8750A649321'; + +sub largest-square(\base) +{ + my $d = (base.pred...0).map({.base(base)}).join + .parse-base(base).sqrt.floor; + + loop + { + my \b = ($d-- ** 2).base(base); + return b if b.comb.Bag.values.max == 1; + } +} -- cgit From 2e43471a3281a74e0b8ba89de28316bc3b89cd6f Mon Sep 17 00:00:00 2001 From: Simon Green Date: Mon, 24 Jan 2022 18:53:50 +1100 Subject: No solutions last week --- challenge-148/sgreen/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 challenge-148/sgreen/README.md diff --git a/challenge-148/sgreen/README.md b/challenge-148/sgreen/README.md deleted file mode 100644 index 40c85b3a56..0000000000 --- a/challenge-148/sgreen/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# The Weekly Challenge 147 - -Solution by Simon Green. [Blog - Look mum, no inputs ๐Ÿ˜›](https://dev.to/simongreennet/look-mum-no-inputs-3lon) -- cgit From 5938deb5fb2f922651079cf3cf270032ded0a6e0 Mon Sep 17 00:00:00 2001 From: Jan Krลˆรกvek Date: Mon, 24 Jan 2022 09:08:53 +0100 Subject: solution week 148 --- challenge-148/wambash/raku/ch-1.raku | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 challenge-148/wambash/raku/ch-1.raku diff --git a/challenge-148/wambash/raku/ch-1.raku b/challenge-148/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..d445cd8c16 --- /dev/null +++ b/challenge-148/wambash/raku/ch-1.raku @@ -0,0 +1,7 @@ +#!#!/usr/bin/env raku + +multi MAIN () { + "",3,4,5,6 X~ 0,2,4,6 + andthen .skip + andthen .say +} -- cgit From 1a8bb9ad40d6b178c661a40613383768123e3787 Mon Sep 17 00:00:00 2001 From: Roger Bell_West Date: Mon, 24 Jan 2022 09:35:24 +0000 Subject: Solutions for challenge #149 --- challenge-149/roger-bell-west/javascript/ch-1.js | 76 ++++++++++++++++++++++ challenge-149/roger-bell-west/javascript/ch-2.js | 60 ++++++++++++++++++ challenge-149/roger-bell-west/kotlin/ch-1.kt | 51 +++++++++++++++ challenge-149/roger-bell-west/kotlin/ch-2.kt | 61 ++++++++++++++++++ challenge-149/roger-bell-west/lua/ch-1.lua | 77 +++++++++++++++++++++++ challenge-149/roger-bell-west/lua/ch-2.lua | 61 ++++++++++++++++++ challenge-149/roger-bell-west/perl/ch-1.pl | 35 +++++++++++ challenge-149/roger-bell-west/perl/ch-2.pl | 42 +++++++++++++ challenge-149/roger-bell-west/postscript/ch-1.ps | 80 ++++++++++++++++++++++++ challenge-149/roger-bell-west/postscript/ch-2.ps | 63 +++++++++++++++++++ challenge-149/roger-bell-west/python/ch-1.py | 39 ++++++++++++ challenge-149/roger-bell-west/python/ch-2.py | 45 +++++++++++++ challenge-149/roger-bell-west/raku/ch-1.p6 | 33 ++++++++++ challenge-149/roger-bell-west/raku/ch-2.p6 | 41 ++++++++++++ challenge-149/roger-bell-west/ruby/ch-1.rb | 47 ++++++++++++++ challenge-149/roger-bell-west/ruby/ch-2.rb | 53 ++++++++++++++++ challenge-149/roger-bell-west/rust/ch-1.rs | 45 +++++++++++++ challenge-149/roger-bell-west/rust/ch-2.rs | 54 ++++++++++++++++ 18 files changed, 963 insertions(+) create mode 100755 challenge-149/roger-bell-west/javascript/ch-1.js create mode 100755 challenge-149/roger-bell-west/javascript/ch-2.js create mode 100644 challenge-149/roger-bell-west/kotlin/ch-1.kt create mode 100644 challenge-149/roger-bell-west/kotlin/ch-2.kt create mode 100755 challenge-149/roger-bell-west/lua/ch-1.lua create mode 100755 challenge-149/roger-bell-west/lua/ch-2.lua create mode 100755 challenge-149/roger-bell-west/perl/ch-1.pl create mode 100755 challenge-149/roger-bell-west/perl/ch-2.pl create mode 100644 challenge-149/roger-bell-west/postscript/ch-1.ps create mode 100644 challenge-149/roger-bell-west/postscript/ch-2.ps create mode 100755 challenge-149/roger-bell-west/python/ch-1.py create mode 100755 challenge-149/roger-bell-west/python/ch-2.py create mode 100755 challenge-149/roger-bell-west/raku/ch-1.p6 create mode 100755 challenge-149/roger-bell-west/raku/ch-2.p6 create mode 100755 challenge-149/roger-bell-west/ruby/ch-1.rb create mode 100755 challenge-149/roger-bell-west/ruby/ch-2.rb create mode 100755 challenge-149/roger-bell-west/rust/ch-1.rs create mode 100755 challenge-149/roger-bell-west/rust/ch-2.rs diff --git a/challenge-149/roger-bell-west/javascript/ch-1.js b/challenge-149/roger-bell-west/javascript/ch-1.js new file mode 100755 index 0000000000..74132cfa72 --- /dev/null +++ b/challenge-149/roger-bell-west/javascript/ch-1.js @@ -0,0 +1,76 @@ +#! /usr/bin/node + +// by Frank Tan +// https://stackoverflow.com/questions/38400594/javascript-deep-comparison +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 fds(n) { + let out=[]; + let f=[1,0]; + let ft=new Set(f); + let k=0; + while (out.length < n) { + let ds=0; + let j=k; + while (j > 0) { + ds += j % 10; + j=Math.floor(j/10); + } + while (f[0] < ds) { + let t=f[1]+f[0]; + f[1]=f[0]; + f[0]=t; + ft.add(f[0]); + } + if (ft.has(ds)) { + out.push(k); + } + k++; + } + return out; +} + +if (deepEqual(fds(8),[0, 1, 2, 3, 5, 8, 10, 11])) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); + +if (deepEqual(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44])) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); + +if (deepEqual(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206])) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); + diff --git a/challenge-149/roger-bell-west/javascript/ch-2.js b/challenge-149/roger-bell-west/javascript/ch-2.js new file mode 100755 index 0000000000..999fbcf321 --- /dev/null +++ b/challenge-149/roger-bell-west/javascript/ch-2.js @@ -0,0 +1,60 @@ +#! /usr/bin/node + +function ls(base) { + let max=0; + for(let i=base; i>0; i--) { + max *= base; + max += i; + } + let t=Math.floor(Math.sqrt(max)); + let digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + while (true) { + let s=t*t; + let v=true; + let c=Array.from(Array(base),_ => 0); + let dg=[]; + while (s > 0) { + let d=s % base; + c[d]++; + if (c[d] > 1) { + v=false; + break; + } + s=Math.floor(s/base); + dg.unshift(digits[d]); + } + if (v) { + return dg.join(""); + } + t--; + } +} + +if (ls(2) == "1") { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); + +if (ls(4) == "3201") { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); + +if (ls(10) == "9814072356") { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); + +if (ls(12) == "B8750A649321") { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); + diff --git a/challenge-149/roger-bell-west/kotlin/ch-1.kt b/challenge-149/roger-bell-west/kotlin/ch-1.kt new file mode 100644 index 0000000000..526f498dab --- /dev/null +++ b/challenge-149/roger-bell-west/kotlin/ch-1.kt @@ -0,0 +1,51 @@ +fun fds(n: Int): ArrayList { + var o=ArrayList() + var f=arrayOf(1,0) + var ft=mutableSetOf() + for (i in f) { + ft.add(i) + } + var k=0 + while (o.size < n) { + var j: Int=k + var ds=0 + while (j > 0) { + ds += j % 10 + j = j/10 + } + while (f[0] < ds) { + val t=f[1]+f[0] + f[1]=f[0] + f[0]=t + ft.add(f[0]) + } + if (ft.contains(ds)) { + o.add(k) + } + k += 1 + } + return o +} + +fun main() { + if (fds(8) == listOf(0, 1, 2, 3, 5, 8, 10, 11)) { + print("Pass") + } else { + print("FAIL") + } + print(" ") + + if (fds(20) == listOf(0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44)) { + print("Pass") + } else { + print("FAIL") + } + print(" ") + + if (fds(61) == listOf(0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206)) { + print("Pass") + } else { + print("FAIL") + } + println("") +} diff --git a/challenge-149/roger-bell-west/kotlin/ch-2.kt b/challenge-149/roger-bell-west/kotlin/ch-2.kt new file mode 100644 index 0000000000..d9c68489af --- /dev/null +++ b/challenge-149/roger-bell-west/kotlin/ch-2.kt @@ -0,0 +1,61 @@ +import kotlin.math.* + +fun ls(base: Int): String { + var max: Long=0 + for (i in base-1 downTo 0) { + max *= base + max += i + } + var t=sqrt(max.toDouble()).toLong() + val digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + while (true) { + var s=t*t + var v=true + var c=IntArray(base) {_ -> 0} + var dg: String="" + while (s > 0) { + val d=(s % base).toInt() + c[d] += 1 + if (c[d] > 1) { + v=false + break + } + s /= base + dg = digits[d] + dg + } + if (v) { + return dg + } + t -= 1 + } +} + +fun main() { + if (ls(2) == "1") { + print("Pass") + } else { + print("FAIL") + } + print(" ") + + if (ls(4) == "3201") { + print("Pass") + } else { + print("FAIL") + } + print(" ") + + if (ls(10) == "9814072356") { + print("Pass") + } else { + print("FAIL") + } + print(" ") + + if (ls(12) == "B8750A649321") { + print("Pass") + } else { + print("FAIL") + } + println("") +} diff --git a/challenge-149/roger-bell-west/lua/ch-1.lua b/challenge-149/roger-bell-west/lua/ch-1.lua new file mode 100755 index 0000000000..a655491e2a --- /dev/null +++ b/challenge-149/roger-bell-west/lua/ch-1.lua @@ -0,0 +1,77 @@ +#! /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 fds(n) + out={} + f={1,0} + ft={} + for i,v in ipairs(f) do + ft[v]=true + end + k=0 + while #out < n do + j=k + ds=0 + while j > 0 do + ds = ds + j % 10 + j=math.floor(j/10) + end + while f[1] < ds do + f[1],f[2]=f[1]+f[2],f[1] + ft[f[1]]=true + end + if ft[ds] ~= nil then + table.insert(out,k) + end + k = k + 1 + end + return out +end + +if recursive_compare(fds(8),{0, 1, 2, 3, 5, 8, 10, 11}) then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if recursive_compare(fds(20),{0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44}) then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if recursive_compare(fds(61),{0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206}) then + io.write("Pass") +else + io.write("FAIL") +end +print("") diff --git a/challenge-149/roger-bell-west/lua/ch-2.lua b/challenge-149/roger-bell-west/lua/ch-2.lua new file mode 100755 index 0000000000..b640896c01 --- /dev/null +++ b/challenge-149/roger-bell-west/lua/ch-2.lua @@ -0,0 +1,61 @@ +#! /usr/bin/lua + +function ls(base) + max=0 + for i = base-1, 0, -1 do + max = max * base + i + end + t=math.floor(math.sqrt(max)) + digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + while true do + s=t*t + v=true + c={} + for i = 0,base-1 do + table.insert(c,0) + end + dg="" + while s > 0 do + d = s % base + 1 + c[d] = c[d] + 1 + if c[d] > 1 then + v=false + break + end + s=math.floor(s/base) + dg = string.sub(digits,d,d) .. dg + end + if v then + return dg + end + t = t - 1 + end +end + +if ls(2) == "1" then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if ls(4) == "3201" then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if ls(10) == "9814072356" then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if ls(12) == "B8750A649321" then + io.write("Pass") +else + io.write("FAIL") +end +print("") diff --git a/challenge-149/roger-bell-west/perl/ch-1.pl b/challenge-149/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..c603706822 --- /dev/null +++ b/challenge-149/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,35 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 3; + +is_deeply(fds(8),[0, 1, 2, 3, 5, 8, 10, 11],'example 1'); +is_deeply(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],'example 2'); +is_deeply(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],'example 3'); + +sub fds { + my $n=shift; + my @o; + my @f=(1,0); + my %ft=map {$_ => 1} @f; + my $k=0; + while (scalar @o < $n) { + my $ds=0; + my $j=$k; + while ($j > 0) { + $ds += ($j % 10); + $j=int($j/10); + } + while ($f[0] < $ds) { + @f=($f[1]+$f[0],$f[0]); + $ft{$f[0]}=1; + } + if (exists $ft{$ds}) { + push @o,$k; + } + $k++; + } + return \@o; +} diff --git a/challenge-149/roger-bell-west/perl/ch-2.pl b/challenge-149/roger-bell-west/perl/ch-2.pl new file mode 100755 index 0000000000..2145d32724 --- /dev/null +++ b/challenge-149/roger-bell-west/perl/ch-2.pl @@ -0,0 +1,42 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 4; + +is(ls(2),'1','example 1'); +is(ls(4),'3201','example 2'); +is(ls(10),'9814072356','example 3'); +is(ls(12),'B8750A649321','example 4'); + +sub ls { + my $base=shift; + my $max=0; + for (my $i=$base-1;$i >= 0; $i--) { + $max *= $base; + $max += $i; + } + my $t=int(sqrt($max)); + my @digits=('0'..'9','A'..'Z'); + while (1) { + my $s=$t*$t; + my $v=1; + my @c=(0) x $base; + my @dg; + while ($s > 0) { + my $d=$s % $base; + $c[$d]++; + if ($c[$d] > 1) { + $v=0; + last; + } + $s = int($s/$base); + unshift @dg,$digits[$d]; + } + if ($v) { + return join('',@dg); + } + $t--; + } +} diff --git a/challenge-149/roger-bell-west/postscript/ch-1.ps b/challenge-149/roger-bell-west/postscript/ch-1.ps new file mode 100644 index 0000000000..d2aba414ba --- /dev/null +++ b/challenge-149/roger-bell-west/postscript/ch-1.ps @@ -0,0 +1,80 @@ +%!PS + +/aeq { + 2 dict begin + /a exch def + /b exch def + a length b length eq { + /e true def + 0 1 a length 1 sub { + dup a exch get + exch b exch get ne { + /e false def + exit + } if + } for + e + } { + false + } ifelse + end +} bind def + +/apush { % [a b] c -> [a b c] + /t exch def + [ exch aload pop t ] +} bind def + +/i2s { + dup 0 le { + (0) + } { + dup log cvi 1 add string cvs + } ifelse +} bind def + +/fds { + /n exch def + /ft n 4 mul dict def + /out 0 array def + /f [ 0 1 ] def + f { + ft exch true put + } forall + /k 0 def + { + /ds 0 def + /j k def + { + j 0 gt { + /ds ds j 10 mod add def + /j j 10 idiv def + } { + exit + } ifelse + } loop + { + f 0 get ds gt { + exit + } if + f 0 get f 1 get add + f 1 get f exch 0 exch put + f exch 1 exch put + ft f 0 get true put + } loop + ft ds known { + /out out k apush def + out length n ge { + exit + } if + } if + /k k 1 add def + } loop + out +} bind def + +8 fds [0 1 2 3 5 8 10 11 ] aeq { (Pass) } { (FAIL) } ifelse print ( ) print + +20 fds [ 0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44] aeq { (Pass) } { (FAIL) } ifelse print ( ) print + +61 fds [0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44 49 50 53 58 62 67 71 76 80 85 94 100 101 102 104 107 110 111 113 116 120 122 125 131 134 139 140 143 148 152 157 161 166 170 175 184 193 200 201 203 206 ] aeq { (Pass) } { (FAIL) } ifelse = diff --git a/challenge-149/roger-bell-west/postscript/ch-2.ps b/challenge-149/roger-bell-west/postscript/ch-2.ps new file mode 100644 index 0000000000..45d80749c5 --- /dev/null +++ b/challenge-149/roger-bell-west/postscript/ch-2.ps @@ -0,0 +1,63 @@ +%!PS + +/ls { + /base exch def + /max 0 def + base 1 sub -1 0 { + /max max base mul def + max add /max exch def + } for + /t max sqrt cvi def + /digits (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def + { + /s t t mul def + /v true def + /c base array def + 0 1 base 1 sub { + c exch 0 put + } for + /dg base string def + /i base def + { + s 0 le { + exit + } if + /d s base mod def + c d get 1 add c exch d exch put + c d get 1 gt { + /v false def + exit + } if + /s s base idiv def + /i i 1 sub def + dg i digits d get put + } loop + v { + exit + } if + /t t 1 sub def + } loop + /st 0 def + /i 1 def + dg { + 0 eq { + /st i def + } if + /i i 1 add def + } forall + st 0 gt { + dg st base st sub getinterval + } { + dg + } ifelse +} bind def + +2 ls (1) eq { (Pass) } { (FAIL) } ifelse +print ( ) print +4 ls (3201) eq { (Pass) } { (FAIL) } ifelse +print ( ) print +10 ls (9814072356) eq { (Pass) } { (FAIL) } ifelse +print ( ) print +12 ls (B8750A649321) eq { (Pass) } { (FAIL) } ifelse += + diff --git a/challenge-149/roger-bell-west/python/ch-1.py b/challenge-149/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..984166c999 --- /dev/null +++ b/challenge-149/roger-bell-west/python/ch-1.py @@ -0,0 +1,39 @@ +#! /usr/bin/python3 + +import unittest + +from math import floor + +def fds(n): + o=[] + f=[1,0] + ft=set(f) + k=0 + while len(o) < n: + ds=0 + j=k + while (j > 0): + ds += j % 10 + j //= 10 + while f[0] < ds: + t=f[1]+f[0] + f[1]=f[0] + f[0]=t + ft.add(f[0]) + if ds in ft: + o.append(k) + k += 1 + return o + +class TestFds(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(fds(8),[0, 1, 2, 3, 5, 8, 10, 11],'example 1') + + def test_ex2(self): + self.assertEqual(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],'example 2') + + def test_ex3(self): + self.assertEqual(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],'example 3') + +unittest.main() diff --git a/challenge-149/roger-bell-west/python/ch-2.py b/challenge-149/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..4306dd9c8e --- /dev/null +++ b/challenge-149/roger-bell-west/python/ch-2.py @@ -0,0 +1,45 @@ +#! /usr/bin/python3 + +import unittest + +from math import sqrt,floor + +def ls(base): + max=0 + for i in reversed(range(base+1)): + max *= base + max += i + digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + t=floor(sqrt(max)) + while True: + s=t*t + v=True + c=[0 for i in range(base)] + dg="" + while s > 0: + d=s % base + c[d] += 1 + if c[d] > 1: + v=False + break + s //= base + dg=digits[d] + dg + if v: + return dg + t -= 1 + +class TestLs(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(ls(2),"1",'example 1') + + def test_ex2(self): + self.assertEqual(ls(4),"3201",'example 2') + + def test_ex3(self): + self.assertEqual(ls(10),"9814072356",'example 3') + + def test_ex4(self): + self.assertEqual(ls(12),"B8750A649321",'example 4') + +unittest.main() diff --git a/challenge-149/roger-bell-west/raku/ch-1.p6 b/challenge-149/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..7edd2b4dd3 --- /dev/null +++ b/challenge-149/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,33 @@ +#! /usr/bin/perl6 + +use Test; + +plan 3; + +is-deeply(fds(8),[0, 1, 2, 3, 5, 8, 10, 11],'example 1'); +is-deeply(fds(20),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],'example 2'); +is-deeply(fds(61),[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],'example 3'); + +sub fds($n) { + my @o; + my @f=[1,0]; + my $ft=SetHash.new(@f); + my $k=0; + while (@o.elems < $n) { + my $ds=0; + my $j=$k; + while ($j > 0) { + $ds += ($j % 10); + $j div= 10; + } + while (@f[0] < $ds) { + @f=[@f[1]+@f[0],@f[0]]; + $ft{@f[0]}++; + } + if ($ft{$ds}:exists) { + push @o,$k; + } + $k++; + } + return @o; +} diff --git a/challenge-149/roger-bell-west/raku/ch-2.p6 b/challenge-149/roger-bell-west/raku/ch-2.p6 new file mode 100755 index 0000000000..4243aa7a44 --- /dev/null +++ b/challenge-149/roger-bell-west/raku/ch-2.p6 @@ -0,0 +1,41 @@ +#! /usr/bin/perl6 + +use Test; + +plan 4; + +is(ls(2),'1','example 1'); +is(ls(4),'3201','example 2'); +is(ls(10),'9814072356','example 3'); +is(ls(12),'B8750A649321','example 4'); + +sub ls($base) { + my $max=0; + loop (my $i=$base-1;$i >= 0; $i--) { + $max *= $base; + $max += $i; + } + my $t=floor(sqrt($max)); + my @digits=['0'..'9']; + @digits.append('A'..'Z'); + while (1) { + my $s=$t*$t; + my $v=True; + my @c=0 xx $base; + my @dg; + while ($s > 0) { + my $d=$s % $base; + @c[$d]++; + if (@c[$d] > 1) { + $v=False; + last; + } + $s = floor($s/$base); + unshift @dg,@digits[$d]; + } + if ($v) { + return join('',@dg); + } + $t--; + } +} diff --git a/challenge-149/roger-bell-west/ruby/ch-1.rb b/challenge-149/roger-bell-west/ruby/ch-1.rb new file mode 100755 index 0000000000..ff1f80c702 --- /dev/null +++ b/challenge-149/roger-bell-west/ruby/ch-1.rb @@ -0,0 +1,47 @@ +#! /usr/bin/ruby + +require 'test/unit' + +require 'set' + +def fds(n) + o=[] + f=[1,0] + ft=Set.new(f) + k=0 + while o.length < n do + ds=0 + j=k + while j > 0 do + ds += j % 10 + j = (j/10).to_i + end + while f[0] < ds do + t=f[1]+f[0] + f[1]=f[0] + f[0]=t + ft.add(f[0]) + end + if ft.include?(ds) then + o.push(k) + end + k += 1 + end + return o +end + +class TestFds < Test::Unit::TestCase + + def test_ex1 + assert_equal([0, 1, 2, 3, 5, 8, 10, 11],fds(8)) + end + + def test_ex2 + assert_equal([0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44],fds(20)) + end + + def test_ex3 + assert_equal([0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206],fds(61)) + end + +end diff --git a/challenge-149/roger-bell-west/ruby/ch-2.rb b/challenge-149/roger-bell-west/ruby/ch-2.rb new file mode 100755 index 0000000000..d50cfb33d4 --- /dev/null +++ b/challenge-149/roger-bell-west/ruby/ch-2.rb @@ -0,0 +1,53 @@ +#! /usr/bin/ruby + +require 'test/unit' + +def ls(base) + max=0 + base.downto(0) do |i| + max *= base + max += i + end + digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + t=Integer.sqrt(max) + while true do + s=t*t + v=true + c=Array.new(base) { 0 } + dg="" + while s > 0 do + d = s % base + c[d] += 1 + if c[d] > 1 then + v=false + break + end + s = (s/base).to_i + dg = digits[d] + dg + end + if v then + return dg + end + t -= 1 + end +end + +class TestLs < Test::Unit::TestCase + + def test_ex1 + assert_equal("1",ls(2)) + end + + def test_ex2 + assert_equal("3201",ls(4)) + end + + def test_ex3 + assert_equal("9814072356",ls(10)) + end + + def test_ex4 + assert_equal("B8750A649321",ls(12)) + end + +end diff --git a/challenge-149/roger-bell-west/rust/ch-1.rs b/challenge-149/roger-bell-west/rust/ch-1.rs new file mode 100755 index 0000000000..d026679394 --- /dev/null +++ b/challenge-149/roger-bell-west/rust/ch-1.rs @@ -0,0 +1,45 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit + +use std::collections::HashSet; + +#[test] +fn test_ex1() { + assert_eq!(fds(8),vec![0, 1, 2, 3, 5, 8, 10, 11]); +} + +#[test] +fn test_ex2() { + assert_eq!(fds(20),vec![0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44]); +} + +#[test] +fn test_ex3() { + assert_eq!(fds(61),vec![0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85, 94, 100, 101, 102, 104, 107, 110, 111, 113, 116, 120, 122, 125, 131, 134, 139, 140, 143, 148, 152, 157, 161, 166, 170, 175, 184, 193, 200, 201, 203, 206]); +} + +fn fds(n: u32) -> Vec { + let mut o=Vec::new(); + let mut f=[1,0]; + let mut ft: HashSet=HashSet::from(f); + let mut k=0; + while o.len() < n as usize { + let mut ds=0; + let mut j=k; + while j > 0 { + ds += j % 10; + j /= 10; + } + while f[0] < ds { + let t=f[1]+f[0]; + f[1]=f[0]; + f[0]=t; + ft.insert(f[0]); + } + if ft.contains(&ds) { + o.push(k); + } + k += 1; + } + o +} diff --git a/challenge-149/roger-bell-west/rust/ch-2.rs b/challenge-149/roger-bell-west/rust/ch-2.rs new file mode 100755 index 0000000000..61d970c1ab --- /dev/null +++ b/challenge-149/roger-bell-west/rust/ch-2.rs @@ -0,0 +1,54 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit + +use std::convert::TryInto; + +#[test] +fn test_ex1() { + assert_eq!(ls(2),"1"); +} + +#[test] +fn test_ex2() { + assert_eq!(ls(4),"3201"); +} + +#[test] +fn test_ex3() { + assert_eq!(ls(10),"9814072356"); +} + +#[test] +fn test_ex4() { + assert_eq!(ls(12),"B8750A649321"); +} + +fn ls(base: u64) -> String { + let mut max=0u64; + for i in (0..base).rev() { + max *= base; + max += i; + } + let mut t=(max as f64).sqrt() as u64; + loop { + let mut s=t*t; + let mut v=true; + let mut c=vec![0u64;base.try_into().unwrap()]; + let mut dg: Vec=Vec::new(); + while s > 0 { + let d = (s % base) as usize; + c[d] += 1; + if c[d] > 1 { + v=false; + break; + } + s /= base; + dg.push(std::char::from_digit(d.try_into().unwrap(), + base.try_into().unwrap()).unwrap()); + } + if v { + return dg.iter().rev().collect::().to_uppercase(); + } + t -= 1; + } +} -- cgit From 004ffc8ebf81ea5b8525e88c1e0a81a007537579 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 24 Jan 2022 09:39:43 +0000 Subject: first pass --- challenge-149/james-smith/README.md | 101 +++------------------------------ challenge-149/james-smith/perl/ch-1.pl | 30 ++++++++++ challenge-149/james-smith/perl/ch-2.pl | 47 +++++++++++++++ 3 files changed, 85 insertions(+), 93 deletions(-) create mode 100644 challenge-149/james-smith/perl/ch-1.pl create mode 100644 challenge-149/james-smith/perl/ch-2.pl diff --git a/challenge-149/james-smith/README.md b/challenge-149/james-smith/README.md index 93fc54aedf..a755db373e 100644 --- a/challenge-149/james-smith/README.md +++ b/challenge-149/james-smith/README.md @@ -1,6 +1,6 @@ -[< Previous 147](https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-145/james-smith) | -[Next 149 >](https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-149/james-smith) -# Perl Weekly Challenge #148 +[< Previous 148](https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-148/james-smith) | +[Next 150 >](https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-150/james-smith) +# Perl Weekly Challenge #149 You can find more information about this weeks, and previous weeks challenges at: @@ -12,103 +12,18 @@ submit solutions in whichever language you feel comfortable with. You can find the solutions here on github at: -https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-148/james-smith +https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-149/james-smith -# Challenge 1 - Eban Numbers +# Challenge 1 - Fibonacci Digit Sum -***Write a script to generate all Eban Numbers <= 100. An Eban number is a number that has no letter โ€˜eโ€™ in it when the number is spelled in English (American or British).*** +***Given an input $N, generate the first $N numbers for which the sum of their digits is a Fibonacci number.*** ## The solution -I will present two different solutions for the more general problem of large Eban numbers, but for numbers less than 1,000 we have: +# Challenge 2 - Largest Square -* The units must be 0, 2, 4, 6 -* The tens must be 0, 30, 40,50, 60, - -So to compute the eban numbers less than 100 (and consequently all eban numbers less than one thousand) we can use: - -```perl -say for map{my$a=$_;map{10*$a+2*$_||()}(0..3)}(0,3..6); -``` - -The `||()` removes the zero value which is not an eban number. - -This gives us the following numbers less than 1,000: - -`2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66` - -Now we can use this sequence to generate all eban numbers. - -For eban numbers of order *1000^n* we just need to multiply all the eban numbers of order "*1000^(n-1)*" these by 1000 and add each one add each of the eban numbers less than 100 (this time including 0). This assumes that for values of 1000, 1000000 etc we say *one thousand*, *one million*, ... - -```perl -say for my@e=grep{$_}my@n=map{my$a=$_;map{10*$a+2*$_}(0..3)}(0,3..6); -for(2..$N){ - say for@e=map{my$a=$_;map{$a*1e3+$_}@n}@e; -} -``` - -The second removes the need to use `sprintf` everytime in the subsequent loops, by generating the list of numbers padded with 0s - we can see this with the performance gain in all but the first case (the first loop is made slightly more complex). - -### Notes: Timings - -| Max | (in words) | Rate | Count | -| ----: | :---------: | --------------: | ---------: | -| 10^3 | Thousand | 200,481.00 /s | 19 | -| 10^6 | Million | 18,214.94 /s | 399 | -| 10^9 | Billion | 971.82 /s | 7,999 | -| 10^12 | Trillion | 49.41 /s | 159,999 | -| 10^15 | Quadrillion | 2.27 /s | 3,199,999 | -| 10^18 | Quintillion | 0.10 /s | 63,999,999 | - -Unable to proceed with values of n greater than 6, as we are hitting memory limits, and the size of integer perl can store by default (64-bit). - - * Would need to look at using `bigint` for working with arbitrary sized integers or reverting to a string based solution (although this uses a even more memory) - -# Challenge 2 - Cardano Triplets -***Write a script to generate first 5 Cardano Triplets. A triplet of positive integers (a,b,c) is called a Cardano Triplet if it satisfies the below condition.*** - -*(a+b.sqrt(c))^(1/3) + (a-b.sqrt(c))^(1/3) = 1* +***Given a number base, derive the largest perfect square with no repeated digits and return it as a string. (For base>10, use โ€˜Aโ€™..โ€˜Zโ€™.)*** ## The solution -There is a very naive solution which tries all combinations of *a*,*b*,*c*. But there is a more performant solution. - -You can rewrite the equation in the form: - -*8.a^3 + 15.a^2 + 6.a - 27.b^2.c = 1* - -Which can be further parametrized as: - -*b^2.c = k^2 . (8.k-3)* - -Where *a=3.k-1*. and *k* starts at 1. - -So the first entry *k=1*, *b^2.c=5* - so is solved by *a=2*, *b=1*, *c=5*. - -So the code to find all cardano triplets with *a<10,000* is: - -```perl -for my $k (1..3333) { - for( my ($b, $n) = (1, $k*$k*(8*$k-3) ); $n > $b*$b; $b++ ) { - say join "\t", 3*$k-1, $b, $n/$b/$b unless $n%($b*$b); - } -} -``` - -We loop through each value of `$k` up to 3,333, this gives the maximum value of `$a` 9,998. Largest less than or equal to 10,000. -We then loop `$b` from 1 up to the value where `$c < 1`. Rather than computing `$c` at this stage (there could be rounding errors). -We just compare the numerator (*k^2 . (8.k-3)*) with the denominator (*b^2*). We then check to see `$c` is an integer - we again -do this without computing `$c` to avoid rounding errors - to compute the results and display them. - -Time taken to calculate these **32,235** cardano triplets is **78.5sec**. - -If we go back to the original problem and look at the first 5 cardano triplets we have either: - -The first 5 (if you sort by *a* and *b*) are: - - (2,1,5), (5,1,52), (5,2,13), (8,1,189), (8,3,21). - -The first 5 (if you sort by total *a+b+c*) are: - (2,1,5), (5,2,13), (8,3,21), (17,18,5), (11,4,29). diff --git a/challenge-149/james-smith/perl/ch-1.pl b/challenge-149/james-smith/perl/ch-1.pl new file mode 100644 index 0000000000..16f8bbb711 --- /dev/null +++ b/challenge-149/james-smith/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/local/bin/perl + +use strict; + +use warnings; +use feature qw(say); +use Test::More; +use Benchmark qw(cmpthese timethis); +use Data::Dumper qw(Dumper); + +my $n = @ARGV ? $ARGV[0] : 20; + +my @fib = (0,1,1); +my %fib = (0,1,1,1); + +for(my $i=0; $n; $i++ ) { + my $ds = 0; + $ds+=$_ foreach split //,$i; + if($ds>$fib[-1]) { + ## If we dont have a large enough fib add the next one... + ## Digit sum can only be 1 larger than current maximum + ## fibonacci. + push @fib, $fib[-2]+$fib[-1]; + $fib{$fib[-1]}=1; + } + next unless exists $fib{$ds}; + say $i; + $n--; +} + diff --git a/challenge-149/james-smith/perl/ch-2.pl b/challenge-149/james-smith/perl/ch-2.pl new file mode 100644 index 0000000000..06fb45a17d --- /dev/null +++ b/challenge-149/james-smith/perl/ch-2.pl @@ -0,0 +1,47 @@ +#!/usr/local/bin/perl + +use strict; + +use warnings; +use feature qw(say); +use Test::More; +use Time::HiRes qw(time); + +my @MAP = ( 0..9,'A'..'Z' ); + +for my $N (2..15) { + my $time = time; + my $v = biggest_perfect_square($N); + say sprintf '%2d v = %10d v^2 = %20d = %16s; TIME = %10.6f', + $N, $v, $v*$v, baseN($v*$v,$N), time-$time; +} + +## We brute force this - we start at the largest possible square. +## and work backwards - our guess at the largest is the square +## root of the largest possible value with $N digits or roughty +## $N**($N/2); + +## Rather than generating a representation of the number we +## just look for repeated digits - if we find one we test the +## next number - note here we use the "next LABEL" to break +## out of both the while and the for loop + +sub biggest_perfect_square { + my $n = shift; + O: for( my $t = int($n**($n/2)); $t; $t -- ) { + my ($q,%seen) = $t**2; + $seen{$q%$n}++?(next O):($q=int($q/$n)) while $q; + return $t; + } +} + +## As we didn't generate earlier - to prove we have a +## candidate we convert the number into base $N... +## We use the same while loop as above to return the +## string. + +sub baseN { + my($o,$v,$n) = ('',@_); + ($o,$v) = ( $MAP[$v%$n].$o, int ($v/$n) ) while $v; + $o; +} -- cgit From 340f3db93536904aff14b86a90ffec06b256210d Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 24 Jan 2022 10:45:42 +0100 Subject: Task 1 done --- challenge-149/luca-ferrari/raku/ch-1.p6 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 challenge-149/luca-ferrari/raku/ch-1.p6 diff --git a/challenge-149/luca-ferrari/raku/ch-1.p6 b/challenge-149/luca-ferrari/raku/ch-1.p6 new file mode 100755 index 0000000000..2282387013 --- /dev/null +++ b/challenge-149/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,13 @@ +#!raku + +sub MAIN( Int $N where { $N > 0 } ) { + my @fibonacci = 1, 1, * + * ... *; + my $fibonacci-index = $N; + my @numbers = lazy gather { + for 0 .. Inf -> $i { + take $i and $fibonacci-index += $N if @fibonacci[ 0 .. $fibonacci-index ].grep( $i.split( '' ).sum );; + } + }; + + @numbers[ 0 .. $N - 1 ].join( ',' ).say; +} -- cgit From 6699a62199e5dc264944ee891832f705048b9036 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 24 Jan 2022 15:33:22 +0100 Subject: Week 149, part 1: Tests --- challenge-149/abigail/t/ctest.ini | 8 ++++++++ challenge-149/abigail/t/input-1-1 | 1 + challenge-149/abigail/t/input-1-2 | 3 +++ challenge-149/abigail/t/output-1-1.exp | 1 + challenge-149/abigail/t/output-1-2.exp | 3 +++ 5 files changed, 16 insertions(+) create mode 100644 challenge-149/abigail/t/ctest.ini create mode 100644 challenge-149/abigail/t/input-1-1 create mode 100644 challenge-149/abigail/t/input-1-2 create mode 100644 challenge-149/abigail/t/output-1-1.exp create mode 100644 challenge-149/abigail/t/output-1-2.exp diff --git a/challenge-149/abigail/t/ctest.ini b/challenge-149/abigail/t/ctest.ini new file mode 100644 index 0000000000..5513a21cc4 --- /dev/null +++ b/challenge-149/abigail/t/ctest.ini @@ -0,0 +1,8 @@ +# +# Configuration file for running tests, using ctest. +# See https://github.com/Abigail/Misc/blob/master/ctest +# + +[names] +1-1 = Given Example +1-2 = More Examples diff --git a/challenge-149/abigail/t/input-1-1 b/challenge-149/abigail/t/input-1-1 new file mode 100644 index 0000000000..209e3ef4b6 --- /dev/null +++ b/challenge-149/abigail/t/input-1-1 @@ -0,0 +1 @@ +20 diff --git a/challenge-149/abigail/t/input-1-2 b/challenge-149/abigail/t/input-1-2 new file mode 100644 index 0000000000..ec34aebfec --- /dev/null +++ b/challenge-149/abigail/t/input-1-2 @@ -0,0 +1,3 @@ +50 +100 +150 diff --git a/challenge-149/abigail/t/output-1-1.exp b/challenge-149/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..57b5a1d81c --- /dev/null +++ b/challenge-149/abigail/t/output-1-1.exp @@ -0,0 +1 @@ +0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44 diff --git a/challenge-149/abigail/t/output-1-2.exp b/challenge-149/abigail/t/output-1-2.exp new file mode 100644 index 0000000000..5a1b85732e --- /dev/null +++ b/challenge-149/abigail/t/output-1-2.exp @@ -0,0 +1,3 @@ +0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44 49 50 53 58 62 67 71 76 80 85 94 100 101 102 104 107 110 111 113 116 120 122 125 131 134 139 140 143 148 152 +0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44 49 50 53 58 62 67 71 76 80 85 94 100 101 102 104 107 110 111 113 116 120 122 125 131 134 139 140 143 148 152 157 161 166 170 175 184 193 200 201 203 206 210 212 215 221 224 229 230 233 238 242 247 251 256 260 265 274 283 292 300 302 305 311 314 319 320 323 328 332 337 341 346 350 355 364 373 382 391 399 401 +0 1 2 3 5 8 10 11 12 14 17 20 21 23 26 30 32 35 41 44 49 50 53 58 62 67 71 76 80 85 94 100 101 102 104 107 110 111 113 116 120 122 125 131 134 139 140 143 148 152 157 161 166 170 175 184 193 200 201 203 206 210 212 215 221 224 229 230 233 238 242 247 251 256 260 265 274 283 292 300 302 305 311 314 319 320 323 328 332 337 341 346 350 355 364 373 382 391 399 401 404 409 410 413 418 422 427 431 436 440 445 454 463 472 481 489 490 498 500 503 508 512 517 521 526 530 535 544 553 562 571 579 580 588 597 602 607 611 616 620 625 634 643 652 661 669 670 678 687 696 -- cgit From 711d5679ff878c272bfd421116253630db330fc7 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 24 Jan 2022 15:33:40 +0100 Subject: Week 149, part 1: Perl solution --- challenge-149/abigail/perl/ch-1.pl | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 challenge-149/abigail/perl/ch-1.pl diff --git a/challenge-149/abigail/perl/ch-1.pl b/challenge-149/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..d1a1f7edb5 --- /dev/null +++ b/challenge-149/abigail/perl/ch-1.pl @@ -0,0 +1,60 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-149 +# + +# +# Run as: perl ch-1.pl < input-file +# + +# +# This is sequence A028840 of the OEIS. The first 10,000 entries can +# be found at https://oeis.org/A028840/b028840.txt +# +# We will make use of the following conjecture: the Nth number is <= 10 * N. +# This holds for the first 10,000 numbers. +# +# Consider that we are asked to generate all the first N numbers (and not +# the Nth number), I doubt we'll be feeding numbers exceeding 10,000 to +# this program. +# +# For the sum of digits, we hark back to challenge 133, part 2. +# + +use List::Util qw [sum]; +sub digitsum ($n) {sum $n =~ /\d/ag} + +while (<>) { + my $N = 0 + $_; + # + # Get an upper bound on the sum of the digits. + # + my $max_fib = 9 * (1 + length $N); + # + # Generate all the Fibonacci numbers up to $max_fib. + # + my %fib = (0 => 1, 1 => 1); + my ($f, $g) = (0, 1); + while ($g < $max_fib) { + ($f, $g) = ($g, $f + $g); + $fib {$g} = 1; + } + + for (my ($c, $k) = (0, 0); $c < $N; $k ++) { + if ($fib {digitsum $k}) { + print "$k "; + $c ++; + } + } + print "\n"; +} -- cgit From d2307ccb4e26f83c41e1d5c1517ae6297ba588a2 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 24 Jan 2022 15:45:55 +0100 Subject: Week 148, part 1: AWK solution --- challenge-149/abigail/awk/ch-1.awk | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 challenge-149/abigail/awk/ch-1.awk diff --git a/challenge-149/abigail/awk/ch-1.awk b/challenge-149/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..392a9bd88a --- /dev/null +++ b/challenge-149/abigail/awk/ch-1.awk @@ -0,0 +1,41 @@ +#!/usr/bin/awk + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-149 +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +function digit_sum (number, sum) { + sum = 0 + while (number > 0) { + sum += number % 10 + number = int (number / 10) + } + return sum +} + +{ + max_fib = 9 * (1 + length ($1)) + f = 0 + g = 1 + fib [f] = 1 + fib [g] = 1 + while (g < max_fib) { + t = f + g + fib [t] = 1 + f = g + g = t + } + + for (c = k = 0; c < $1; k ++) { + if (digit_sum(k) in fib) { + printf ("%d ", k) + c ++ + } + } + + printf ("\n") +} -- cgit From 779989d8a5014e672ed8f74c1e7e4d2fb059c133 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 24 Jan 2022 15:27:43 +0000 Subject: Update README.md --- challenge-149/james-smith/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/challenge-149/james-smith/README.md b/challenge-149/james-smith/README.md index a755db373e..9ebbcb0a39 100644 --- a/challenge-149/james-smith/README.md +++ b/challenge-149/james-smith/README.md @@ -20,6 +20,27 @@ https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-149/ja ## The solution +```perl +for( my($n,$ds,$i,$fa,$fb,%fib)=(@ARGV?$ARGV[0]:20,0,0,1,1,0,1,1,1); + $n; $i++,$ds=0 ) { ## 1 + $ds+=$_ foreach split //,$i; ## 2 + ($fib{$fa+$fb},$fa,$fb)=(1,$fb,$fa+$fb) if $ds > $fb; ## 3 + (say $i)**$n-- if exists $fib{$ds}; ## 4 +} +``` + +**Notes:** + + * Line 1 - We initialise everything inside the for loop + * `$n` is the number to print (and is based on what is passed at the command line) + * `$ds` is the digit sum (Note we reset it everytime through the loop in the incremement part of the loop + * `$i` current value being considered + * `$fa` & `$fb` - the highest two fibonacci numbers + * `%fib` hash whose keys are fibonacci numbers + * Line 2 - Computes the digit sum by splitting number on `//` I split into 1 character blocks + * Line 3 - Expand the fibonacci hash by 1 if the digit sum is greater than the highest fibonnaci number {we don't need to loop this as the digit sum of `$n+1` can only be at most 1 higher than that for `$n`. Note we just update $fb and $fa in this line + * Line 4 - Check to see if the digit sum exists, print and decrement counter - and return to the start of the loop. + # Challenge 2 - Largest Square ***Given a number base, derive the largest perfect square with no repeated digits and return it as a string. (For base>10, use โ€˜Aโ€™..โ€˜Zโ€™.)*** -- cgit From d14e65562eb2ae5f5d0a1d26b3643d285ffbd93a Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 24 Jan 2022 15:28:02 +0000 Subject: updated code --- challenge-149/james-smith/perl/ch-1.pl | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/challenge-149/james-smith/perl/ch-1.pl b/challenge-149/james-smith/perl/ch-1.pl index 16f8bbb711..7cd08cdc48 100644 --- a/challenge-149/james-smith/perl/ch-1.pl +++ b/challenge-149/james-smith/perl/ch-1.pl @@ -8,23 +8,17 @@ use Test::More; use Benchmark qw(cmpthese timethis); use Data::Dumper qw(Dumper); -my $n = @ARGV ? $ARGV[0] : 20; - -my @fib = (0,1,1); -my %fib = (0,1,1,1); - -for(my $i=0; $n; $i++ ) { - my $ds = 0; +# As an array we don't need to keep the fibonacci numbers +# We need them as the keys to the hash %fib which we use +# to check that a digit sum is a fibonacci number. Instead +# We only keep the last two values $fa & $fb +for( my($n,$ds,$i,$fa,$fb,%fib)=(@ARGV?$ARGV[0]:20,0,0,1,1,0,1,1,1); + $n; $i++,$ds=0 ) { $ds+=$_ foreach split //,$i; - if($ds>$fib[-1]) { - ## If we dont have a large enough fib add the next one... - ## Digit sum can only be 1 larger than current maximum - ## fibonacci. - push @fib, $fib[-2]+$fib[-1]; - $fib{$fib[-1]}=1; - } - next unless exists $fib{$ds}; - say $i; - $n--; + ## If we dont have a large enough fib add the next one... + ## Digit sum can only be 1 larger than current maximum + ## fibonacci. + ($fib{$fa+$fb},$fa,$fb)=(1,$fb,$fa+$fb) if $ds > $fb; + (say $i)**$n-- if exists $fib{$ds}; } -- cgit From 0ac867d28196c81d1158cb32bbe452f85f958ad6 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 24 Jan 2022 16:06:50 +0000 Subject: Update README.md --- challenge-149/james-smith/README.md | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/challenge-149/james-smith/README.md b/challenge-149/james-smith/README.md index 9ebbcb0a39..5d82a88441 100644 --- a/challenge-149/james-smith/README.md +++ b/challenge-149/james-smith/README.md @@ -47,4 +47,45 @@ for( my($n,$ds,$i,$fa,$fb,%fib)=(@ARGV?$ARGV[0]:20,0,0,1,1,0,1,1,1); ## The solution +```perl +sub biggest_perfect_square { + my $nt = my $m = (my $n = shift) -1; ## 1 + $m=$m*$n+$nt while $nt--; ## 2 + O: for( my $t = int sqrt $m; ; $t -- ) { ## 3 + my ($q,%seen) = $t**2; ## 4 + $seen{$q%$n}++?(next O):($q=int($q/$n)) while $q; ## 5 + return $t; ## 6 + } +} +``` + +**Notes:** + * Line 1 - initialise `$n` the base we are looking at, and variables to compute the maximum possible square + * Line 2 - Compute the maximum possible pandigital value for the given base - it is the digits in descending order *e.g.* `BA9876543210` for `$n=12` + * Line 3 - Here we just loop from the maximum possible square (sqrt of max pandigital number rounded down). Loop will finish for all +be bases as `1` is a solution in all cases. + * Line 4/5 - We loop through all digits to see if we have already seen the digit if so we skip to the next value of `$t` by using `next` with a label to not just out of this loop but to go to the next element of the outer loop. + * If we get through the while loop we have a value - and it must be the highest. + +## Results + +The values for each value of $N are given below up to (base 15) - the largest value for which we can compute in perl's 64-bit architecture. + +| N | v | v^2 | v^2 (base N) | Time | +| -: | --------: | -----------------: | --------------: | --------: | +| 2 | 1 | 1 | 1 | 0.000028 | +| 3 | 1 | 1 | 1 | 0.000024 | +| 4 | 15 | 225 | 3201 | 0.000022 | +| 5 | 24 | 576 | 4301 | 0.000053 | +| 6 | 195 | 38025 | 452013 | 0.000030 | +| 7 | 867 | 751689 | 6250341 | 0.000043 | +| 8 | 3213 | 10323369 | 47302651 | 0.001041 | +| 9 | 18858 | 355624164 | 823146570 | 0.000961 | +| 10 | 99066 | 9814072356 | 9814072356 | 0.000468 | +| 11 | 528905 | 279740499025 | A8701245369 | 0.003916 | +| 12 | 2950717 | 8706730814089 | B8750A649321 | 0.035817 | +| 13 | 4809627 | 23132511879129 | CBA504216873 | 18.810472 | +| 14 | 105011842 | 11027486960232964 | DC71B30685A924 | 0.140345 | +| 15 | 659854601 | 435408094460869201 | EDAC93B24658701 | 0.310490 | + +You will note that most time is taken where `$n` is 13. You will note that for `$n` in `3`, `5`, `13` there are no pan-digital solutions so we have to loop through all the 13 digit numbers and reach the 12 digit numbers before we find a solution. -- cgit From b82c07acecd65f6cfa3921e885c1ddf99f5570ad Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 24 Jan 2022 16:16:30 +0000 Subject: Update README.md --- challenge-149/james-smith/README.md | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/challenge-149/james-smith/README.md b/challenge-149/james-smith/README.md index 5d82a88441..935315da63 100644 --- a/challenge-149/james-smith/README.md +++ b/challenge-149/james-smith/README.md @@ -71,21 +71,23 @@ sub biggest_perfect_square { The values for each value of $N are given below up to (base 15) - the largest value for which we can compute in perl's 64-bit architecture. -| N | v | v^2 | v^2 (base N) | Time | -| -: | --------: | -----------------: | --------------: | --------: | -| 2 | 1 | 1 | 1 | 0.000028 | -| 3 | 1 | 1 | 1 | 0.000024 | -| 4 | 15 | 225 | 3201 | 0.000022 | -| 5 | 24 | 576 | 4301 | 0.000053 | -| 6 | 195 | 38025 | 452013 | 0.000030 | -| 7 | 867 | 751689 | 6250341 | 0.000043 | -| 8 | 3213 | 10323369 | 47302651 | 0.001041 | -| 9 | 18858 | 355624164 | 823146570 | 0.000961 | -| 10 | 99066 | 9814072356 | 9814072356 | 0.000468 | -| 11 | 528905 | 279740499025 | A8701245369 | 0.003916 | -| 12 | 2950717 | 8706730814089 | B8750A649321 | 0.035817 | -| 13 | 4809627 | 23132511879129 | CBA504216873 | 18.810472 | -| 14 | 105011842 | 11027486960232964 | DC71B30685A924 | 0.140345 | -| 15 | 659854601 | 435408094460869201 | EDAC93B24658701 | 0.310490 | - -You will note that most time is taken where `$n` is 13. You will note that for `$n` in `3`, `5`, `13` there are no pan-digital solutions so we have to loop through all the 13 digit numbers and reach the 12 digit numbers before we find a solution. +| N | v | v^2 | v^2 (base N) | Time | Evals | +| -: | --------: | -----------------: | --------------: | --------: | -------: | +| 2 | 1 | 1 | 1 | 0.000020 | 1 | +| 3 | 1 | 1 | 1 | 0.000022 | 4 | +| 4 | 15 | 225 | 3201 | 0.000014 | 1 | +| 5 | 24 | 576 | 4301 | 0.000043 | 31 | +| 6 | 195 | 38025 | 452013 | 0.000029 | 17 | +| 7 | 867 | 751689 | 6250341 | 0.000045 | 28 | +| 8 | 3213 | 10323369 | 47302651 | 0.001050 | 841 | +| 9 | 18858 | 355624164 | 823146570 | 0.000947 | 671 | +| 10 | 99066 | 9814072356 | 9814072356 | 0.000476 | 315 | +| 11 | 528905 | 279740499025 | A8701245369 | 0.004091 | 2564 | +| 12 | 2950717 | 8706730814089 | B8750A649321 | 0.035980 | 22903 | +| 13 | 4809627 | 23132511879129 | CBA504216873 | 18.936489 | 12533147 | +| 14 | 105011842 | 11027486960232964 | DC71B30685A924 | 0.143197 | 89326 | +| 15 | 659854601 | 435408094460869201 | EDAC93B24658701 | 0.315265 | 190654 | + + +You will note that most time is taken where `$n` is 13. You will note that for `$n` in `3`, `5`, `13` there are no pan-digital solutions so we have to loop through all the 13 digit numbers and reach the 12 digit numbers before we find a solution. *97.6%* of the checks for matching digits are in the case where `$n` is 13 (approximately 97% of the time in the code). + -- cgit From 27863c17b772945f2795edcba873a65500791469 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 24 Jan 2022 16:30:26 +0000 Subject: Update README.md --- challenge-149/james-smith/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-149/james-smith/README.md b/challenge-149/james-smith/README.md index 935315da63..37e10a0cab 100644 --- a/challenge-149/james-smith/README.md +++ b/challenge-149/james-smith/README.md @@ -89,5 +89,5 @@ The values for each value of $N are given below up to (base 15) - the largest va | 15 | 659854601 | 435408094460869201 | EDAC93B24658701 | 0.315265 | 190654 | -You will note that most time is taken where `$n` is 13. You will note that for `$n` in `3`, `5`, `13` there are no pan-digital solutions so we have to loop through all the 13 digit numbers and reach the 12 digit numbers before we find a solution. *97.6%* of the checks for matching digits are in the case where `$n` is 13 (approximately 97% of the time in the code). +You will note that most time is taken where `$n` is 13. You will note that for `$n` in `3`, `5`, `13` there are no pan-digital solutions so we have to loop through all the 13 digit numbers and reach the 12 digit numbers before we find a solution. **97.6%** of the checks for matching digits are in the case where `$n` is 13 (approximately *97%* of the time in the code). -- cgit From dedf5a105550b946c57596926d534ecab1683fa9 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 24 Jan 2022 16:30:45 +0000 Subject: Update README.md --- challenge-149/james-smith/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-149/james-smith/README.md b/challenge-149/james-smith/README.md index 37e10a0cab..475b4dfb28 100644 --- a/challenge-149/james-smith/README.md +++ b/challenge-149/james-smith/README.md @@ -89,5 +89,5 @@ The values for each value of $N are given below up to (base 15) - the largest va | 15 | 659854601 | 435408094460869201 | EDAC93B24658701 | 0.315265 | 190654 | -You will note that most time is taken where `$n` is 13. You will note that for `$n` in `3`, `5`, `13` there are no pan-digital solutions so we have to loop through all the 13 digit numbers and reach the 12 digit numbers before we find a solution. **97.6%** of the checks for matching digits are in the case where `$n` is 13 (approximately *97%* of the time in the code). +You will note that most time is taken where `$n` is 13. You will note that for `$n` in `3`, `5`, `13` there are no pan-digital solutions so we have to loop through all the 13 digit numbers and reach the 12 digit numbers before we find a solution. **97.6%** of the checks for matching digits are in the case where `$n` is 13 (approximately **97%** of the time in the code). -- cgit From 2ce2cc61314509613499e0355e84615df5a65979 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 24 Jan 2022 16:31:57 +0000 Subject: change output format - and include number of runs! --- challenge-149/james-smith/perl/ch-2.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/challenge-149/james-smith/perl/ch-2.pl b/challenge-149/james-smith/perl/ch-2.pl index 06fb45a17d..f24004f989 100644 --- a/challenge-149/james-smith/perl/ch-2.pl +++ b/challenge-149/james-smith/perl/ch-2.pl @@ -9,11 +9,15 @@ use Time::HiRes qw(time); my @MAP = ( 0..9,'A'..'Z' ); +## Format output so I can paste it straight into github markup... +say '| N | v | v^2 | v^2 (base N) | Time | Evals |'; +say '| -: | --------: | -----------------: | --------------: | --------: | -------: |'; + for my $N (2..15) { my $time = time; - my $v = biggest_perfect_square($N); - say sprintf '%2d v = %10d v^2 = %20d = %16s; TIME = %10.6f', - $N, $v, $v*$v, baseN($v*$v,$N), time-$time; + my ($v,$c) = biggest_perfect_square($N); + say sprintf '| %2d | %9d | %18d | %15s | %9.6f | %8d |', + $N, $v, $v*$v, baseN($v*$v,$N), time-$time, $c; } ## We brute force this - we start at the largest possible square. @@ -27,11 +31,12 @@ for my $N (2..15) { ## out of both the while and the for loop sub biggest_perfect_square { - my $n = shift; - O: for( my $t = int($n**($n/2)); $t; $t -- ) { + my $nt = my $m = (my $n = shift) -1; + $m=$m*$n+$nt while $nt--; + O: for( my $tn = my $t = int sqrt $m; $t; $t -- ) { my ($q,%seen) = $t**2; $seen{$q%$n}++?(next O):($q=int($q/$n)) while $q; - return $t; + return($t,$tn-$t+1); } } -- cgit From b94e67d7026dada1b8679732a2c55cf707f9e3ca Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 24 Jan 2022 16:32:04 +0000 Subject: added --- challenge-149/james-smith/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-149/james-smith/blog.txt diff --git a/challenge-149/james-smith/blog.txt b/challenge-149/james-smith/blog.txt new file mode 100644 index 0000000000..b2d392785b --- /dev/null +++ b/challenge-149/james-smith/blog.txt @@ -0,0 +1 @@ +https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-149/james-smith -- cgit From b5c9bfe42e52ff7446069a103ba0874d3a8c0361 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 24 Jan 2022 16:33:37 +0000 Subject: rabbit --- challenge-149/james-smith/perl/ch-1.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-149/james-smith/perl/ch-1.pl b/challenge-149/james-smith/perl/ch-1.pl index 7cd08cdc48..52c15c2a2d 100644 --- a/challenge-149/james-smith/perl/ch-1.pl +++ b/challenge-149/james-smith/perl/ch-1.pl @@ -19,6 +19,6 @@ for( my($n,$ds,$i,$fa,$fb,%fib)=(@ARGV?$ARGV[0]:20,0,0,1,1,0,1,1,1); ## Digit sum can only be 1 larger than current maximum ## fibonacci. ($fib{$fa+$fb},$fa,$fb)=(1,$fb,$fa+$fb) if $ds > $fb; - (say $i)**$n-- if exists $fib{$ds}; + $n--,say $i if exists $fib{$ds}; } -- cgit From 0d01621b90240a4320aaf59d0a8f8434b2f9b510 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 24 Jan 2022 16:34:03 +0000 Subject: Update README.md --- challenge-149/james-smith/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-149/james-smith/README.md b/challenge-149/james-smith/README