From e3c2b1a4332c3620a8bc7361f271ffdf32ec9931 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 6 Jan 2022 21:36:22 +0100 Subject: Week 004: Fix references. For part 1, this means fiddling with the fodder lines. --- challenge-004/abigail/awk/ch-1.awk | 10 +++++----- challenge-004/abigail/awk/ch-2.gawk | 2 +- challenge-004/abigail/bash/ch-1.sh | 11 +++++------ challenge-004/abigail/bash/ch-2.sh | 2 +- challenge-004/abigail/c/ch-1.c | 7 +++---- challenge-004/abigail/c/ch-2.c | 2 +- challenge-004/abigail/lua/ch-1.lua | 9 ++++----- challenge-004/abigail/lua/ch-2.lua | 2 +- challenge-004/abigail/node/ch-1.js | 5 ++--- challenge-004/abigail/node/ch-2.js | 2 +- challenge-004/abigail/perl/ch-1.pl | 5 ++--- challenge-004/abigail/perl/ch-2.pl | 2 +- challenge-004/abigail/python/ch-1.py | 17 ++++++++--------- challenge-004/abigail/python/ch-2.py | 4 ++-- challenge-004/abigail/ruby/ch-1.rb | 4 ++-- challenge-004/abigail/ruby/ch-2.rb | 2 +- 16 files changed, 40 insertions(+), 46 deletions(-) diff --git a/challenge-004/abigail/awk/ch-1.awk b/challenge-004/abigail/awk/ch-1.awk index 2264ee94d1..ef3e23fbf5 100644 --- a/challenge-004/abigail/awk/ch-1.awk +++ b/challenge-004/abigail/awk/ch-1.awk @@ -1,7 +1,7 @@ #!/usr/bin/awk # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # @@ -67,8 +67,8 @@ BEGIN { } # -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER? +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER! # diff --git a/challenge-004/abigail/awk/ch-2.gawk b/challenge-004/abigail/awk/ch-2.gawk index 11c73f7913..d5954a9edf 100644 --- a/challenge-004/abigail/awk/ch-2.gawk +++ b/challenge-004/abigail/awk/ch-2.gawk @@ -1,7 +1,7 @@ #!/opt/local/bin/gawk # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # diff --git a/challenge-004/abigail/bash/ch-1.sh b/challenge-004/abigail/bash/ch-1.sh index 1740f2d690..090463de8e 100644 --- a/challenge-004/abigail/bash/ch-1.sh +++ b/challenge-004/abigail/bash/ch-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # @@ -67,13 +67,12 @@ echo # # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER, +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER. # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER: # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER! +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! # diff --git a/challenge-004/abigail/bash/ch-2.sh b/challenge-004/abigail/bash/ch-2.sh index e9a2935272..38ea2179e2 100644 --- a/challenge-004/abigail/bash/ch-2.sh +++ b/challenge-004/abigail/bash/ch-2.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # diff --git a/challenge-004/abigail/c/ch-1.c b/challenge-004/abigail/c/ch-1.c index 21131ffb53..a4bd327725 100644 --- a/challenge-004/abigail/c/ch-1.c +++ b/challenge-004/abigail/c/ch-1.c @@ -3,7 +3,7 @@ # include /* - * See ../README.md + * See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 */ /* @@ -67,8 +67,7 @@ int main (void) { } /* - * FODDER FODDER FODDER FODDER FODDER FODDER FODDER - * FODDER FODDER FODDER FODDER FODDER FODDER FODDER. - * FODDER FODDER FODDER FODDER FODDER FODDER FODDER. + * FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER: * FODDER FODDER FODDER FODDER FODDER FODDER FODDER. + * FODDER FODDER FODDER FODDER FODDER FODDER FODDER!! */ diff --git a/challenge-004/abigail/c/ch-2.c b/challenge-004/abigail/c/ch-2.c index 3df60fc2dc..bbb7375b75 100644 --- a/challenge-004/abigail/c/ch-2.c +++ b/challenge-004/abigail/c/ch-2.c @@ -9,7 +9,7 @@ # define NR_OF_LETTERS 26 /* - * See ../README.md + * See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 */ /* diff --git a/challenge-004/abigail/lua/ch-1.lua b/challenge-004/abigail/lua/ch-1.lua index 03a06fd74b..f8f39b4135 100644 --- a/challenge-004/abigail/lua/ch-1.lua +++ b/challenge-004/abigail/lua/ch-1.lua @@ -1,7 +1,7 @@ #!/opt/local/bin/lua -- --- See ../README.md +-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 -- -- @@ -64,8 +64,7 @@ io . write ("\n") -- --- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER --- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER --- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER --- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! +-- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +-- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +-- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER!!!! -- diff --git a/challenge-004/abigail/lua/ch-2.lua b/challenge-004/abigail/lua/ch-2.lua index c1214ac67d..8454fa5d5d 100644 --- a/challenge-004/abigail/lua/ch-2.lua +++ b/challenge-004/abigail/lua/ch-2.lua @@ -1,7 +1,7 @@ #!/opt/local/bin/lua -- --- See ../README.md +-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 -- -- diff --git a/challenge-004/abigail/node/ch-1.js b/challenge-004/abigail/node/ch-1.js index aba62f0098..aad1be89d3 100644 --- a/challenge-004/abigail/node/ch-1.js +++ b/challenge-004/abigail/node/ch-1.js @@ -1,7 +1,7 @@ #!/usr/local/bin/node // -// See ../README.md +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 // // @@ -67,8 +67,7 @@ process . stdout . write ("\n") // -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER // FODDER FODDER FODDER FODDER FODDER FODDER FODDER // FODDER FODDER FODDER FODDER FODDER FODDER FODDER // FODDER FODDER FODDER FODDER FODDER FODDER FODDER diff --git a/challenge-004/abigail/node/ch-2.js b/challenge-004/abigail/node/ch-2.js index a239d89949..6327b42262 100644 --- a/challenge-004/abigail/node/ch-2.js +++ b/challenge-004/abigail/node/ch-2.js @@ -1,7 +1,7 @@ #!/usr/local/bin/node // -// See ../README.md +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 // // diff --git a/challenge-004/abigail/perl/ch-1.pl b/challenge-004/abigail/perl/ch-1.pl index a36eb78e42..1921bd3903 100644 --- a/challenge-004/abigail/perl/ch-1.pl +++ b/challenge-004/abigail/perl/ch-1.pl @@ -10,7 +10,7 @@ use experimental 'signatures'; use experimental 'lexical_subs'; # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # @@ -54,8 +54,7 @@ while () { print "\n"; # -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER!! # __DATA__ diff --git a/challenge-004/abigail/perl/ch-2.pl b/challenge-004/abigail/perl/ch-2.pl index 20cd5148b0..be5ee93be6 100644 --- a/challenge-004/abigail/perl/ch-2.pl +++ b/challenge-004/abigail/perl/ch-2.pl @@ -10,7 +10,7 @@ use experimental 'signatures'; use experimental 'lexical_subs'; # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # diff --git a/challenge-004/abigail/python/ch-1.py b/challenge-004/abigail/python/ch-1.py index 0f7f8bf725..af5d05111a 100644 --- a/challenge-004/abigail/python/ch-1.py +++ b/challenge-004/abigail/python/ch-1.py @@ -1,11 +1,11 @@ #!/opt/local/bin/python # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # -# Run as python ch-1.py +# Run as: python ch-1.py # import sys @@ -66,11 +66,10 @@ for i in range (0, len (pi), in_size): sys . stdout . write ("\n") # -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER!! +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER!! # diff --git a/challenge-004/abigail/python/ch-2.py b/challenge-004/abigail/python/ch-2.py index 4e94f7fe7d..26dd33b60f 100644 --- a/challenge-004/abigail/python/ch-2.py +++ b/challenge-004/abigail/python/ch-2.py @@ -1,11 +1,11 @@ #!/opt/local/bin/python # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # -# Run as python ch-2.py < input-file +# Run as: python ch-2.py < input-file # import fileinput diff --git a/challenge-004/abigail/ruby/ch-1.rb b/challenge-004/abigail/ruby/ch-1.rb index 7c9571686d..a5af29eeb0 100644 --- a/challenge-004/abigail/ruby/ch-1.rb +++ b/challenge-004/abigail/ruby/ch-1.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # @@ -70,5 +70,5 @@ printf "\n" # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER # FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER # diff --git a/challenge-004/abigail/ruby/ch-2.rb b/challenge-004/abigail/ruby/ch-2.rb index 5dfcb0afce..289187feed 100644 --- a/challenge-004/abigail/ruby/ch-2.rb +++ b/challenge-004/abigail/ruby/ch-2.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby # -# See ../README.md +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 # # -- cgit From 44dbdf9f6469b72a383eb3b95fbaf17d228facca Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 7 Jan 2022 14:07:10 +0100 Subject: Week 4, part1: Go solution --- challenge-004/abigail/README.md | 1 + challenge-004/abigail/go/ch-1.go | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 challenge-004/abigail/go/ch-1.go diff --git a/challenge-004/abigail/README.md b/challenge-004/abigail/README.md index 75267e87b2..2847d51cf2 100644 --- a/challenge-004/abigail/README.md +++ b/challenge-004/abigail/README.md @@ -24,6 +24,7 @@ and printing. We may even need to filler comments to make it all work out. * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) * [C](c/ch-1.c) +* [Go](go/ch-1.go) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.node) * [Perl](perl/ch-1.pl) diff --git a/challenge-004/abigail/go/ch-1.go b/challenge-004/abigail/go/ch-1.go new file mode 100644 index 0000000000..961f901695 --- /dev/null +++ b/challenge-004/abigail/go/ch-1.go @@ -0,0 +1,73 @@ +package main + +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 +// + +// +// Run as: go run ch-1.go < input-file +// + +import ( + "fmt" +) + +func main () { + first_ord := int ('"') + 1; + skip_ord := int ('\\'); + last_ord := int ('~'); + ord_range := last_ord - first_ord; + in_size := 5; + pi := [] rune ( + "%(uP7+Y`ME)gy(7')v?;%s^qc(Mj1}16idp'ONGs'2m.o,1HLY'}~P61@@Y-" + + "*O/.v,Jc~D+ttA'&EPjR(zXxD$dr,M$P=-f*YQqe,GIZ`0x5oL1(mpl17en`" + + ")Q$ge,L6_5.I;hj%yy6n,L_t')dtyy)[ugS&-3(c&lC:a&~8SP#+iis+WR&8" + + "*Y;V3/+JD@-J>7u0$Nh<#2&:@+#=`/*YtP-0t8uf+tf/V&yjx>+]S=&%d}7z" + + "0YXa9$SOyt$*mzv1&X(W(.{0G-Vya`0a}KI0pQD2,nV0:,WE0+#?F[>(iMb}" + + "%k(tB/UO0m.8R'x%Vys_-|IgL.y-n6(v[*#+/-J1#[`]" + + "&*M#'1wg" + + "-}+B}*jWDi)/2&k,h|/)+eu-3)9{mU-`:]M/YF$a.O0SF0{~2C.EjkZ&>|lD" + + "#%UmL+w)$V&14Ty0arq+%xnAo/XX/y0_=Bl/)f*}'Gc88'GV;X1RG~<+gJ8p" + + "&^E~A'/3N=*R2|j&SgD@-0St?*jL@'-ZsbD$+_hy.#HkF0cO_[#t0wL-8._r" + + "#0)@p#4(ha+lyD6,[|1w%_K//+c2#j.4xl2)SpX=.>)gp$R)ZP,IS%@,}%#J" + + "*1zj[,sIw#%6pwl%D'fk#Bx6'%4?.0&c9'?#R7P|&ZJ;M&q6q&&|h9?0LVI}" + + "(2lq>#/G+<,Bv`l+U'K?'2i}q+,J8W/7dU++X(l51R>#T&)fV0'I%FC%HHkt" + + "%{(NN&Kn$]*e0," + + "$K`U.%bSL*&dG^f,lN@.+jGbU.g8,s&FwUP$9p3S/)f(4,y>{*/L)t" + + "-Oi$Y*&I1x1Kyk#$}~i|)^4uG%|&sU)XNR-,PLl/.lmT'&_~it-16U9-B~A[" + + "(}s.a0~]Zj*<*~%-~N27%$O,*/a,,c%<#@60On3z0~3@B13UOG/A^&K,GRHi" + + ",S_:*&9I{_$nCM9&U^*9)WmPj+$TL8.]WpP)CWDR$u#7])K/Bi+,[B9(0~a&" + + "&=aag,L-UG#HoAx/=@p,&ux{:0($3X*[J<4,eh{E1F&tE$cGo.&C}15*:u{Z" + + ",:*H^'f,=~$,z%B)WZbL$DjA;/oFKa%.>ig/^o.90e/P=*Auex0TD}p/hncA" + + "/%d87#/u19,r&sM(A+4V0%4u$.}F+P0o|4e.g(<[#5yy*]3@5%II741/XZ>)Lm6e0``3L%.JF[+Z?8b(tj7C" + + "'S/z}#vS|i)S9[=*/nCG)PMaY-{pML);vN?%kRcr#*.Tg,x;42'(1w.0dA)S" + + ")-us%.#1$R-rkwf%m%B-(ctK8+4Sn^%*C1Y-wqsr%eNg11%$De&&07q+%1>-" + + "+mCl2%)V#w%#y:[,?t*D$64`9.U+{`-SBX-+gi/o)0B$q#V$tW+#lmM)';EH" + + "%yFPZ/Gy(~,dl@h)A&ju-Co2,-du++)[Awk&wE}p*H;._.[]4W+Eb7K#iiKB") + fmt . Print ("3.") + for i := 0; i < len (pi); i += in_size { + out := 0 + for j := i; j < i + in_size; j ++ { + out *= ord_range + out += int (pi [j]) - first_ord + if int (pi [j]) > skip_ord { + out -- + } + } + fmt . Printf ("%09d", out) + } + fmt . Print ("\n") +} + +// +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! +// -- cgit From 729d909478f75603982c1e15ea8cd60fc2bf20fa Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 7 Jan 2022 14:36:10 +0100 Subject: Week 4, part1: Java solution --- challenge-004/abigail/README.md | 1 + challenge-004/abigail/java/ch-1.java | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 challenge-004/abigail/java/ch-1.java diff --git a/challenge-004/abigail/README.md b/challenge-004/abigail/README.md index 2847d51cf2..98e4afda0d 100644 --- a/challenge-004/abigail/README.md +++ b/challenge-004/abigail/README.md @@ -25,6 +25,7 @@ and printing. We may even need to filler comments to make it all work out. * [Bash](bash/ch-1.sh) * [C](c/ch-1.c) * [Go](go/ch-1.go) +* [Java](java/ch-1.java) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.node) * [Perl](perl/ch-1.pl) diff --git a/challenge-004/abigail/java/ch-1.java b/challenge-004/abigail/java/ch-1.java new file mode 100644 index 0000000000..cba07272da --- /dev/null +++ b/challenge-004/abigail/java/ch-1.java @@ -0,0 +1,66 @@ +// +// See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 +// + +// +// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file +// + +import java.util.*; + +public class ch1 { + public static void main (String [] args) { + int first = '"' + 1; + int skip = '\\'; + int last = '~'; + int range = last - first; + int in_size = 5; + char [] pi = + ("%(uP7+Y`ME)gy(7')v?;%s^qc(Mj1}16idp'ONGs'2m.o,1HLY'}~P61@@Y-" + + "*O/.v,Jc~D+ttA'&EPjR(zXxD$dr,M$P=-f*YQqe,GIZ`0x5oL1(mpl17en`" + + ")Q$ge,L6_5.I;hj%yy6n,L_t')dtyy)[ugS&-3(c&lC:a&~8SP#+iis+WR&8" + + "*Y;V3/+JD@-J>7u0$Nh<#2&:@+#=`/*YtP-0t8uf+tf/V&yjx>+]S=&%d}7z" + + "0YXa9$SOyt$*mzv1&X(W(.{0G-Vya`0a}KI0pQD2,nV0:,WE0+#?F[>(iMb}" + + "%k(tB/UO0m.8R'x%Vys_-|IgL.y-n6(v[*#+/-J1#[`]" + + "&*M#'1wg" + + "-}+B}*jWDi)/2&k,h|/)+eu-3)9{mU-`:]M/YF$a.O0SF0{~2C.EjkZ&>|lD" + + "#%UmL+w)$V&14Ty0arq+%xnAo/XX/y0_=Bl/)f*}'Gc88'GV;X1RG~<+gJ8p" + + "&^E~A'/3N=*R2|j&SgD@-0St?*jL@'-ZsbD$+_hy.#HkF0cO_[#t0wL-8._r" + + "#0)@p#4(ha+lyD6,[|1w%_K//+c2#j.4xl2)SpX=.>)gp$R)ZP,IS%@,}%#J" + + "*1zj[,sIw#%6pwl%D'fk#Bx6'%4?.0&c9'?#R7P|&ZJ;M&q6q&&|h9?0LVI}" + + "(2lq>#/G+<,Bv`l+U'K?'2i}q+,J8W/7dU++X(l51R>#T&)fV0'I%FC%HHkt" + + "%{(NN&Kn$]*e0," + + "$K`U.%bSL*&dG^f,lN@.+jGbU.g8,s&FwUP$9p3S/)f(4,y>{*/L)t" + + "-Oi$Y*&I1x1Kyk#$}~i|)^4uG%|&sU)XNR-,PLl/.lmT'&_~it-16U9-B~A[" + + "(}s.a0~]Zj*<*~%-~N27%$O,*/a,,c%<#@60On3z0~3@B13UOG/A^&K,GRHi" + + ",S_:*&9I{_$nCM9&U^*9)WmPj+$TL8.]WpP)CWDR$u#7])K/Bi+,[B9(0~a&" + + "&=aag,L-UG#HoAx/=@p,&ux{:0($3X*[J<4,eh{E1F&tE$cGo.&C}15*:u{Z" + + ",:*H^'f,=~$,z%B)WZbL$DjA;/oFKa%.>ig/^o.90e/P=*Auex0TD}p/hncA" + + "/%d87#/u19,r&sM(A+4V0%4u$.}F+P0o|4e.g(<[#5yy*]3@5%II741/XZ>)Lm6e0``3L%.JF[+Z?8b(tj7C" + + "'S/z}#vS|i)S9[=*/nCG)PMaY-{pML);vN?%kRcr#*.Tg,x;42'(1w.0dA)S" + + ")-us%.#1$R-rkwf%m%B-(ctK8+4Sn^%*C1Y-wqsr%eNg11%$De&&07q+%1>-" + + "+mCl2%)V#w%#y:[,?t*D$64`9.U+{`-SBX-+gi/o)0B$q#V$tW+#lmM)';EH" + + "%yFPZ/Gy(~,dl@h)A&ju-Co2,-du++)[Awk&wE}p*H;._.[]4W+Eb7K#iiKB") . + toCharArray (); + System . out . print ("3."); + for (int i = 0; i < pi . length; i += in_size) { + int out = 0; + for (int j = i; j < i + in_size; j ++) { + out *= range; + out += pi [j] - first; + if (pi [j] > skip) { + out --; + } + } + System . out . printf ("%09d", out); + } + System . out . print ("\n"); + } +} + +// FODDER FODDER! -- cgit From 29230d1c0af2972b3cc1008566d160f1a22c3430 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 7 Jan 2022 15:36:13 +0100 Subject: Week 4, part 1: bc solution --- challenge-004/abigail/bc/ch-1.bc | 59 ++++++++++++++++++++++++++++++++++ challenge-004/abigail/t/ctest.ini | 12 +++++++ challenge-004/abigail/t/input-1-2 | 0 challenge-004/abigail/t/output-1-2.exp | 1 + 4 files changed, 72 insertions(+) create mode 100644 challenge-004/abigail/bc/ch-1.bc create mode 100644 challenge-004/abigail/t/input-1-2 create mode 100644 challenge-004/abigail/t/output-1-2.exp diff --git a/challenge-004/abigail/bc/ch-1.bc b/challenge-004/abigail/bc/ch-1.bc new file mode 100644 index 0000000000..98f682f3ab --- /dev/null +++ b/challenge-004/abigail/bc/ch-1.bc @@ -0,0 +1,59 @@ +#!/usr/bin/bc + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 +# + +# +# Run as: bc -l ch-1.bc +# + +scale = 3240 +4 * a (1) +halt + +# +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER: +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! +# diff --git a/challenge-004/abigail/t/ctest.ini b/challenge-004/abigail/t/ctest.ini index 161f1c35f0..c72f82b193 100644 --- a/challenge-004/abigail/t/ctest.ini +++ b/challenge-004/abigail/t/ctest.ini @@ -1,11 +1,23 @@ [names] 1-1 = Pi, 3242 digits +1-2 = Pi, 3242 digits 2-1 = Small wordlist 2-2 = Large wordlist [challenges/1] extra_tests = Check_Program_Size +[1-1/bc] +skip = Not for bc + +[1-2] +skip = Only for bc + +[1-2/bc] +skip = 0 +exe_args = -l %RUN_FILE +env = BC_LINE_LENGTH=3300 + [2-1/node] line_at_a_time = 1 diff --git a/challenge-004/abigail/t/input-1-2 b/challenge-004/abigail/t/input-1-2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-004/abigail/t/output-1-2.exp b/challenge-004/abigail/t/output-1-2.exp new file mode 100644 index 0000000000..9596eb7c20 --- /dev/null +++ b/challenge-004/abigail/t/output-1-2.exp @@ -0,0 +1 @@ +3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796782354781636009341721641219924586315030286182974555706749838505494588586926995690927210797509302955321165344987202755960236480665499119881834797753566369807426542527862551818417574672890977772793800081647060016145249192173217214772350141441973568548161361157352552133475741849468438523323907394143334547762416862518983569485562099219222184272550254256887671790494601653466804988627232791786085784383827967976681454100953883786360950680064225125205117392984896084128488626945604241965285022210661186306744278622039194945047123713786960956364371917287467764657573962413890865832645995813390478027590099465764078951269468398352595709825822620522489407726719478268482601476990902640136394437455305068203496252451749399651431429809190659250937221696461515709858387410597885959772975498930161753928468138268683868942774155991855925245953959431049972524680845987273644695848653836736222626099124608051243884390451244136549762780797715691435997700129616089441694868555848406353422072225828488648158456028506016842739452267467678895252138522549954666727823986456596116354886230577456498035593634568174324112515076069479451096596094025228879710893145669136867228748940560101503308617928680920874760917824938589009714909675985261365549781893129784821682998948722658804857564014270477555132379641451523746234364542858444795265867821051141354735739523113427166102135969536231442952484937187110145765403590279934403742007310578539062198387447808478489683321445713868751943506430218453191048481005370614680674919278191197939952061419663428754440643745123718192179998391015919561814675142691239748940907186494231961567945208095146550225231603881930142093762137855956638937787083039069792077346722182562599661501421503068038447734549202605414665925201497442850732518666002132434088190710486331734649651453905796268561005508106658796998163574736384052571456 -- cgit From b5f0bb3367e23fb81e170d3796d871f5e349877d Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 7 Jan 2022 15:44:29 +0100 Subject: Week 4, part 1: Fix 'Run as:' line for Go, Java and Node.js --- challenge-004/abigail/go/ch-1.go | 12 ++++++------ challenge-004/abigail/java/ch-1.java | 4 ++-- challenge-004/abigail/node/ch-1.js | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/challenge-004/abigail/go/ch-1.go b/challenge-004/abigail/go/ch-1.go index 961f901695..134f8f2c6b 100644 --- a/challenge-004/abigail/go/ch-1.go +++ b/challenge-004/abigail/go/ch-1.go @@ -5,7 +5,7 @@ package main // // -// Run as: go run ch-1.go < input-file +// Run as: go run ch-1.go // import ( @@ -65,9 +65,9 @@ func main () { } // -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER, +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER, +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER? +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER: +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! // diff --git a/challenge-004/abigail/java/ch-1.java b/challenge-004/abigail/java/ch-1.java index cba07272da..80322e375c 100644 --- a/challenge-004/abigail/java/ch-1.java +++ b/challenge-004/abigail/java/ch-1.java @@ -3,7 +3,7 @@ // // -// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file +// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 // import java.util.*; @@ -63,4 +63,4 @@ public class ch1 { } } -// FODDER FODDER! +// FODDER FODDER FODDER FODDER! diff --git a/challenge-004/abigail/node/ch-1.js b/challenge-004/abigail/node/ch-1.js index aad1be89d3..cc75958b8f 100644 --- a/challenge-004/abigail/node/ch-1.js +++ b/challenge-004/abigail/node/ch-1.js @@ -5,7 +5,7 @@ // // -// Run as: node ch-1.js < input-file +// Run as: node ch-1.js // let pi = "%(uP7+Y`ME)gy(7')v?;%s^qc(Mj1}16idp'ONGs'2m.o,1HLY'}~P61@@Y-" + @@ -67,8 +67,8 @@ process . stdout . write ("\n") // -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER -// FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +// FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER // -- cgit From 23d627e6ea19493fab5640509b8e97bc74b5082c Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 7 Jan 2022 18:19:40 +0100 Subject: Week 4, part 1: Pascal solution --- challenge-004/abigail/README.md | 2 + challenge-004/abigail/pascal/ch-1.p | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 challenge-004/abigail/pascal/ch-1.p diff --git a/challenge-004/abigail/README.md b/challenge-004/abigail/README.md index 98e4afda0d..3bc8c65c4e 100644 --- a/challenge-004/abigail/README.md +++ b/challenge-004/abigail/README.md @@ -23,11 +23,13 @@ and printing. We may even need to filler comments to make it all work out. ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) +* [bc](bc/ch-1.bc) * [C](c/ch-1.c) * [Go](go/ch-1.go) * [Java](java/ch-1.java) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.node) +* [Pascal](pascal/ch-1.p) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) * [Ruby](ruby/ch-1.rb) diff --git a/challenge-004/abigail/pascal/ch-1.p b/challenge-004/abigail/pascal/ch-1.p new file mode 100644 index 0000000000..9578563329 --- /dev/null +++ b/challenge-004/abigail/pascal/ch-1.p @@ -0,0 +1,73 @@ +Program XXX; + +(* *) +(* See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 *) +(* *) + +(* *) +(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out *) +(* *) + +uses + sysutils; + +var + pi: AnsiString; + first, last, skip, dquote, quote, range, ch, i, j, in_size: integer; + out: qword; + +begin + first := ord ('"') + 1; + last := ord ('~'); + skip := ord ('\'); + dquote := ord ('"'); + quote := ord (''''); + range := last - first; + in_size := 5; + pi := '%(uP7+Y`ME)gy(7")v?;%s^qc(Mj1}16idp"ONGs"2m.o,1HLY"}~P61@@Y-' + + '*O/.v,Jc~D+ttA"&EPjR(zXxD$dr,M$P=-f*YQqe,GIZ`0x5oL1(mpl17en`' + + ')Q$ge,L6_5.I;hj%yy6n,L_t")dtyy)[ugS&-3(c&lC:a&~8SP#+iis+WR&8' + + '*Y;V3/+JD@-J>7u0$Nh<#2&:@+#=`/*YtP-0t8uf+tf/V&yjx>+]S=&%d}7z' + + '0YXa9$SOyt$*mzv1&X(W(.{0G-Vya`0a}KI0pQD2,nV0:,WE0+#?F[>(iMb}' + + '%k(tB/UO0m.8R"x%Vys_-|IgL.y-n6(v[*#+/-J1#[`]' + + '&*M#"1wg' + + '-}+B}*jWDi)/2&k,h|/)+eu-3)9{mU-`:]M/YF$a.O0SF0{~2C.EjkZ&>|lD' + + '#%UmL+w)$V&14Ty0arq+%xnAo/XX/y0_=Bl/)f*}"Gc88"GV;X1RG~<+gJ8p' + + '&^E~A"/3N=*R2|j&SgD@-0St?*jL@"-ZsbD$+_hy.#HkF0cO_[#t0wL-8._r' + + '#0)@p#4(ha+lyD6,[|1w%_K//+c2#j.4xl2)SpX=.>)gp$R)ZP,IS%@,}%#J' + + '*1zj[,sIw#%6pwl%D"fk#Bx6"%4?.0&c9"?#R7P|&ZJ;M&q6q&&|h9?0LVI}' + + '(2lq>#/G+<,Bv`l+U"K?"2i}q+,J8W/7dU++X(l51R>#T&)fV0"I%FC%HHkt' + + '%{(NN&Kn$]*e0,' + + '$K`U.%bSL*&dG^f,lN@.+jGbU.g8,s&FwUP$9p3S/)f(4,y>{*/L)t' + + '-Oi$Y*&I1x1Kyk#$}~i|)^4uG%|&sU)XNR-,PLl/.lmT"&_~it-16U9-B~A[' + + '(}s.a0~]Zj*<*~%-~N27%$O,*/a,,c%<#@60On3z0~3@B13UOG/A^&K,GRHi' + + ',S_:*&9I{_$nCM9&U^*9)WmPj+$TL8.]WpP)CWDR$u#7])K/Bi+,[B9(0~a&' + + '&=aag,L-UG#HoAx/=@p,&ux{:0($3X*[J<4,eh{E1F&tE$cGo.&C}15*:u{Z' + + ',:*H^"f,=~$,z%B)WZbL$DjA;/oFKa%.>ig/^o.90e/P=*Auex0TD}p/hncA' + + '/%d87#/u19,r&sM(A+4V0%4u$.}F+P0o|4e.g(<[#5yy*]3@5%II741/XZ>)Lm6e0``3L%.JF[+Z?8b(tj7C' + + '"S/z}#vS|i)S9[=*/nCG)PMaY-{pML);vN?%kRcr#*.Tg,x;42"(1w.0dA)S' + + ')-us%.#1$R-rkwf%m%B-(ctK8+4Sn^%*C1Y-wqsr%eNg11%$De&&07q+%1>-' + + '+mCl2%)V#w%#y:[,?t*D$64`9.U+{`-SBX-+gi/o)0B$q#V$tW+#lmM)";EH' + + '%yFPZ/Gy(~,dl@h)A&ju-Co2,-du++)[Awk&wE}p*H;._.[]4W+Eb7K#iiKB'; + write ('3.'); + i := 1; + while i <= length (pi) do begin + out := 0; + for j := i to i + in_size - 1 do begin + ch := ord (pi [j]); + if ch = dquote then + ch := quote; + out := out * range + ch - first; + if ch > skip then + out := out - 1; + end; + i := i + in_size; + write (format ('%.9D', [out])); + end; + writeln (''); +end. -- cgit From 30f2c751214fba83c926b409ecf60f402fb75b7b Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 7 Jan 2022 20:41:21 +0100 Subject: Week 4, part 1. R solution --- challenge-004/abigail/README.md | 1 + challenge-004/abigail/r/ch-1.r | 70 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 challenge-004/abigail/r/ch-1.r diff --git a/challenge-004/abigail/README.md b/challenge-004/abigail/README.md index 3bc8c65c4e..6d83ea003f 100644 --- a/challenge-004/abigail/README.md +++ b/challenge-004/abigail/README.md @@ -32,6 +32,7 @@ and printing. We may even need to filler comments to make it all work out. * [Pascal](pascal/ch-1.p) * [Perl](perl/ch-1.pl) * [Python](python/ch-1.py) +* [R](r/ch-1.r) * [Ruby](ruby/ch-1.rb) diff --git a/challenge-004/abigail/r/ch-1.r b/challenge-004/abigail/r/ch-1.r new file mode 100644 index 0000000000..227256a10f --- /dev/null +++ b/challenge-004/abigail/r/ch-1.r @@ -0,0 +1,70 @@ +#!/usr/local/bin/Rscript + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-004 +# + +# +# Run as: Rscript ch-1.r +# + +first_ord <- as.integer (charToRaw ('"')) + 1 +last_ord <- as.integer (charToRaw ('~')) +skip_ord <- as.integer (charToRaw ('\\')) - first_ord +range <- last_ord - first_ord +in_size <- 5 + +pi <- as.integer (charToRaw (paste ( + "%(uP7+Y`ME)gy(7')v?;%s^qc(Mj1}16idp'ONGs'2m.o,1HLY'}~P61@@Y-", + "*O/.v,Jc~D+ttA'&EPjR(zXxD$dr,M$P=-f*YQqe,GIZ`0x5oL1(mpl17en`", + ")Q$ge,L6_5.I;hj%yy6n,L_t')dtyy)[ugS&-3(c&lC:a&~8SP#+iis+WR&8", + "*Y;V3/+JD@-J>7u0$Nh<#2&:@+#=`/*YtP-0t8uf+tf/V&yjx>+]S=&%d}7z", + "0YXa9$SOyt$*mzv1&X(W(.{0G-Vya`0a}KI0pQD2,nV0:,WE0+#?F[>(iMb}", + "%k(tB/UO0m.8R'x%Vys_-|IgL.y-n6(v[*#+/-J1#[`]", + "&*M#'1wg", + "-}+B}*jWDi)/2&k,h|/)+eu-3)9{mU-`:]M/YF$a.O0SF0{~2C.EjkZ&>|lD", + "#%UmL+w)$V&14Ty0arq+%xnAo/XX/y0_=Bl/)f*}'Gc88'GV;X1RG~<+gJ8p", + "&^E~A'/3N=*R2|j&SgD@-0St?*jL@'-ZsbD$+_hy.#HkF0cO_[#t0wL-8._r", + "#0)@p#4(ha+lyD6,[|1w%_K//+c2#j.4xl2)SpX=.>)gp$R)ZP,IS%@,}%#J", + "*1zj[,sIw#%6pwl%D'fk#Bx6'%4?.0&c9'?#R7P|&ZJ;M&q6q&&|h9?0LVI}", + "(2lq>#/G+<,Bv`l+U'K?'2i}q+,J8W/7dU++X(l51R>#T&)fV0'I%FC%HHkt", + "%{(NN&Kn$]*e0,", + "$K`U.%bSL*&dG^f,lN@.+jGbU.g8,s&FwUP$9p3S/)f(4,y>{*/L)t", + "-Oi$Y*&I1x1Kyk#$}~i|)^4uG%|&sU)XNR-,PLl/.lmT'&_~it-16U9-B~A[", + "(}s.a0~]Zj*<*~%-~N27%$O,*/a,,c%<#@60On3z0~3@B13UOG/A^&K,GRHi", + ",S_:*&9I{_$nCM9&U^*9)WmPj+$TL8.]WpP)CWDR$u#7])K/Bi+,[B9(0~a&", + "&=aag,L-UG#HoAx/=@p,&ux{:0($3X*[J<4,eh{E1F&tE$cGo.&C}15*:u{Z", + ",:*H^'f,=~$,z%B)WZbL$DjA;/oFKa%.>ig/^o.90e/P=*Auex0TD}p/hncA", + "/%d87#/u19,r&sM(A+4V0%4u$.}F+P0o|4e.g(<[#5yy*]3@5%II741/XZ>)Lm6e0``3L%.JF[+Z?8b(tj7C", + "'S/z}#vS|i)S9[=*/nCG)PMaY-{pML);vN?%kRcr#*.Tg,x;42'(1w.0dA)S", + ")-us%.#1$R-rkwf%m%B-(ctK8+4Sn^%*C1Y-wqsr%eNg11%$De&&07q+%1>-", + "+mCl2%)V#w%#y:[,?t*D$64`9.U+{`-SBX-+gi/o)0B$q#V$tW+#lmM)';EH", + "%yFPZ/Gy(~,dl@h)A&ju-Co2,-du++)[Awk&wE}p*H;._.[]4W+Eb7K#iiKB", + sep = '', collapse = ''))) - c (first_ord) + +i <- 1 +cat ("3.") +while (i < length (pi)) { + out <- 0 + for (j in i : (i + in_size - 1)) { + out <- out * range + pi [[j]] + if (pi [[j]] > skip_ord) { + out <- out - 1 + } + } + i <- i + in_size + cat (sprintf ("%09d", out)) +} +cat ("\n") + +# +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER +# FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER! +# -- cgit From 2a8a2434896d98d8f59ff739fab15405a191f76b Mon Sep 17 00:00:00 2001 From: Jan Krňávek Date: Sat, 8 Jan 2022 19:24:31 +0100 Subject: solutions week 146 --- challenge-146/wambash/raku/ch-1.raku | 22 ++++++++++++++++++++++ challenge-146/wambash/raku/ch-2.raku | 27 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 challenge-146/wambash/raku/ch-1.raku create mode 100644 challenge-146/wambash/raku/ch-2.raku diff --git a/challenge-146/wambash/raku/ch-1.raku b/challenge-146/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..aa8c9f75ba --- /dev/null +++ b/challenge-146/wambash/raku/ch-1.raku @@ -0,0 +1,22 @@ +#!/usr/bin/env raku + +constant @prime = ^Inf .grep: *.is-prime; + +sub n-prime-number ($n=10001) { + @prime + andthen .skip: $n-1 + andthen .head +} + +multi MAIN (Bool :test($)!) { + use Test; + is n-prime-number(1),2; + is n-prime-number(2),3; + is n-prime-number(6),13; + is n-prime-number(), 104_743; + done-testing; +} + +multi MAIN ($n=10001) { + say n-prime-number $n +} diff --git a/challenge-146/wambash/raku/ch-2.raku b/challenge-146/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..167ec464d6 --- /dev/null +++ b/challenge-146/wambash/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/usr/bin/env raku + +multi sub parent (Rat $r where * > 1) { + $r - 1 +} + +multi sub parent (Rat $r) { + $r / (1-$r) +} + +sub curious-fraction-tree (Rat $member) { + $member, *.&parent ... 1 +} + +multi MAIN (Bool :test($)!) { + use Test; + is curious-fraction-tree(3/5), (3/5, 3/2, 1/2, 1); + is curious-fraction-tree(4/3), (4/3, 1/3, 1/2, 1); + is curious-fraction-tree(121/155), (121/155, 121/34, 87/34, 53/34, 19/34, 19/15, 4/15, 4/11, 4/7, 4/3, 1/3, 1/2, 1); + done-testing; +} + +multi MAIN ($member) { + curious-fraction-tree $member + andthen .map: *.nude.join: '/' + andthen .put +} -- cgit From b2a17ffd1dc54aae0fb98681489af4604cf49cc2 Mon Sep 17 00:00:00 2001 From: dcw Date: Sat, 8 Jan 2022 21:51:29 +0000 Subject: imported my solutions to both tasks, liked both, and only took 30 minutes overall to solve both --- challenge-146/duncan-c-white/README | 74 ++++++------------- challenge-146/duncan-c-white/perl/MakePrimes.pm | 97 +++++++++++++++++++++++++ challenge-146/duncan-c-white/perl/ch-1.pl | 49 +++++++++++++ challenge-146/duncan-c-white/perl/ch-2.pl | 64 ++++++++++++++++ 4 files changed, 231 insertions(+), 53 deletions(-) create mode 100644 challenge-146/duncan-c-white/perl/MakePrimes.pm create mode 100755 challenge-146/duncan-c-white/perl/ch-1.pl create mode 100755 challenge-146/duncan-c-white/perl/ch-2.pl diff --git a/challenge-146/duncan-c-white/README b/challenge-146/duncan-c-white/README index bdbeb3c3a5..aae0f64482 100644 --- a/challenge-146/duncan-c-white/README +++ b/challenge-146/duncan-c-white/README @@ -1,71 +1,39 @@ -TASK #1 - Dot Product +TASK #1 - 10001st Prime Number -You are given 2 arrays of same size, @a and @b. +Write a script to generate the 10001st prime number. -Write a script to implement Dot Product. +(Remember that 2 is the 1st prime number). -Example: - @a = (1, 2, 3); - @b = (4, 5, 6); +MY NOTES: Very easy, especially (tada) if you happen to have a prime +generating module that you've already used several times in these +challenges.. - $dot_product = (1 * 4) + (2 * 5) + (3 * 6) => 4 + 10 + 18 => 32 -MY NOTES: Very easy. +TASK #2 - Curious Fraction Tree +Consider the following Curious Fraction Tree: -TASK #2 - Palindromic Tree +[diagram in which the root is 1/1, and for each element N/D +it's right child is N+D/D, and it's left child is N/N+D] -You are given a string $s. +You are given a N/D member of the tree created similar to the above sample. -Write a script to create a Palindromic Tree for the given string. - -I found this blog exaplaining Palindromic Tree in detail: - -https://medium.com/@alessiopiergiacomi/eertree-or-palindromic-tree-82453e75025b +Write a script to find out the parent and grandparent of the given member. Example 1: - Input: $s = 'redivider' - Output: r redivider e edivide d divid i ivi v + Input: $member = '3/5'; + Output: parent = '3/2' and grandparent = '1/2' Example 2: - Input: $s = 'deific' - Output: d e i ifi f c - -Example 3: - - Input: $s = 'rotors' - Output: r rotor o oto t s - -Example 4: - - Input: $s = 'challenge' - Output: c h a l ll e n g - -Example 5: - - Input: $s = 'champion' - Output: c h a m p i o n - -Example 6: - - Input: $s = 'christmas' - Output: c h r i s t m a - -MY NOTES: hmm.. I read the blog, but what on earth is it -talking about, it's not very clear? the underlying paper -https://arxiv.org/pdf/1506.04862.pdf is a lot clearer, but -still way too detailed for 10pm on a Sunday. + Input: $member = '4/3'; + Output: parent = '1/3' and grandparent = '1/2' -Looking at the examples given above, the output seems to be -a list of palindromic substrings not previously encountered, -in the natural order found by sequencing through every starting -position in the word and trying increasingly long substrings -for "Palindromic"-ness. +MY NOTES: hmm.. having determined the left and right child rules +above, I worked out that given a child N/D the parent rule is +"if D>N then (N, D-N) else (N-D, D)" -So, could we solve the "generate the output from the input" -problem, entirely ignoring the whole "build a weird tree" -part of it? Presumably a lot less efficient than their -clever eertree/Palindrome tree thingy, but who cares. +So very easy using that rule twice (and why not go all the way up to +the root while we're doing it). diff --git a/challenge-146/duncan-c-white/perl/MakePrimes.pm b/challenge-146/duncan-c-white/perl/MakePrimes.pm new file mode 100644 index 0000000000..6b5cd8e9fe --- /dev/null +++ b/challenge-146/duncan-c-white/perl/MakePrimes.pm @@ -0,0 +1,97 @@ +# +# mkprimes module (converted from mkprimes.c) +# + +use strict; +use warnings; +use Function::Parameters; + + +my $debug = 0; +my @foundprimes; # remember all primes we've found.. + + +fun prime_debug( $d ) +{ + $debug = $d; +} + + +# +# my @primes = primes_upto( $n ); +# Find all primes up to N; return a list of all such primes +# (note that 1 is not usually considered a prime) +# +fun primes_upto( $n ) +{ + my @isprime; + + for( my $i=1; $i<=$n; $i++ ) + { + $isprime[$i] = 1; # initially + } + + # now sieve the non-primes out.. + my $upper = int(sqrt($n)); + printf( "debug: n=%d, upper=%d\n", $n, $upper ) if $debug; + for( my $i=2; $i<=$upper; $i++ ) + { + if( $isprime[$i] ) + { + #printf( "debug: crossing out multiples of %d\n", $i ); + for( my $j=$i*$i; $j<=$n; $j+=$i ) + { + $isprime[$j] = 0; + } + } + } + + # after sieving, extract the primes + my @primes = grep { $isprime[$_] } 2..$n; + + # remember them + @foundprimes = @primes; + + return @primes; +} + + +# +# my @moreprimes = more_primes( $n, $m ); +# Need more primes! Have @foundprimes up to $n, but need +# to sieve primes from $n+1..$m, so re-sieve, return +# a list of all new primes (in the range $n+1..$m) that we find. +# +fun more_primes( $n, $m ) +{ + my %isprime; + + print "finding more primes from ", $n+1, "..$m\n" if $debug; + + for( my $i=$n+1; $i<=$m; $i++ ) + { + $isprime{$i} = 1; # pre-sieving + } + + # now sieve the non-primes out.. + foreach my $prime (@foundprimes) + { + # find first multiple of $prime > $n + my $mult = $prime * (int($n/$prime)+1); + + #print "debug: xo multiples of $prime from $mult to $m\n"; + + for( my $j=$mult; $j<=$m; $j+=$prime ) + { + delete $isprime{$j}; + } + } + + # after sieving, extract the primes + my @primes = grep { $isprime{$_} } $n+1..$m; + push @foundprimes, @primes; + return @primes; +} + + +1; diff --git a/challenge-146/duncan-c-white/perl/ch-1.pl b/challenge-146/duncan-c-white/perl/ch-1.pl new file mode 100755 index 0000000000..c90a9b20de --- /dev/null +++ b/challenge-146/duncan-c-white/perl/ch-1.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl +# +# TASK #1 - 10001st Prime Number +# +# Write a script to generate the 10001st prime number. +# +# (Remember that 2 is the 1st prime number). +# +# +# MY NOTES: Very easy, especially (tada) if you happen to have a prime +# generating module that you've already used several times in these +# challenges.. +# + +use strict; +use warnings; +use feature 'say'; +use Getopt::Long; +use Data::Dumper; + +use lib qw(.); +use MakePrimes; + +my $debug=0; +die "Usage: nth-prime [--debug] [N, default 10001]\n" unless + GetOptions( "debug"=>\$debug ) && @ARGV<2; + +my $n = shift // 10001; + +prime_debug( $debug ); + +my $bandwidth = 10000; +my $upto = $bandwidth; +my @primes = primes_upto( $upto ); + +#die Dumper(\@primes); + +my $primesfound = @primes; + +while( $primesfound < $n ) +{ + my $from = $upto; + $upto += $bandwidth; + my @moreprimes = more_primes( $from, $upto ); + push @primes, @moreprimes; + $primesfound = @primes; +} + +say $primes[$n-1]; diff --git a/challenge-146/duncan-c-white/perl/ch-2.pl b/challenge-146/duncan-c-white/perl/ch-2.pl new file mode 100755 index 0000000000..c14d2ac179 --- /dev/null +++ b/challenge-146/duncan-c-white/perl/ch-2.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl +# +# TASK #2 - Curious Fraction Tree +# +# Consider the following Curious Fraction Tree: +# +# [diagram in which the root is 1/1, and for each element N/D +# it's right child is N+D/D, and it's left child is N/N+D] +# +# You are given a N/D member of the tree created similar to the above sample. +# +# Write a script to find out the parent and grandparent of the given member. +# +# Example 1: +# +# Input: $member = '3/5'; +# Output: parent = '3/2' and grandparent = '1/2' +# +# Example 2: +# +# Input: $member = '4/3'; +# Output: parent = '1/3' and grandparent = '1/2' +# +# MY NOTES: hmm.. having determined the left and right child rules +# above, I worked out that given a child N/D the parent rule is +# "if D>N then (N, D-N) else (N-D, D)" +# +# So very easy using that rule twice (and why not go all the way up to +# the root while we're doing it). +# + +use strict; +use warnings; +use feature 'say'; +use Getopt::Long; +use Data::Dumper; +use Function::Parameters; + + +my $debug=0; + + +die "Usage: curious-fraction-tree-ancestors [--debug] N/D\n" unless + GetOptions( "debug"=>\$debug ) && @ARGV==1; +my $s = shift; + +die "cft: bad N/D string $s\n" unless $s =~ m|^(\d+)/(\d+)$|; +my( $n, $d ) = ( $1, $2 ); + +my $label = "parent"; + +while( $n>0 && $d>0 ) +{ + # change (n,d) to parent(n,d) + if( $d > $n ) + { + $d -= $n; + } else + { + $n -= $d; + } + say "$label: $n/$d" if $n>0 && $d>0; + $label = "grand$label"; +} -- cgit From 5d774188960c533ff59b4b9a42285b96f893f8c2 Mon Sep 17 00:00:00 2001 From: mohammad khalid anwar Date: Sun, 9 Jan 2022 03:34:07 +0530 Subject: 10001st Prime Number --- challenge-146/khalid-anwar/python/ch-1.py | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 challenge-146/khalid-anwar/python/ch-1.py diff --git a/challenge-146/khalid-anwar/python/ch-1.py b/challenge-146/khalid-anwar/python/ch-1.py new file mode 100644 index 0000000000..f5c05e61f5 --- /dev/null +++ b/challenge-146/khalid-anwar/python/ch-1.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +""" Returns the n-th prime number By Khalid Anwar +""" +def get_nth_prime_number(nth): + total_number_of_primes = 0 + factor = 2 + s = (nth * factor) + while total_number_of_primes < nth: + primes = make_prime(s) + total_number_of_primes = sum(primes[2:]) + factor += 1 + s = (nth * factor) + nth_prime_number = count_primes(primes, nth) + return nth_prime_number + +""" using the Sieve of Eratosthenes +""" +def make_prime(k): + prime = bytearray([1]*k) + for i in range(2, k): + if prime[i] == 1: + for j in range(i, k): + if i*j < k: + prime[i*j] = 0 + else: + break + return prime + +""" Returns the n-th prime +""" +def count_primes(primes, nth): + count = 0 + for k in range(2, len(primes)): + count += primes[k] + if count == nth: + return k + + +def main(): + NTH = 10001 + nth_prime_number = get_nth_prime_number(NTH) + print("The {}-th prime number is => {}".format(NTH, nth_prime_number)) + + +if __name__ == "__main__": + main() \ No newline at end of file -- cgit From fb0789c3ddec9b910e380206faf65c4510e2c39d Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Sat, 8 Jan 2022 12:45:20 -0800 Subject: prep for challenge New year, new template! --- challenge-146/tyler-wardhaugh/clojure/.gitignore | 22 +++++++++--- challenge-146/tyler-wardhaugh/clojure/LICENSE | 2 +- challenge-146/tyler-wardhaugh/clojure/README.md | 39 +++++++-------------- challenge-146/tyler-wardhaugh/clojure/bb.edn | 39 ++++++--------------- challenge-146/tyler-wardhaugh/clojure/build.clj | 19 ++++++++++ challenge-146/tyler-wardhaugh/clojure/deps.edn | 21 +++++------ challenge-146/tyler-wardhaugh/clojure/pom.xml | 44 ------------------------ 7 files changed, 71 insertions(+), 115 deletions(-) create mode 100644 challenge-146/tyler-wardhaugh/clojure/build.clj delete mode 100644 challenge-146/tyler-wardhaugh/clojure/pom.xml diff --git a/challenge-146/tyler-wardhaugh/clojure/.gitignore b/challenge-146/tyler-wardhaugh/clojure/.gitignore index 894239c8e8..ac8c2a1062 100644 --- a/challenge-146/tyler-wardhaugh/clojure/.gitignore +++ b/challenge-146/tyler-wardhaugh/clojure/.gitignore @@ -1,16 +1,28 @@ *.class *.jar +*.swp +*~ .*_history -.clj-kondo/ -.hg/ -.hgignore -.lsp/ -.projections.json +.sw* +.vscode +/.calva/output-window/ +/.classpath +/.clj-kondo/ /.cpcache/ +/.eastwood/ +/.factorypath +/.hg/ +/.hgignore +/.java-version /.lein-* /.lsp/ /.nrepl-history /.nrepl-port +/.project +/.projections.json +/.rebel_readline_history +/.settings +/.socket-repl-port /checkouts/ /classes/ /target/ diff --git a/challenge-146/tyler-wardhaugh/clojure/LICENSE b/challenge-146/tyler-wardhaugh/clojure/LICENSE index 7689f30efd..d921d3dffe 100644 --- a/challenge-146/tyler-wardhaugh/clojure/LICENSE +++ b/challenge-146/tyler-wardhaugh/clojure/LICENSE @@ -126,7 +126,7 @@ a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and -b) allow the Commercial Contributor tocontrol, and cooperate with the +b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. diff --git a/challenge-146/tyler-wardhaugh/clojure/README.md b/challenge-146/tyler-wardhaugh/clojure/README.md index 213f1884bc..4738867627 100644 --- a/challenge-146/tyler-wardhaugh/clojure/README.md +++ b/challenge-146/tyler-wardhaugh/clojure/README.md @@ -1,48 +1,35 @@ -# tw.weekly.c140 +# c146 - -The Weekly Challenge - #140 - Tyler Wardhaugh +The Weekly Challenge — #146 — Tyler Wardhaugh ## Usage Clojure ([installation instructions](https://clojure.org/guides/getting_started#_clojure_installer_and_cli_tools)) required for `clojure` commands; Babashka ([installation instructions](https://github.com/babashka/babashka#quickstart)) required for the `bb` commands. -Run the project directly (shows default output from both tasks): +Run Task #1: - $ clojure -M -m tw.weekly.c140.core + $ clojure -M:t1 # ... or ... - $ bb run both - -Run the project's tests (which are samples from the task descriptions): + $ bb run task-1 - $ clojure -X:test - # ... or ... - $ bb run test - -Run Task #1 with input +Run Task #2 with input: - $ clojure -M -m tw.weekly.c140.t1 A B + $ clojure -M:t2 M # ... or ... - $ bb run task-1 A B + $ bb run task-2 M -Run Task #2 with input: +Run the project's tests (which are samples from the task descriptions): - $ clojure -M -m tw.weekly.c140.t2 I J K + $ clojure -T:build test # ... or ... - $ bb run task-2 I J K + $ bb run test View available tasks Babashka can run: $ bb tasks -## Project Template - -I used Sean Corfield's clj-new to generate the project template - -See [seancorfield/clj-new: Generate new projects based on clj, Boot, or Leiningen Templates!](https://github.com/seancorfield/clj-new) for more information. - ## License -Copyright © 2021 Tyler Wardhaugh +Copyright © 2022 Tyler Wardhaugh -Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. +Distributed under the Eclipse Public License version 1.0. diff --git a/challenge-146/tyler-wardhaugh/clojure/bb.edn b/challenge-146/tyler-wardhaugh/clojure/bb.edn index e053ec5de1..e21cd63a1e 100644 --- a/challenge-146/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-146/tyler-wardhaugh/clojure/bb.edn @@ -16,15 +16,13 @@ (defn get-task-ns [task] - (let [glob-target (format "src/tw/weekly/*/%s.clj" (name task)) + (let [glob-target (format "src/*/%s.clj" (name task)) file (->> glob-target (fs/glob ".") first)] (-> file get-first-form second str))) - (defn run-task - ([task args] (run-task task args (get-task-ns task))) - ([task args task-ns] - (let [clj-options (format "-M -m %s " task-ns)] - (apply clojure clj-options args)))) + (defn run-task-clj + [task args] + (apply clojure (str "-M:" task) args)) (defn run-task-bb ([task args] (run-task-bb task args (get-task-ns task))) @@ -43,11 +41,9 @@ (System/exit 1))) clean {:doc "Clean out temporary files" - :task (run! fs/delete-tree - [".nrepl-port" ".cpcache" ".lsp" ".clj-kondo"])} - - generate-pom {:doc "Generate POM file" - :task (clojure "-X:deps mvn-pom")} + :task (do (clojure "-T:build" "clean") + (run! fs/delete-tree + [".nrepl-port" ".cpcache" ".lsp" ".clj-kondo"]))} generate-jar {:doc "Generate JAR file" :depends [generate-pom] @@ -68,35 +64,20 @@ p/check))} test {:doc "Run tests" - :task (clojure "-X:test")} + :task (clojure "-T:build test")} c**** {:doc "CHALLENGE TASKS"} task-1 {:doc "Run Task 1 (via clojure)" - :task (run-task :t1 *command-line-args*)} + :task (run-task-clj :t1 *command-line-args*)} task-1-bb {:doc "Run Task 1 (via Babashka)" :task (run-task-bb :t1 *command-line-args*)} task-2 {:doc "Run Task 2 (via clojure)" - :task (run-task :t2 *command-line-args*)} + :task (run-task-clj :t2 *command-line-args*)} task-2-bb {:doc "Run Task 2 (via Babashka)" :task (run-task-bb :t2 *command-line-args*)} - - both {:doc "Run both tasks (via clojure)" - :task (do - (println "Task 1:") - (run 'task-1) - (println "\nTask 2:") - (run 'task-2))} - - both-bb {:doc "Run both tasks (via Babashka)" - :task (do - (println "Task 1:") - (run 'task-1-bb) - (println "\nTask 2:") - (run 'task-2-bb))} - } } diff --git a/challenge-146/tyler-wardhaugh/clojure/build.clj b/challenge-146/tyler-wardhaugh/clojure/build.clj new file mode 100644 index 0000000000..8a78fbc09a --- /dev/null +++ b/challenge-146/tyler-wardhaugh/clojure/build.clj @@ -0,0 +1,19 @@ +(ns build + (:refer-clojure :exclude [test]) + (:require [org.corfield.build :as bb])) + +(def lib 'net.clojars.c146/c146) +(def version "0.1.0-SNAPSHOT") +(def main 'c146.c146) + +(defn test "Run the tests." [opts] + (bb/run-tests opts)) + +(def clean bb/clean) + +(defn ci "Run the CI pipeline of tests (and build the uberjar)." [opts] + (-> opts + (assoc :lib lib :version version :main main) + (bb/run-tests) + (bb/clean) + (bb/uber))) diff --git a/challenge-146/tyler-wardhaugh/clojure/deps.edn b/challenge-146/tyler-wardhaugh/clojure/deps.edn index 5b1400b27e..16a95bc2f6 100644 --- a/challenge-146/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-146/tyler-wardhaugh/clojure/deps.edn @@ -1,14 +1,15 @@ {:paths ["src" "resources"] :deps {org.clojure/clojure {:mvn/version "1.10.3"}} :aliases - {:test {:extra-paths ["test"] - :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"} + {:t1 {:main-opts ["-m" "c146.t1"]} + :t2 {:main-opts ["-m" "c146.t2"]} + :build {:deps {io.github.seancorfield/build-clj + {:git/tag "v0.6.3" :git/sha "9b8e09b" + ;; since we're building an app uberjar, we do not + ;; need deps-deploy for clojars.org deployment: + :deps/root "slim"}} + :ns-default build} + :test {:extra-paths ["test"] + :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"} io.github.cognitect-labs/test-runner - {:git/url "https://github.com/cognitect-labs/test-runner" - :sha "62ef1de18e076903374306060ac0e8a752e57c86"}} - :exec-fn cognitect.test-runner.api/test} - :jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.278"}} - :exec-fn hf.depstar/uberjar - :exec-args {:aot true - :jar "tw-weekly.jar" - :sync-pom true}}}} + {:git/tag "v0.5.0" :git/sha "48c3c67"}}}}} diff --git a/challenge-146/tyler-wardhaugh/clojure/pom.xml b/challenge-146/tyler-wardhaugh/clojure/pom.xml deleted file mode 100644 index e51de32ab2..0000000000 --- a/challenge-146/tyler-wardhaugh/clojure/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - 4.0.0 - tw.weekly - tw.weekly.c140 - 0.1.0-SNAPSHOT - tw.weekly.c140 - Challenge #140 - https://github.com/tw.weekly/tw.weekly.c140 - - - Eclipse Public License - http://www.eclipse.org/legal/epl-v10.html - - - - - Tyler Wardhaugh - - - - - org.clojure - clojure - 1.10.3 - - - - src - - - - clojars - https://repo.clojars.org/ - - - - - clojars - Clojars repository - https://clojars.org/repo - - - -- cgit From fb357b920a95257266a0063ad44d0480b66fbff2 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Sat, 8 Jan 2022 12:40:06 -0800 Subject: Ch146 (Clojure): Task 1 --- challenge-146/tyler-wardhaugh/clojure/src/c146/t1.clj | 17 +++++++++++++++++ challenge-146/tyler-wardhaugh/clojure/src/c146/t1b.clj | 11 +++++++++++ .../tyler-wardhaugh/clojure/test/c146/t1_test.clj | 8 ++++++++ 3 files changed, 36 insertions(+) create mode 100644 challenge-146/tyler-wardhaugh/clojure/src/c146/t1.clj create mode 100644 challenge-146/tyler-wardhaugh/clojure/src/c146/t1b.clj create mode 100644 challenge-146/tyler-wardhaugh/clojure/test/c146/t1_test.clj diff --git a/challenge-146/tyler-wardhaugh/clojure/src/c146/t1.clj b/challenge-146/tyler-wardhaugh/clojure/src/c146/t1.clj new file mode 100644 index 0000000000..f7e965c92b --- /dev/null +++ b/challenge-146/tyler-wardhaugh/clojure/src/c146/t1.clj @@ -0,0 +1,17 @@ +(ns c146.t1) + +(def TARGET 10001) + +(defn nth-prime + [n] + (let [p (promise) + sieve (fn [n] + (not-any? #(zero? (rem n %)) + (take-while #(<= (* % %) n) @p)))] + (->> @(deliver p (filter sieve (iterate inc 2))) + (drop (dec n)) + first))) + +(defn -main + [& _] + (println (nth-prime TARGET))) diff --git a/challenge-146/tyler-wardhaugh/clojure/src/c146/t1b.clj b/challenge-146/tyler-wardhaugh/clojure/src/c