From deacba787f3ddafc108c92ac97f9cd53c589ff73 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 22 Jul 2019 01:42:33 +0100 Subject: - Added template for Challenge 018. --- challenge-018/abigail/README | 1 + challenge-018/adam-russell/README | 1 + challenge-018/ailbhe-tweedie/README | 1 + challenge-018/alex-daniel/README | 1 + challenge-018/alexander-karelas/README | 1 + challenge-018/alexey-melezhik/README | 1 + challenge-018/alicia-bielsa/README | 1 + challenge-018/andrezgz/README | 1 + challenge-018/antonio-gamiz/README | 1 + challenge-018/arne-sommer/README | 1 + challenge-018/arpad-toth/README | 1 + challenge-018/athanasius/README | 1 + challenge-018/aubrey-quarcoo/README | 1 + challenge-018/bill-palmer/README | 1 + challenge-018/bob-kleemann/README | 1 + challenge-018/cliveholloway/README | 1 + challenge-018/daniel-mantovani/README | 1 + challenge-018/daniel-mita/README | 1 + challenge-018/dave-cross/README | 1 + challenge-018/dave-jacoby/README | 1 + challenge-018/david-kayal/README | 1 + challenge-018/denis-yurashku/README | 1 + challenge-018/donald-hunter/README | 1 + challenge-018/doug-schrag/README | 1 + challenge-018/duane-powell/README | 1 + challenge-018/duncan-c-white/README | 43 ++++++++++++++++++++++++++++ challenge-018/e-choroba/README | 1 + challenge-018/eddy-hs/README | 1 + challenge-018/feng-chang/README | 1 + challenge-018/finley/README | 1 + challenge-018/fjwhittle/README | 1 + challenge-018/fred-zinn/README | 1 + challenge-018/freddie-b/README | 1 + challenge-018/guillermo-ramos/README | 1 + challenge-018/gustavo-chaves/README | 1 + challenge-018/jacques-guinnebault/README | 1 + challenge-018/jaime/README | 15 ++++++++++ challenge-018/jaldhar-h-vyas/README | 1 + challenge-018/jeff/README | 1 + challenge-018/jeremy-carman/README | 1 + challenge-018/jim-bacon/README | 1 + challenge-018/jj-merelo/README | 1 + challenge-018/jo-christian-oterhals/README | 1 + challenge-018/joe-tym/README | 1 + challenge-018/joelle-maslak/README | 1 + challenge-018/joelle-maslak/perl5/.gitignore | 1 + challenge-018/john-barrett/README | 1 + challenge-018/juan-caballero/README | 1 + challenge-018/kevin-colyer/README | 1 + challenge-018/khalid/README | 1 + challenge-018/kian-meng-ang/README | 1 + challenge-018/kivanc-yazan/README | 1 + challenge-018/lars-balker/README | 1 + challenge-018/laurent-rosenfeld/README | 1 + challenge-018/lubos-kolouch/README | 1 + challenge-018/magnus-woldrich/README | 1 + challenge-018/mano-chandar/README | 1 + challenge-018/mark-senn/README | 1 + challenge-018/martin-barth/README | 1 + challenge-018/martin-mugeni/README | 1 + challenge-018/matt-latusek/README | 1 + challenge-018/matthew-persico/README | 1 + challenge-018/maxim-kolodyazhny/README | 1 + challenge-018/maxim-nechaev/README | 1 + challenge-018/michael-hamlin/README | 5 ++++ challenge-018/michael-schaap/README | 1 + challenge-018/neil-bowers/README | 1 + challenge-018/nick-logan/README | 1 + challenge-018/nikhil-prasanna/README | 1 + challenge-018/noud/README | 1 + challenge-018/ohmycloud/README | 1 + challenge-018/oleksii-tsvietnov/README | 1 + challenge-018/ozzy/README | 1 + challenge-018/pavel-jurca/README | 1 + challenge-018/pavel-starikov/README | 1 + challenge-018/pete-houston/README | 1 + challenge-018/pete-sergeant/README | 1 + challenge-018/philippe-bruhat/README | 1 + challenge-018/prajith-p/README | 1 + challenge-018/randy-lauen/README | 1 + challenge-018/rob-van-dam/README | 1 + challenge-018/rob4t/README | 1 + challenge-018/roger-bell-west/README | 1 + challenge-018/ruben-westerberg/README | 12 ++++++++ challenge-018/sean-meininger/README | 1 + challenge-018/sergiotarxz/README | 1 + challenge-018/shardiwal/README | 1 + challenge-018/shaun-pearce/README | 1 + challenge-018/simon-miner/README | 1 + challenge-018/simon-proctor/README | 1 + challenge-018/simon-reinhardt/README | 1 + challenge-018/steve-rogerson/README | 1 + challenge-018/steven-lembark/README | 1 + challenge-018/steven-wilson/README | 1 + challenge-018/tiago-stock/README | 1 + challenge-018/tim-smith/README | 1 + challenge-018/tore-andersson/README | 1 + challenge-018/uzluisf/README | 1 + challenge-018/veesh-goldman/README | 1 + challenge-018/walt-mankowski/README | 1 + challenge-018/william-gilmore/README | 1 + challenge-018/yary-h/README | 1 + challenge-018/yozen-hernandez/README | 1 + 103 files changed, 174 insertions(+) create mode 100644 challenge-018/abigail/README create mode 100644 challenge-018/adam-russell/README create mode 100644 challenge-018/ailbhe-tweedie/README create mode 100644 challenge-018/alex-daniel/README create mode 100644 challenge-018/alexander-karelas/README create mode 100644 challenge-018/alexey-melezhik/README create mode 100644 challenge-018/alicia-bielsa/README create mode 100644 challenge-018/andrezgz/README create mode 100644 challenge-018/antonio-gamiz/README create mode 100644 challenge-018/arne-sommer/README create mode 100644 challenge-018/arpad-toth/README create mode 100644 challenge-018/athanasius/README create mode 100644 challenge-018/aubrey-quarcoo/README create mode 100644 challenge-018/bill-palmer/README create mode 100644 challenge-018/bob-kleemann/README create mode 100644 challenge-018/cliveholloway/README create mode 100644 challenge-018/daniel-mantovani/README create mode 100644 challenge-018/daniel-mita/README create mode 100644 challenge-018/dave-cross/README create mode 100644 challenge-018/dave-jacoby/README create mode 100644 challenge-018/david-kayal/README create mode 100644 challenge-018/denis-yurashku/README create mode 100644 challenge-018/donald-hunter/README create mode 100644 challenge-018/doug-schrag/README create mode 100644 challenge-018/duane-powell/README create mode 100644 challenge-018/duncan-c-white/README create mode 100644 challenge-018/e-choroba/README create mode 100644 challenge-018/eddy-hs/README create mode 100644 challenge-018/feng-chang/README create mode 100644 challenge-018/finley/README create mode 100644 challenge-018/fjwhittle/README create mode 100644 challenge-018/fred-zinn/README create mode 100644 challenge-018/freddie-b/README create mode 100644 challenge-018/guillermo-ramos/README create mode 100644 challenge-018/gustavo-chaves/README create mode 100644 challenge-018/jacques-guinnebault/README create mode 100644 challenge-018/jaime/README create mode 100644 challenge-018/jaldhar-h-vyas/README create mode 100644 challenge-018/jeff/README create mode 100644 challenge-018/jeremy-carman/README create mode 100644 challenge-018/jim-bacon/README create mode 100644 challenge-018/jj-merelo/README create mode 100644 challenge-018/jo-christian-oterhals/README create mode 100644 challenge-018/joe-tym/README create mode 100644 challenge-018/joelle-maslak/README create mode 100644 challenge-018/joelle-maslak/perl5/.gitignore create mode 100644 challenge-018/john-barrett/README create mode 100644 challenge-018/juan-caballero/README create mode 100644 challenge-018/kevin-colyer/README create mode 100644 challenge-018/khalid/README create mode 100644 challenge-018/kian-meng-ang/README create mode 100644 challenge-018/kivanc-yazan/README create mode 100644 challenge-018/lars-balker/README create mode 100644 challenge-018/laurent-rosenfeld/README create mode 100644 challenge-018/lubos-kolouch/README create mode 100644 challenge-018/magnus-woldrich/README create mode 100644 challenge-018/mano-chandar/README create mode 100644 challenge-018/mark-senn/README create mode 100644 challenge-018/martin-barth/README create mode 100644 challenge-018/martin-mugeni/README create mode 100644 challenge-018/matt-latusek/README create mode 100644 challenge-018/matthew-persico/README create mode 100644 challenge-018/maxim-kolodyazhny/README create mode 100644 challenge-018/maxim-nechaev/README create mode 100644 challenge-018/michael-hamlin/README create mode 100644 challenge-018/michael-schaap/README create mode 100644 challenge-018/neil-bowers/README create mode 100644 challenge-018/nick-logan/README create mode 100644 challenge-018/nikhil-prasanna/README create mode 100644 challenge-018/noud/README create mode 100644 challenge-018/ohmycloud/README create mode 100644 challenge-018/oleksii-tsvietnov/README create mode 100644 challenge-018/ozzy/README create mode 100644 challenge-018/pavel-jurca/README create mode 100644 challenge-018/pavel-starikov/README create mode 100644 challenge-018/pete-houston/README create mode 100644 challenge-018/pete-sergeant/README create mode 100644 challenge-018/philippe-bruhat/README create mode 100644 challenge-018/prajith-p/README create mode 100644 challenge-018/randy-lauen/README create mode 100644 challenge-018/rob-van-dam/README create mode 100644 challenge-018/rob4t/README create mode 100644 challenge-018/roger-bell-west/README create mode 100644 challenge-018/ruben-westerberg/README create mode 100644 challenge-018/sean-meininger/README create mode 100644 challenge-018/sergiotarxz/README create mode 100644 challenge-018/shardiwal/README create mode 100644 challenge-018/shaun-pearce/README create mode 100644 challenge-018/simon-miner/README create mode 100644 challenge-018/simon-proctor/README create mode 100644 challenge-018/simon-reinhardt/README create mode 100644 challenge-018/steve-rogerson/README create mode 100644 challenge-018/steven-lembark/README create mode 100644 challenge-018/steven-wilson/README create mode 100644 challenge-018/tiago-stock/README create mode 100644 challenge-018/tim-smith/README create mode 100644 challenge-018/tore-andersson/README create mode 100644 challenge-018/uzluisf/README create mode 100644 challenge-018/veesh-goldman/README create mode 100644 challenge-018/walt-mankowski/README create mode 100644 challenge-018/william-gilmore/README create mode 100644 challenge-018/yary-h/README create mode 100644 challenge-018/yozen-hernandez/README (limited to 'challenge-018') diff --git a/challenge-018/abigail/README b/challenge-018/abigail/README new file mode 100644 index 0000000000..5f0d73ae16 --- /dev/null +++ b/challenge-018/abigail/README @@ -0,0 +1 @@ +Solution by Abigail diff --git a/challenge-018/adam-russell/README b/challenge-018/adam-russell/README new file mode 100644 index 0000000000..9420c9a781 --- /dev/null +++ b/challenge-018/adam-russell/README @@ -0,0 +1 @@ +Solution by Adam Russell diff --git a/challenge-018/ailbhe-tweedie/README b/challenge-018/ailbhe-tweedie/README new file mode 100644 index 0000000000..36d4034b70 --- /dev/null +++ b/challenge-018/ailbhe-tweedie/README @@ -0,0 +1 @@ +Solution by Ailbhe Tweedie diff --git a/challenge-018/alex-daniel/README b/challenge-018/alex-daniel/README new file mode 100644 index 0000000000..65550789bd --- /dev/null +++ b/challenge-018/alex-daniel/README @@ -0,0 +1 @@ +Solution by Alex Daniel. diff --git a/challenge-018/alexander-karelas/README b/challenge-018/alexander-karelas/README new file mode 100644 index 0000000000..3de9fce8d9 --- /dev/null +++ b/challenge-018/alexander-karelas/README @@ -0,0 +1 @@ +Solution by Alexander Karelas diff --git a/challenge-018/alexey-melezhik/README b/challenge-018/alexey-melezhik/README new file mode 100644 index 0000000000..ca7008f224 --- /dev/null +++ b/challenge-018/alexey-melezhik/README @@ -0,0 +1 @@ +Solution by Alexey Melezhik diff --git a/challenge-018/alicia-bielsa/README b/challenge-018/alicia-bielsa/README new file mode 100644 index 0000000000..c5187874c3 --- /dev/null +++ b/challenge-018/alicia-bielsa/README @@ -0,0 +1 @@ +Solution by Alicia Beilsa. diff --git a/challenge-018/andrezgz/README b/challenge-018/andrezgz/README new file mode 100644 index 0000000000..f4fd0da88e --- /dev/null +++ b/challenge-018/andrezgz/README @@ -0,0 +1 @@ +Solution by Andrezgz diff --git a/challenge-018/antonio-gamiz/README b/challenge-018/antonio-gamiz/README new file mode 100644 index 0000000000..1f5ed5871a --- /dev/null +++ b/challenge-018/antonio-gamiz/README @@ -0,0 +1 @@ +Solution by Antonio Gamiz diff --git a/challenge-018/arne-sommer/README b/challenge-018/arne-sommer/README new file mode 100644 index 0000000000..b5d88e4df4 --- /dev/null +++ b/challenge-018/arne-sommer/README @@ -0,0 +1 @@ +Solution by Arne Sommer. diff --git a/challenge-018/arpad-toth/README b/challenge-018/arpad-toth/README new file mode 100644 index 0000000000..6661dd82c1 --- /dev/null +++ b/challenge-018/arpad-toth/README @@ -0,0 +1 @@ +Solution by Arpad Toth diff --git a/challenge-018/athanasius/README b/challenge-018/athanasius/README new file mode 100644 index 0000000000..cc357fda4a --- /dev/null +++ b/challenge-018/athanasius/README @@ -0,0 +1 @@ +Solution by Athanasius diff --git a/challenge-018/aubrey-quarcoo/README b/challenge-018/aubrey-quarcoo/README new file mode 100644 index 0000000000..8e63a2c1f5 --- /dev/null +++ b/challenge-018/aubrey-quarcoo/README @@ -0,0 +1 @@ +Solution by Aubrey Quarcoo diff --git a/challenge-018/bill-palmer/README b/challenge-018/bill-palmer/README new file mode 100644 index 0000000000..08ec849a41 --- /dev/null +++ b/challenge-018/bill-palmer/README @@ -0,0 +1 @@ +Solution by Bill Palmer. diff --git a/challenge-018/bob-kleemann/README b/challenge-018/bob-kleemann/README new file mode 100644 index 0000000000..78680e4035 --- /dev/null +++ b/challenge-018/bob-kleemann/README @@ -0,0 +1 @@ +Solution by Bob Kleemann diff --git a/challenge-018/cliveholloway/README b/challenge-018/cliveholloway/README new file mode 100644 index 0000000000..b69201296e --- /dev/null +++ b/challenge-018/cliveholloway/README @@ -0,0 +1 @@ +Solution by Clive Holloway diff --git a/challenge-018/daniel-mantovani/README b/challenge-018/daniel-mantovani/README new file mode 100644 index 0000000000..ed538216f2 --- /dev/null +++ b/challenge-018/daniel-mantovani/README @@ -0,0 +1 @@ +Solution by Daniel Mantovani diff --git a/challenge-018/daniel-mita/README b/challenge-018/daniel-mita/README new file mode 100644 index 0000000000..37339f491f --- /dev/null +++ b/challenge-018/daniel-mita/README @@ -0,0 +1 @@ +Solution by Daniel Mita diff --git a/challenge-018/dave-cross/README b/challenge-018/dave-cross/README new file mode 100644 index 0000000000..04b1b0623b --- /dev/null +++ b/challenge-018/dave-cross/README @@ -0,0 +1 @@ +Solution by Dave Cross diff --git a/challenge-018/dave-jacoby/README b/challenge-018/dave-jacoby/README new file mode 100644 index 0000000000..7c06689f16 --- /dev/null +++ b/challenge-018/dave-jacoby/README @@ -0,0 +1 @@ +Solution by Dave Jacoby diff --git a/challenge-018/david-kayal/README b/challenge-018/david-kayal/README new file mode 100644 index 0000000000..66f8615260 --- /dev/null +++ b/challenge-018/david-kayal/README @@ -0,0 +1 @@ +Solution by David Kayal diff --git a/challenge-018/denis-yurashku/README b/challenge-018/denis-yurashku/README new file mode 100644 index 0000000000..2fea994000 --- /dev/null +++ b/challenge-018/denis-yurashku/README @@ -0,0 +1 @@ +Solutions by Denis Yurashku. diff --git a/challenge-018/donald-hunter/README b/challenge-018/donald-hunter/README new file mode 100644 index 0000000000..2eef878f17 --- /dev/null +++ b/challenge-018/donald-hunter/README @@ -0,0 +1 @@ +Solutions by Donald Hunter. diff --git a/challenge-018/doug-schrag/README b/challenge-018/doug-schrag/README new file mode 100644 index 0000000000..bf8a10ffb4 --- /dev/null +++ b/challenge-018/doug-schrag/README @@ -0,0 +1 @@ +Solution by Doug Schrag diff --git a/challenge-018/duane-powell/README b/challenge-018/duane-powell/README new file mode 100644 index 0000000000..3445422743 --- /dev/null +++ b/challenge-018/duane-powell/README @@ -0,0 +1 @@ +Solutions by Duane Powell. diff --git a/challenge-018/duncan-c-white/README b/challenge-018/duncan-c-white/README new file mode 100644 index 0000000000..37c8c6c8c7 --- /dev/null +++ b/challenge-018/duncan-c-white/README @@ -0,0 +1,43 @@ +Challenge 1: "Create a script to demonstrate Ackermann function. The +Ackermann function is defined as below, m and n are positive number: + + A(m, n) = n + 1 if m = 0 + A(m, n) = A(m - 1, 1) if m > 0 and n = 0 + A(m, n) = A(m - 1, A(m, n - 1)) if m > 0 and n > 0 + +eg. A(1, 2) = A(0, A(1, 1)) + = A(0, A(0, A(1, 0))) + = A(0, A(0, A(0, 1))) + = A(0, A(0, 2)) + = A(0, 3) + = 4 +" + +My notes: + +Clearly described. I seem to recall that the Ackermann function is +tremendously inefficient to calculate recursively, but that memoization +really helps. So, before writing a line of code, I think "use Memoize" +is going to help.. + + +Challenge 2: "Create a script to parse URL and print the components of +URL. According to the Wiki page https://en.wikipedia.org/wiki/URL, the URL +syntax is as below: + + scheme:[//[userinfo@]host[:port]]path[?query][#fragment] + +eg. jdbc://user:password@localhost:3306/pwc?profile=true#h1 + + scheme: jdbc + userinfo: user:password + host: localhost + port: 3306 + path: /pwc + query: profile=true + fragment: h1 + +My notes: sounds pretty trivial for regexes, if the lexical syntax of +each component is defined clearly. Ok, reading the above wiki page +doesn't make it 100% clear, but let's hack it up, that's probably good +enough for most cases. diff --git a/challenge-018/e-choroba/README b/challenge-018/e-choroba/README new file mode 100644 index 0000000000..efff637bcb --- /dev/null +++ b/challenge-018/e-choroba/README @@ -0,0 +1 @@ +Solutions by E. Choroba. diff --git a/challenge-018/eddy-hs/README b/challenge-018/eddy-hs/README new file mode 100644 index 0000000000..0ed51d222d --- /dev/null +++ b/challenge-018/eddy-hs/README @@ -0,0 +1 @@ +Solution by Eddy HS diff --git a/challenge-018/feng-chang/README b/challenge-018/feng-chang/README new file mode 100644 index 0000000000..74e56de3ed --- /dev/null +++ b/challenge-018/feng-chang/README @@ -0,0 +1 @@ +Solutions by Feng Chang. diff --git a/challenge-018/finley/README b/challenge-018/finley/README new file mode 100644 index 0000000000..f08a121076 --- /dev/null +++ b/challenge-018/finley/README @@ -0,0 +1 @@ +Solution by Finley diff --git a/challenge-018/fjwhittle/README b/challenge-018/fjwhittle/README new file mode 100644 index 0000000000..7dcc95e189 --- /dev/null +++ b/challenge-018/fjwhittle/README @@ -0,0 +1 @@ +Solution by Francis Whittle diff --git a/challenge-018/fred-zinn/README b/challenge-018/fred-zinn/README new file mode 100644 index 0000000000..17bac4f094 --- /dev/null +++ b/challenge-018/fred-zinn/README @@ -0,0 +1 @@ +Solution by Fred Zinn diff --git a/challenge-018/freddie-b/README b/challenge-018/freddie-b/README new file mode 100644 index 0000000000..823d7474b5 --- /dev/null +++ b/challenge-018/freddie-b/README @@ -0,0 +1 @@ +Solution by Freddie B diff --git a/challenge-018/guillermo-ramos/README b/challenge-018/guillermo-ramos/README new file mode 100644 index 0000000000..a39eb01bff --- /dev/null +++ b/challenge-018/guillermo-ramos/README @@ -0,0 +1 @@ +Solution by Guillermo Ramos. diff --git a/challenge-018/gustavo-chaves/README b/challenge-018/gustavo-chaves/README new file mode 100644 index 0000000000..a66bbbf8a3 --- /dev/null +++ b/challenge-018/gustavo-chaves/README @@ -0,0 +1 @@ +Solution by Gustavo Chaves diff --git a/challenge-018/jacques-guinnebault/README b/challenge-018/jacques-guinnebault/README new file mode 100644 index 0000000000..9d3e7c037f --- /dev/null +++ b/challenge-018/jacques-guinnebault/README @@ -0,0 +1 @@ +Solution by Jacques Guinnebault. diff --git a/challenge-018/jaime/README b/challenge-018/jaime/README new file mode 100644 index 0000000000..9acbfee5ea --- /dev/null +++ b/challenge-018/jaime/README @@ -0,0 +1,15 @@ +Solution by Jaime Corchado, (@tortsnare)[https://twitter.com/tortsnare]. + +# Challenge #1 + +Write a script to generate Van Eck’s sequence. + +# Challenge #2 + +Using only the official postal (2-letter) abbreviations for the 50 U.S. states, +write a script to find the longest English word you can spell. + +# Challenge #3 + +Find the given city current time using the Geo DB Cities API. + diff --git a/challenge-018/jaldhar-h-vyas/README b/challenge-018/jaldhar-h-vyas/README new file mode 100644 index 0000000000..7dce927eca --- /dev/null +++ b/challenge-018/jaldhar-h-vyas/README @@ -0,0 +1 @@ +Solution by Jaldhar H. Vyas diff --git a/challenge-018/jeff/README b/challenge-018/jeff/README new file mode 100644 index 0000000000..d5f15f4a8e --- /dev/null +++ b/challenge-018/jeff/README @@ -0,0 +1 @@ +Solution by Jeff diff --git a/challenge-018/jeremy-carman/README b/challenge-018/jeremy-carman/README new file mode 100644 index 0000000000..3d08510e49 --- /dev/null +++ b/challenge-018/jeremy-carman/README @@ -0,0 +1 @@ +Solution by Jeremy Carman diff --git a/challenge-018/jim-bacon/README b/challenge-018/jim-bacon/README new file mode 100644 index 0000000000..8dcfd637a3 --- /dev/null +++ b/challenge-018/jim-bacon/README @@ -0,0 +1 @@ +Solution by Jim Bacon diff --git a/challenge-018/jj-merelo/README b/challenge-018/jj-merelo/README new file mode 100644 index 0000000000..d09838676b --- /dev/null +++ b/challenge-018/jj-merelo/README @@ -0,0 +1 @@ +Solution by JJ Merelo diff --git a/challenge-018/jo-christian-oterhals/README b/challenge-018/jo-christian-oterhals/README new file mode 100644 index 0000000000..eafff999fb --- /dev/null +++ b/challenge-018/jo-christian-oterhals/README @@ -0,0 +1 @@ +Solution by Jo Christian Oterhals diff --git a/challenge-018/joe-tym/README b/challenge-018/joe-tym/README new file mode 100644 index 0000000000..4e2d1b704f --- /dev/null +++ b/challenge-018/joe-tym/README @@ -0,0 +1 @@ +Solutions by Joe Tym. diff --git a/challenge-018/joelle-maslak/README b/challenge-018/joelle-maslak/README new file mode 100644 index 0000000000..d12c7940c3 --- /dev/null +++ b/challenge-018/joelle-maslak/README @@ -0,0 +1 @@ +Solution by Joelle Maslak diff --git a/challenge-018/joelle-maslak/perl5/.gitignore b/challenge-018/joelle-maslak/perl5/.gitignore new file mode 100644 index 0000000000..714f73c541 --- /dev/null +++ b/challenge-018/joelle-maslak/perl5/.gitignore @@ -0,0 +1 @@ +_Inline diff --git a/challenge-018/john-barrett/README b/challenge-018/john-barrett/README new file mode 100644 index 0000000000..a7ff0af641 --- /dev/null +++ b/challenge-018/john-barrett/README @@ -0,0 +1 @@ +Solution by John Barrett diff --git a/challenge-018/juan-caballero/README b/challenge-018/juan-caballero/README new file mode 100644 index 0000000000..bffe4b05c2 --- /dev/null +++ b/challenge-018/juan-caballero/README @@ -0,0 +1 @@ +Solution by Juan Caballero diff --git a/challenge-018/kevin-colyer/README b/challenge-018/kevin-colyer/README new file mode 100644 index 0000000000..32aa940083 --- /dev/null +++ b/challenge-018/kevin-colyer/README @@ -0,0 +1 @@ +Solutions by Kevin Colyer. diff --git a/challenge-018/khalid/README b/challenge-018/khalid/README new file mode 100644 index 0000000000..1ca4211368 --- /dev/null +++ b/challenge-018/khalid/README @@ -0,0 +1 @@ +Solution by Khalid diff --git a/challenge-018/kian-meng-ang/README b/challenge-018/kian-meng-ang/README new file mode 100644 index 0000000000..a5f0359813 --- /dev/null +++ b/challenge-018/kian-meng-ang/README @@ -0,0 +1 @@ +Solution by Kian-Meng Ang diff --git a/challenge-018/kivanc-yazan/README b/challenge-018/kivanc-yazan/README new file mode 100644 index 0000000000..bc7f8ca509 --- /dev/null +++ b/challenge-018/kivanc-yazan/README @@ -0,0 +1 @@ +Solution by Kivanc Yazan diff --git a/challenge-018/lars-balker/README b/challenge-018/lars-balker/README new file mode 100644 index 0000000000..054649c9eb --- /dev/null +++ b/challenge-018/lars-balker/README @@ -0,0 +1 @@ +Solution by Lars Balker diff --git a/challenge-018/laurent-rosenfeld/README b/challenge-018/laurent-rosenfeld/README new file mode 100644 index 0000000000..f9c6e1437e --- /dev/null +++ b/challenge-018/laurent-rosenfeld/README @@ -0,0 +1 @@ +Solution by Laurent Rosenfeld diff --git a/challenge-018/lubos-kolouch/README b/challenge-018/lubos-kolouch/README new file mode 100644 index 0000000000..921b2d9f4a --- /dev/null +++ b/challenge-018/lubos-kolouch/README @@ -0,0 +1 @@ +Solutions by Lubos Kolouch. diff --git a/challenge-018/magnus-woldrich/README b/challenge-018/magnus-woldrich/README new file mode 100644 index 0000000000..79cde2997c --- /dev/null +++ b/challenge-018/magnus-woldrich/README @@ -0,0 +1 @@ +Solution by Magnus Woldrich diff --git a/challenge-018/mano-chandar/README b/challenge-018/mano-chandar/README new file mode 100644 index 0000000000..2ec028460a --- /dev/null +++ b/challenge-018/mano-chandar/README @@ -0,0 +1 @@ +Solutions by Mano Chandar. diff --git a/challenge-018/mark-senn/README b/challenge-018/mark-senn/README new file mode 100644 index 0000000000..f37c93431c --- /dev/null +++ b/challenge-018/mark-senn/README @@ -0,0 +1 @@ +Solution by Mark Senn diff --git a/challenge-018/martin-barth/README b/challenge-018/martin-barth/README new file mode 100644 index 0000000000..13c469f3c3 --- /dev/null +++ b/challenge-018/martin-barth/README @@ -0,0 +1 @@ +Solutions by Martin Barth. diff --git a/challenge-018/martin-mugeni/README b/challenge-018/martin-mugeni/README new file mode 100644 index 0000000000..416ca98166 --- /dev/null +++ b/challenge-018/martin-mugeni/README @@ -0,0 +1 @@ +Solution by Martin Mugeni diff --git a/challenge-018/matt-latusek/README b/challenge-018/matt-latusek/README new file mode 100644 index 0000000000..e1dc8b6e16 --- /dev/null +++ b/challenge-018/matt-latusek/README @@ -0,0 +1 @@ +Solution by Matt Latusek. diff --git a/challenge-018/matthew-persico/README b/challenge-018/matthew-persico/README new file mode 100644 index 0000000000..5aa5622296 --- /dev/null +++ b/challenge-018/matthew-persico/README @@ -0,0 +1 @@ +Solutions by Matthew O. Persico. diff --git a/challenge-018/maxim-kolodyazhny/README b/challenge-018/maxim-kolodyazhny/README new file mode 100644 index 0000000000..e5b4df7154 --- /dev/null +++ b/challenge-018/maxim-kolodyazhny/README @@ -0,0 +1 @@ +Solution by Maxim Kolodyazhny diff --git a/challenge-018/maxim-nechaev/README b/challenge-018/maxim-nechaev/README new file mode 100644 index 0000000000..0695cbfa4d --- /dev/null +++ b/challenge-018/maxim-nechaev/README @@ -0,0 +1 @@ +Solutions by Maxim Nechaev. diff --git a/challenge-018/michael-hamlin/README b/challenge-018/michael-hamlin/README new file mode 100644 index 0000000000..3c1a735306 --- /dev/null +++ b/challenge-018/michael-hamlin/README @@ -0,0 +1,5 @@ +Solutions by Michael Hamlin. + +ch-1.pl the Ackermann function grows so rapidly that I dont think I can +test the real hyperness of my code, even with GMP. + diff --git a/challenge-018/michael-schaap/README b/challenge-018/michael-schaap/README new file mode 100644 index 0000000000..db803c5d87 --- /dev/null +++ b/challenge-018/michael-schaap/README @@ -0,0 +1 @@ +Solution by Michael Schaap diff --git a/challenge-018/neil-bowers/README b/challenge-018/neil-bowers/README new file mode 100644 index 0000000000..9d446303df --- /dev/null +++ b/challenge-018/neil-bowers/README @@ -0,0 +1 @@ +Solution by Neil Bowers diff --git a/challenge-018/nick-logan/README b/challenge-018/nick-logan/README new file mode 100644 index 0000000000..86919ac8b8 --- /dev/null +++ b/challenge-018/nick-logan/README @@ -0,0 +1 @@ +Solution by Nick Logan diff --git a/challenge-018/nikhil-prasanna/README b/challenge-018/nikhil-prasanna/README new file mode 100644 index 0000000000..7c28d1a844 --- /dev/null +++ b/challenge-018/nikhil-prasanna/README @@ -0,0 +1 @@ +Solution by Nikhil Prasanna. diff --git a/challenge-018/noud/README b/challenge-018/noud/README new file mode 100644 index 0000000000..0b0970d708 --- /dev/null +++ b/challenge-018/noud/README @@ -0,0 +1 @@ +Solution by Noud diff --git a/challenge-018/ohmycloud/README b/challenge-018/ohmycloud/README new file mode 100644 index 0000000000..e993fafea7 --- /dev/null +++ b/challenge-018/ohmycloud/README @@ -0,0 +1 @@ +Solution by Ohmycloud diff --git a/challenge-018/oleksii-tsvietnov/README b/challenge-018/oleksii-tsvietnov/README new file mode 100644 index 0000000000..113183cc6d --- /dev/null +++ b/challenge-018/oleksii-tsvietnov/README @@ -0,0 +1 @@ +Solution by Oleksii Tsvietnov diff --git a/challenge-018/ozzy/README b/challenge-018/ozzy/README new file mode 100644 index 0000000000..44e39371ef --- /dev/null +++ b/challenge-018/ozzy/README @@ -0,0 +1 @@ +Solution by Ozzy diff --git a/challenge-018/pavel-jurca/README b/challenge-018/pavel-jurca/README new file mode 100644 index 0000000000..78d131bd34 --- /dev/null +++ b/challenge-018/pavel-jurca/README @@ -0,0 +1 @@ +Solution by Pavel Jurca diff --git a/challenge-018/pavel-starikov/README b/challenge-018/pavel-starikov/README new file mode 100644 index 0000000000..67ed468ff0 --- /dev/null +++ b/challenge-018/pavel-starikov/README @@ -0,0 +1 @@ +Solutions by Pavel Starikov. diff --git a/challenge-018/pete-houston/README b/challenge-018/pete-houston/README new file mode 100644 index 0000000000..15d44fe3a4 --- /dev/null +++ b/challenge-018/pete-houston/README @@ -0,0 +1 @@ +Solution by Pete Houston diff --git a/challenge-018/pete-sergeant/README b/challenge-018/pete-sergeant/README new file mode 100644 index 0000000000..baf8dfe304 --- /dev/null +++ b/challenge-018/pete-sergeant/README @@ -0,0 +1 @@ +Solutions by Pete Sergeant. diff --git a/challenge-018/philippe-bruhat/README b/challenge-018/philippe-bruhat/README new file mode 100644 index 0000000000..0bf3aeed05 --- /dev/null +++ b/challenge-018/philippe-bruhat/README @@ -0,0 +1 @@ +Solution by Philippe Bruhat diff --git a/challenge-018/prajith-p/README b/challenge-018/prajith-p/README new file mode 100644 index 0000000000..20517308f8 --- /dev/null +++ b/challenge-018/prajith-p/README @@ -0,0 +1 @@ +Solution by Prajith P diff --git a/challenge-018/randy-lauen/README b/challenge-018/randy-lauen/README new file mode 100644 index 0000000000..17fac69a1c --- /dev/null +++ b/challenge-018/randy-lauen/README @@ -0,0 +1 @@ +Solution by Randy Lauen diff --git a/challenge-018/rob-van-dam/README b/challenge-018/rob-van-dam/README new file mode 100644 index 0000000000..d0e17767f8 --- /dev/null +++ b/challenge-018/rob-van-dam/README @@ -0,0 +1 @@ +Solution by Rob Van Dam diff --git a/challenge-018/rob4t/README b/challenge-018/rob4t/README new file mode 100644 index 0000000000..787d89fa0a --- /dev/null +++ b/challenge-018/rob4t/README @@ -0,0 +1 @@ +Solution by Robert Gratza diff --git a/challenge-018/roger-bell-west/README b/challenge-018/roger-bell-west/README new file mode 100644 index 0000000000..245784dce5 --- /dev/null +++ b/challenge-018/roger-bell-west/README @@ -0,0 +1 @@ +Solutions by Roger Bell West. diff --git a/challenge-018/ruben-westerberg/README b/challenge-018/ruben-westerberg/README new file mode 100644 index 0000000000..14ffe9e086 --- /dev/null +++ b/challenge-018/ruben-westerberg/README @@ -0,0 +1,12 @@ +Solution by Ruben Westerberg + +ch-1.pl and ch-1.p6 +=== +Run the program to with two arguments to calculate the Ackerman value of them +Displays the current recusrion count as a progress indicator and displays the +calculated value and total recursion count as last output. + +ch-2.pl and ch-2.p6 +=== +Run the program with a command line argument (in single quotes). The argument is a URL to validate. +With no command line argument, uses builtin test URI diff --git a/challenge-018/sean-meininger/README b/challenge-018/sean-meininger/README new file mode 100644 index 0000000000..8ca81e00a0 --- /dev/null +++ b/challenge-018/sean-meininger/README @@ -0,0 +1 @@ +Solution by Sean Meininger diff --git a/challenge-018/sergiotarxz/README b/challenge-018/sergiotarxz/README new file mode 100644 index 0000000000..6aac3baa4f --- /dev/null +++ b/challenge-018/sergiotarxz/README @@ -0,0 +1 @@ +Solution by Sergio Iglesias. diff --git a/challenge-018/shardiwal/README b/challenge-018/shardiwal/README new file mode 100644 index 0000000000..c529c63c01 --- /dev/null +++ b/challenge-018/shardiwal/README @@ -0,0 +1 @@ +Solution by Rakesh Kumar Shardiwal diff --git a/challenge-018/shaun-pearce/README b/challenge-018/shaun-pearce/README new file mode 100644 index 0000000000..9b251e6c06 --- /dev/null +++ b/challenge-018/shaun-pearce/README @@ -0,0 +1 @@ +Solutions by Shaun Pearce. diff --git a/challenge-018/simon-miner/README b/challenge-018/simon-miner/README new file mode 100644 index 0000000000..cc433eaa54 --- /dev/null +++ b/challenge-018/simon-miner/README @@ -0,0 +1 @@ +Solutions by Simon Miner. diff --git a/challenge-018/simon-proctor/README b/challenge-018/simon-proctor/README new file mode 100644 index 0000000000..f674742166 --- /dev/null +++ b/challenge-018/simon-proctor/README @@ -0,0 +1 @@ +Solution by Simon Proctor diff --git a/challenge-018/simon-reinhardt/README b/challenge-018/simon-reinhardt/README new file mode 100644 index 0000000000..422afa13b4 --- /dev/null +++ b/challenge-018/simon-reinhardt/README @@ -0,0 +1 @@ +Solution by Simon Reinhardt diff --git a/challenge-018/steve-rogerson/README b/challenge-018/steve-rogerson/README new file mode 100644 index 0000000000..bd91edaf63 --- /dev/null +++ b/challenge-018/steve-rogerson/README @@ -0,0 +1 @@ +Solution by Steve Rogerson diff --git a/challenge-018/steven-lembark/README b/challenge-018/steven-lembark/README new file mode 100644 index 0000000000..74894afa94 --- /dev/null +++ b/challenge-018/steven-lembark/README @@ -0,0 +1 @@ +Solution by Steven Lembark diff --git a/challenge-018/steven-wilson/README b/challenge-018/steven-wilson/README new file mode 100644 index 0000000000..6911e56168 --- /dev/null +++ b/challenge-018/steven-wilson/README @@ -0,0 +1 @@ +Solution by Steven Wilson diff --git a/challenge-018/tiago-stock/README b/challenge-018/tiago-stock/README new file mode 100644 index 0000000000..096a081b30 --- /dev/null +++ b/challenge-018/tiago-stock/README @@ -0,0 +1 @@ +Solution by Tiago Stock diff --git a/challenge-018/tim-smith/README b/challenge-018/tim-smith/README new file mode 100644 index 0000000000..83596de4fd --- /dev/null +++ b/challenge-018/tim-smith/README @@ -0,0 +1 @@ +Solution by Tim Smith diff --git a/challenge-018/tore-andersson/README b/challenge-018/tore-andersson/README new file mode 100644 index 0000000000..6b1b021ce0 --- /dev/null +++ b/challenge-018/tore-andersson/README @@ -0,0 +1 @@ +Solution by Tore Andersson diff --git a/challenge-018/uzluisf/README b/challenge-018/uzluisf/README new file mode 100644 index 0000000000..c668a77e15 --- /dev/null +++ b/challenge-018/uzluisf/README @@ -0,0 +1 @@ +Solution by Luis F. Uceta. diff --git a/challenge-018/veesh-goldman/README b/challenge-018/veesh-goldman/README new file mode 100644 index 0000000000..28a85f6e5c --- /dev/null +++ b/challenge-018/veesh-goldman/README @@ -0,0 +1 @@ +Solution by Veesh Goldman diff --git a/challenge-018/walt-mankowski/README b/challenge-018/walt-mankowski/README new file mode 100644 index 0000000000..cf907b02dd --- /dev/null +++ b/challenge-018/walt-mankowski/README @@ -0,0 +1 @@ +Solutions by Walt Mankowski. diff --git a/challenge-018/william-gilmore/README b/challenge-018/william-gilmore/README new file mode 100644 index 0000000000..e3df40ca2a --- /dev/null +++ b/challenge-018/william-gilmore/README @@ -0,0 +1 @@ +Solution by William Gilmore diff --git a/challenge-018/yary-h/README b/challenge-018/yary-h/README new file mode 100644 index 0000000000..200fbce413 --- /dev/null +++ b/challenge-018/yary-h/README @@ -0,0 +1 @@ +Solution by Yary H diff --git a/challenge-018/yozen-hernandez/README b/challenge-018/yozen-hernandez/README new file mode 100644 index 0000000000..07779f04ee --- /dev/null +++ b/challenge-018/yozen-hernandez/README @@ -0,0 +1 @@ +Solutions by Yozen Hernandez. -- cgit From 7180e1d1ddc515c9bba7e6083c8d84ca1879117a Mon Sep 17 00:00:00 2001 From: Roger Bell_West Date: Mon, 22 Jul 2019 05:41:25 +0100 Subject: Solutions to #18 --- challenge-018/roger-bell-west/perl5/1.pl | 51 +++++++++++++++++++++++++++++++ challenge-018/roger-bell-west/perl5/2.pl | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100755 challenge-018/roger-bell-west/perl5/1.pl create mode 100755 challenge-018/roger-bell-west/perl5/2.pl (limited to 'challenge-018') diff --git a/challenge-018/roger-bell-west/perl5/1.pl b/challenge-018/roger-bell-west/perl5/1.pl new file mode 100755 index 0000000000..7d6f3a92f5 --- /dev/null +++ b/challenge-018/roger-bell-west/perl5/1.pl @@ -0,0 +1,51 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +print map {"$_\n"} lcsubstr(@ARGV); + +sub lcsubstr { + my @str=@_; + if (scalar @str < 2) { + return @str; + } + my @a=lcsubstr2(shift @str,shift @str); + while (@str) { + my %b; + my $c=shift @str; + foreach my $a (@a) { + map {$b{$_}=1} lcsubstr2($a,$c); + } + @a=sort keys %b; + } + return @a; +} + +# don't use this, use String::LCSS_XS instead +sub lcsubstr2 { # https://en.wikipedia.org/wiki/Longest_common_substring_problem#Pseudocode + my @s=split '',shift; + my @t=split '',shift; + my %l; + my $z=0; + my @ret; + foreach my $si (0..$#s) { + foreach my $ti (0..$#t) { + if ($s[$si] eq $t[$ti]) { + if ($si==0 || $ti==0) { + $l{$si}{$ti}=1; + } else { + $l{$si}{$ti}=($l{$si-1}{$ti-1} || 0)+1; + } + if ($l{$si}{$ti} > $z) { + $z=$l{$si}{$ti}; + @ret=(); + } + if ($l{$si}{$ti} == $z) { + push @ret,join('',@s[$si-$z+1..$si]); + } + } + } + } + return @ret; +} diff --git a/challenge-018/roger-bell-west/perl5/2.pl b/challenge-018/roger-bell-west/perl5/2.pl new file mode 100755 index 0000000000..59aae2cd5a --- /dev/null +++ b/challenge-018/roger-bell-west/perl5/2.pl @@ -0,0 +1,52 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +my $q=Local::PriorityQueue->new; +$q->insert_with_priority(4,1); +$q->insert_with_priority(3,2); +$q->insert_with_priority(1,3); +$q->insert_with_priority(2,3); +$q->insert_with_priority(5,0); +while (!$q->is_empty) { + print $q->pull_highest_priority_element,"\n"; +} + +package Local::PriorityQueue; +use List::Util qw(max); + +sub new { + my $class = shift; + my $self={}; + bless $self,$class; + return $self; +} + +sub is_empty { + my $self=shift; + if (scalar keys %{$self}) { + return 0; + } + return 1; +} + +sub insert_with_priority { + my $self=shift; + my $element=shift; + my $priority=shift; + push @{$self->{$priority}},$element; +} + +sub pull_highest_priority_element { + my $self=shift; + if ($self->is_empty) { + return undef; + } + my $prio=max(keys %{$self}); + my $element=shift @{$self->{$prio}}; + if (scalar @{$self->{$prio}}==0) { + delete $self->{$prio}; + } + return $element; +} -- cgit From 4c9f9b62170ec501a27c753b49e0b0f54b732782 Mon Sep 17 00:00:00 2001 From: Roger Bell_West Date: Mon, 22 Jul 2019 06:11:30 +0100 Subject: Oops. --- challenge-018/roger-bell-west/perl5/1.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'challenge-018') diff --git a/challenge-018/roger-bell-west/perl5/1.pl b/challenge-018/roger-bell-west/perl5/1.pl index 7d6f3a92f5..7e952a9cdd 100755 --- a/challenge-018/roger-bell-west/perl5/1.pl +++ b/challenge-018/roger-bell-west/perl5/1.pl @@ -3,6 +3,8 @@ use strict; use warnings; +use List::Util qw(max); + print map {"$_\n"} lcsubstr(@ARGV); sub lcsubstr { @@ -17,7 +19,8 @@ sub lcsubstr { foreach my $a (@a) { map {$b{$_}=1} lcsubstr2($a,$c); } - @a=sort keys %b; + my $m=max(map {length($_)} keys %b); + @a=sort grep {length($_)==$m} keys %b; } return @a; } -- cgit From ad5afaa24f905945daec75e9ebcb311d883436f7 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 22 Jul 2019 10:43:34 +0100 Subject: Longest substrings challenge --- challenge-018/simon-proctor/perl6/ch-1.p6 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-018/simon-proctor/perl6/ch-1.p6 (limited to 'challenge-018') diff --git a/challenge-018/simon-proctor/perl6/ch-1.p6 b/challenge-018/simon-proctor/perl6/ch-1.p6 new file mode 100644 index 0000000000..ee828ecfd1 --- /dev/null +++ b/challenge-018/simon-proctor/perl6/ch-1.p6 @@ -0,0 +1,23 @@ +#!/usr/bin/env perl6 + +use v6; + +#| Find the longest common sub strings of a list of strings +sub MAIN ( + *@words where *.elems > 1 #= List of words to compare +) { + my @word-subs = @words.map( &all-substrings ); + .say for ([(&)] @word-subs).keys.sort( { $^b.codes <=> $^a.codes } ).grep( { state $len = $_.codes; $_.codes == $len }); +} + +sub all-substrings( Str $word ) { + my $len = $word.codes; + my @subs; + + for (1..$len) -> $sub-len { + for (0..$len-$sub-len) -> $start { + @subs.push( $word.substr($start,$sub-len) ); + } + } + return set( @subs ); +} -- cgit From 1d03bfdae1130bbf391661bbb7e3f6fd1917e6c3 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 22 Jul 2019 14:05:50 +0100 Subject: Initial version of the queue --- challenge-018/simon-proctor/perl6/ch-2.p6 | 68 ++++++++++++++++++++++++++++++ challenge-018/simon-proctor/perl6/test.csv | 9 ++++ 2 files changed, 77 insertions(+) create mode 100644 challenge-018/simon-proctor/perl6/ch-2.p6 create mode 100644 challenge-018/simon-proctor/perl6/test.csv (limited to 'challenge-018') diff --git a/challenge-018/simon-proctor/perl6/ch-2.p6 b/challenge-018/simon-proctor/perl6/ch-2.p6 new file mode 100644 index 0000000000..79c7161676 --- /dev/null +++ b/challenge-018/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,68 @@ +#!/usr/bin/env perl6 + +role SingleQueue { + has @!items; + + method add-item( $item ) { + @!items.push( $item ); + } + + method get-item() { + return @!items.shift; + } + + method is-empty() { + @!items.elems == 0; + } +} + +role OrderedQueue { + + has SingleQueue %!queues; + + method is_empty() { + self.is-empty(); + } + + method is-empty() { + [&&] %!queues.kv.map( -> $k, $v { $v.is-empty } ); + } + + method insert_with_priority( $item, Int() $priority ) { + self.insert-with-priority( $item, $priority ); + } + + method insert-with-priority( $item, Int() $priority ) { + %!queues{$priority} //= SingleQueue.new(); + %!queues{$priority}.add-item( $item ); + } + + method pull_highest_priority_element() { + self.pull-highest-priority-element() + } + + method pull-highest-priority-element() { + return Nil if self.is-empty; + my $queue = %!queues.keys.sort( {$^b <=> $^a }).first; + my $value = %!queues{$queue}.get-item; + if %!queues{$queue}.is-empty { + %!queues{$queue}:delete; + } + return $value; + } +} + +#| Given a file in csv format "priority,item" add all the items to the queue +#| then print them in the given order +sub MAIN( $file ) { + my $queue = OrderedQueue.new(); + + for $file.IO.lines -> $line { + my ( $priority, $item ) = $line.split(","); + $queue.insert-with-priority( $item, $priority ); + } + + while ! $queue.is-empty { + $queue.pull-highest-priority-element().say; + } +} \ No newline at end of file diff --git a/challenge-018/simon-proctor/perl6/test.csv b/challenge-018/simon-proctor/perl6/test.csv new file mode 100644 index 0000000000..06209ce75b --- /dev/null +++ b/challenge-018/simon-proctor/perl6/test.csv @@ -0,0 +1,9 @@ +1,Apple +1,Pear +1,Orange +10,Carrot +9,Lettuce +1,Antelope +7,Seven +10,Another ten +11,Top Priority \ No newline at end of file -- cgit From a517fd0485c34a5c8ad8575acefd11e910bd0763 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 22 Jul 2019 14:17:30 +0100 Subject: Update my queue to be iterable --- challenge-018/simon-proctor/perl6/ch-2.p6 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'challenge-018') diff --git a/challenge-018/simon-proctor/perl6/ch-2.p6 b/challenge-018/simon-proctor/perl6/ch-2.p6 index 79c7161676..4b7858f317 100644 --- a/challenge-018/simon-proctor/perl6/ch-2.p6 +++ b/challenge-018/simon-proctor/perl6/ch-2.p6 @@ -16,7 +16,7 @@ role SingleQueue { } } -role OrderedQueue { +role OrderedQueue does Iterator does Iterable { has SingleQueue %!queues; @@ -50,19 +50,25 @@ role OrderedQueue { } return $value; } + + method pull-one() { + self.pull-highest-priority-element // IterationEnd; + } + + method iterator() { + return self; + } } #| Given a file in csv format "priority,item" add all the items to the queue #| then print them in the given order sub MAIN( $file ) { - my $queue = OrderedQueue.new(); + my $queue := OrderedQueue.new(); for $file.IO.lines -> $line { my ( $priority, $item ) = $line.split(","); $queue.insert-with-priority( $item, $priority ); } - while ! $queue.is-empty { - $queue.pull-highest-priority-element().say; - } + .say for $queue; } \ No newline at end of file -- cgit From 85b780b6d7925e3189ab4edf35cc9c0e24502f92 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 22 Jul 2019 14:52:27 +0100 Subject: - Added solutions by Roger Bell West. --- challenge-018/roger-bell-west/perl5/1.pl | 54 ----------------------------- challenge-018/roger-bell-west/perl5/2.pl | 52 --------------------------- challenge-018/roger-bell-west/perl5/ch-1.pl | 54 +++++++++++++++++++++++++++++ challenge-018/roger-bell-west/perl5/ch-2.pl | 52 +++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 106 deletions(-) delete mode 100755 challenge-018/roger-bell-west/perl5/1.pl delete mode 100755 challenge-018/roger-bell-west/perl5/2.pl create mode 100755 challenge-018/roger-bell-west/perl5/ch-1.pl create mode 100755 challenge-018/roger-bell-west/perl5/ch-2.pl (limited to 'challenge-018') diff --git a/challenge-018/roger-bell-west/perl5/1.pl b/challenge-018/roger-bell-west/perl5/1.pl deleted file mode 100755 index 7e952a9cdd..0000000000 --- a/challenge-018/roger-bell-west/perl5/1.pl +++ /dev/null @@ -1,54 +0,0 @@ -#! /usr/bin/perl - -use strict; -use warnings; - -use List::Util qw(max); - -print map {"$_\n"} lcsubstr(@ARGV); - -sub lcsubstr { - my @str=@_; - if (scalar @str < 2) { - return @str; - } - my @a=lcsubstr2(shift @str,shift @str); - while (@str) { - my %b; - my $c=shift @str; - foreach my $a (@a) { - map {$b{$_}=1} lcsubstr2($a,$c); - } - my $m=max(map {length($_)} keys %b); - @a=sort grep {length($_)==$m} keys %b; - } - return @a; -} - -# don't use this, use String::LCSS_XS instead -sub lcsubstr2 { # https://en.wikipedia.org/wiki/Longest_common_substring_problem#Pseudocode - my @s=split '',shift; - my @t=split '',shift; - my %l; - my $z=0; - my @ret; - foreach my $si (0..$#s) { - foreach my $ti (0..$#t) { - if ($s[$si] eq $t[$ti]) { - if ($si==0 || $ti==0) { - $l{$si}{$ti}=1; - } else { - $l{$si}{$ti}=($l{$si-1}{$ti-1} || 0)+1; - } - if ($l{$si}{$ti} > $z) { - $z=$l{$si}{$ti}; - @ret=(); - } - if ($l{$si}{$ti} == $z) { - push @ret,join('',@s[$si-$z+1..$si]); - } - } - } - } - return @ret; -} diff --git a/challenge-018/roger-bell-west/perl5/2.pl b/challenge-018/roger-bell-west/perl5/2.pl deleted file mode 100755 index 59aae2cd5a..0000000000 --- a/challenge-018/roger-bell-west/perl5/2.pl +++ /dev/null @@ -1,52 +0,0 @@ -#! /usr/bin/perl - -use strict; -use warnings; - -my $q=Local::PriorityQueue->new; -$q->insert_with_priority(4,1); -$q->insert_with_priority(3,2); -$q->insert_with_priority(1,3); -$q->insert_with_priority(2,3); -$q->insert_with_priority(5,0); -while (!$q->is_empty) { - print $q->pull_highest_priority_element,"\n"; -} - -package Local::PriorityQueue; -use List::Util qw(max); - -sub new { - my $class = shift; - my $self={}; - bless $self,$class; - return $self; -} - -sub is_empty { - my $self=shift; - if (scalar keys %{$self}) { - return 0; - } - return 1; -} - -sub insert_with_priority { - my $self=shift; - my $element=shift; - my $priority=shift; - push @{$self->{$priority}},$element; -} - -sub pull_highest_priority_element { - my $self=shift; - if ($self->is_empty) { - return undef; - } - my $prio=max(keys %{$self}); - my $element=shift @{$self->{$prio}}; - if (scalar @{$self->{$prio}}==0) { - delete $self->{$prio}; - } - return $element; -} diff --git a/challenge-018/roger-bell-west/perl5/ch-1.pl b/challenge-018/roger-bell-west/perl5/ch-1.pl new file mode 100755 index 0000000000..7e952a9cdd --- /dev/null +++ b/challenge-018/roger-bell-west/perl5/ch-1.pl @@ -0,0 +1,54 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use List::Util qw(max); + +print map {"$_\n"} lcsubstr(@ARGV); + +sub lcsubstr { + my @str=@_; + if (scalar @str < 2) { + return @str; + } + my @a=lcsubstr2(shift @str,shift @str); + while (@str) { + my %b; + my $c=shift @str; + foreach my $a (@a) { + map {$b{$_}=1} lcsubstr2($a,$c); + } + my $m=max(map {length($_)} keys %b); + @a=sort grep {length($_)==$m} keys %b; + } + return @a; +} + +# don't use this, use String::LCSS_XS instead +sub lcsubstr2 { # https://en.wikipedia.org/wiki/Longest_common_substring_problem#Pseudocode + my @s=split '',shift; + my @t=split '',shift; + my %l; + my $z=0; + my @ret; + foreach my $si (0..$#s) { + foreach my $ti (0..$#t) { + if ($s[$si] eq $t[$ti]) { + if ($si==0 || $ti==0) { + $l{$si}{$ti}=1; + } else { + $l{$si}{$ti}=($l{$si-1}{$ti-1} || 0)+1; + } + if ($l{$si}{$ti} > $z) { + $z=$l{$si}{$ti}; + @ret=(); + } + if ($l{$si}{$ti} == $z) { + push @ret,join('',@s[$si-$z+1..$si]); + } + } + } + } + return @ret; +} diff --git a/challenge-018/roger-bell-west/perl5/ch-2.pl b/challenge-018/roger-bell-west/perl5/ch-2.pl new file mode 100755 index 0000000000..59aae2cd5a --- /dev/null +++ b/challenge-018/roger-bell-west/perl5/ch-2.pl @@ -0,0 +1,52 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +my $q=Local::PriorityQueue->new; +$q->insert_with_priority(4,1); +$q->insert_with_priority(3,2); +$q->insert_with_priority(1,3); +$q->insert_with_priority(2,3); +$q->insert_with_priority(5,0); +while (!$q->is_empty) { + print $q->pull_highest_priority_element,"\n"; +} + +package Local::PriorityQueue; +use List::Util qw(max); + +sub new { + my $class = shift; + my $self={}; + bless $self,$class; + return $self; +} + +sub is_empty { + my $self=shift; + if (scalar keys %{$self}) { + return 0; + } + return 1; +} + +sub insert_with_priority { + my $self=shift; + my $element=shift; + my $priority=shift; + push @{$self->{$priority}},$element; +} + +sub pull_highest_priority_element { + my $self=shift; + if ($self->is_empty) { + return undef; + } + my $prio=max(keys %{$self}); + my $element=shift @{$self->{$prio}}; + if (scalar @{$self->{$prio}}==0) { + delete $self->{$prio}; + } + return $element; +} -- cgit From 0bcaecb707c2f9ebe12a1666d616b896ac5a11dd Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 23 Jul 2019 15:14:56 +0100 Subject: - Added solutions by Duane Powell. --- challenge-018/duane-powell/perl5/ch-1.pl | 123 +++++++++++++++++++ challenge-018/duane-powell/perl5/ch-2.pl | 203 +++++++++++++++++++++++++++++++ 2 files changed, 326 insertions(+) create mode 100644 challenge-018/duane-powell/perl5/ch-1.pl create mode 100644 challenge-018/duane-powell/perl5/ch-2.pl (limited to 'challenge-018') diff --git a/challenge-018/duane-powell/perl5/ch-1.pl b/challenge-018/duane-powell/perl5/ch-1.pl new file mode 100644 index 0000000000..ed4443dd1b --- /dev/null +++ b/challenge-018/duane-powell/perl5/ch-1.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl +use Modern::Perl; + +# Write a script that takes 2 or more strings as command line parameters and print the longest common substring. +# For example, the longest common substring of the strings “ABABC”, “BABCA” and “ABCBA” is string “ABC” of length 3. +# Other common substrings are “A”, “AB”, “B”, “BA”, “BC” and “C” + +sub common_substr_find { + my @str = @_; + # The plan is to chunk our strings from largest to smallest + # for example: hello,hell,ello,hel,ell,llo,he,el,ll,lo,h,e,l,l,o + # Then use the chunks as hash keys to count occurances. + # We stop looking at smaller chunks if a bigger match is found. + + my $out = ""; + my %count; + my %chunk; + my $longest_match = 0; + foreach my $str (@str) { + my $i = 0; + my $len = length($str); + my $offset = $len; + while ($offset > 0) { + while (($i + $offset) <= $len and ($i + $offset) >= $longest_match) { + my $chunk = substr($str,$i,$offset); + unless (defined $chunk{$str}{$chunk}) { + # don't match chunks within the same str + $chunk{$str}{$chunk} = 1; + $count{$chunk}++; + } + $longest_match = length($chunk) if ($count{$chunk} > 1 and length($chunk) > $longest_match); + $i++; + } + $i = 0; + $offset--; + } + } + + foreach (keys %count) { + if ($count{$_} > 1) { + $out .= "$_\n" if (length($_) == $longest_match); + } + } + + say "strings are: " . join(",",@str); + if ($out) { + $out = "longest matching substrings are:\n" . $out; + } else { + $out = "no substrings match\n"; + } + say $out; +} + +if (@ARGV) { + common_substr_find(@ARGV); + exit; +} + +my %testdata = ( + 1 => "hello world", + 2 => "polar bears love snow", + 3 => "goodbye goodyear goody", + 4 => "abc xzy", + 5 => "duane powell xxxxduanexxxpowellxxx", + 6 => "abba bbaa aaaa bbbb baba abab", + 7 => "ALL ENGLISH WORDS ... words.txt", +); + +foreach my $data (sort(keys %testdata)) { + my @str; + if ($data < 7) { + @str = split(" ",$testdata{$data}); + common_substr_find(@str); + } else { + open(my $fh, "<", "words.txt") or die "Can't open < words.txt: $!"; + while (my $word = <$fh>) { + chomp $word; + push @str, $word; + } + common_substr_find(@str); + } +} + +__END__ + +./ch1.pl foo bar fubar +strings are: foo,bar,fubar +longest matching substrings are: +bar + +./ch1.pl +strings are: hello,world +longest matching substrings are: +o +l + +strings are: polar,bears,love,snow +longest matching substrings are: +ar + +strings are: goodbye,goodyear,goody +longest matching substrings are: +goody + +strings are: abc,xzy +no substrings match + +strings are: duane,powell,xxxxduanexxxpowellxxx +longest matching substrings are: +powell + +strings are: abba,bbaa,aaaa,bbbb,baba,abab +longest matching substrings are: +bba +aba +bab + +strings are: ... ALL ENGLISH WORDS ... +longest matching substrings are: +electroencephalographical +antidisestablishmentarian +microspectrophotometrical + diff --git a/challenge-018/duane-powell/perl5/ch-2.pl b/challenge-018/duane-powell/perl5/ch-2.pl new file mode 100644 index 0000000000..9eb7d0cf3f --- /dev/null +++ b/challenge-018/duane-powell/perl5/ch-2.pl @@ -0,0 +1,203 @@ +#!/usr/bin/perl +use Modern::Perl; + +# Write a script to implement Priority Queue. It is like regular queue except each element has a priority associated with it. +# In a priority queue, an element with high priority is served before an element with low priority. + +my $p = PriorityQueue->new(); +$p->pull_highest_priority_element(); +$p->insert_with_priority(200,"milkshake!"); +$p->insert_with_priority(300,"pizza?"); +$p->insert_with_priority(500,"cheeseburgers!"); +sleep 1; # sleep a second so nodes have different date values +$p->insert_with_priority(250,"steak and eggs!"); +$p->queue_print(); +$p->pull_highest_priority_element(); +$p->insert_with_priority(350,"hotdogs?"); +$p->insert_with_priority(550,"pancakces and syrup!"); +$p->insert_with_priority(650,"donuts!"); +$p->insert_with_priority(600,"cookies!"); +$p->queue_print(); +$p->pull_highest_priority_element(); +$p->queue_print(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +sleep 1; # sleep a second so nodes have different date values +$p->insert_with_priority(200,"dr peppers!"); +$p->insert_with_priority(300,"pizza?"); +$p->insert_with_priority(500,"cheeseburgers!"); +$p->insert_with_priority(250,"steak and eggs!"); +$p->insert_with_priority(350,"hotdogs?"); +$p->insert_with_priority(550,"pancakces and syrup!"); +$p->queue_print(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->queue_print(); +sleep 1; # sleep a second so nodes have different date values +$p->insert_with_priority(350,"hotdogs?"); +$p->insert_with_priority(550,"pancakces and syrup!"); +$p->queue_print(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->pull_highest_priority_element(); +$p->queue_print(); +exit; + +package PriorityQueue; +sub new { + my $class = shift; + # Simple class to represent a priority queue. + # The queue is made of nested hash refs, linked by _next + # _next=>{ ..., _next=>{ ..., _next=>undef}} + my $self = { + _next => undef, # undef signals empty queue + }; + return bless $self, $class; +} + +sub is_empty { + my $self = shift; + return not defined $self->{_next}; +} + +sub insert_with_priority { + my $self = shift; + + # init new node + my $priority = shift; + my $data = shift; + my $i = { + priority => $priority || 100, + data => $data, + date => time, + _next => undef, # undef signals end of queue + }; + + # empty queue, insert first node and return + if ($self->is_empty()) { + $self->{_next} = $i; + return; + } + + # iterate over queue nodes and insert $i where it belongs + my $here = $self; + my $n = $self->{_next}; + while ($n) { + if ($n->{priority} >= $i->{priority}) { + if (defined $n->{_next}) { + # iterate + $here = $n; + $n = $n->{_next}; + } else { + # we're at the end of queue + $n->{_next} = $i; + return; + } + } else { + # insert $i here + $i->{_next} = $here->{_next}; + $here->{_next} = $i; + return; + } + } +} + +sub pull_highest_priority_element { + my $self = shift; + if ($self->is_empty()) { + say "nothing to pop, queue is empty."; + return; + } else { + my $n = $self->{_next}; + $self->{_next} = $n->{_next}; + say "popping $n->{priority} $n->{date} $n->{data}"; + return $n; + } +} + +sub queue_print { + my $self = shift; + my $n = $self->{_next}; + my $depth = 0; + say "queue print:"; + while ($n) { + my $space = (' ' x $depth); + say "$space $n->{priority} $n->{date} $n->{data}"; + $n = $n->{_next}; + $depth++; + } +} + + +1; + +__END__ + +./ch2.pl +nothing to pop, queue is empty. +queue print: + 500 1563884736 cheeseburgers! + 300 1563884736 pizza? + 250 1563884737 steak and eggs! + 200 1563884736 milkshake! +popping 500 1563884736 cheeseburgers! +queue print: + 650 1563884737 donuts! + 600 1563884737 cookies! + 550 1563884737 pancakces and syrup! + 350 1563884737 hotdogs? + 300 1563884736 pizza? + 250 1563884737 steak and eggs! + 200 1563884736 milkshake! +popping 650 1563884737 donuts! +queue print: + 600 1563884737 cookies! + 550 1563884737 pancakces and syrup! + 350 1563884737 hotdogs? + 300 1563884736 pizza? + 250 1563884737 steak and eggs! + 200 1563884736 milkshake! +popping 600 1563884737 cookies! +popping 550 1563884737 pancakces and syrup! +queue print: + 550 1563884738 pancakces and syrup! + 500 1563884738 cheeseburgers! + 350 1563884737 hotdogs? + 350 1563884738 hotdogs? + 300 1563884736 pizza? + 300 1563884738 pizza? + 250 1563884737 steak and eggs! + 250 1563884738 steak and eggs! + 200 1563884736 milkshake! + 200 1563884738 dr peppers! +popping 550 1563884738 pancakces and syrup! +popping 500 1563884738 cheeseburgers! +popping 350 1563884737 hotdogs? +popping 350 1563884738 hotdogs? +popping 300 1563884736 pizza? +popping 300 1563884738 pizza? +popping 250 1563884737 steak and eggs! +popping 250 1563884738 steak and eggs! +queue print: + 200 1563884736 milkshake! + 200 1563884738 dr peppers! +queue print: + 550 1563884739 pancakces and syrup! + 350 1563884739 hotdogs? + 200 1563884736 milkshake! + 200 1563884738 dr peppers! +popping 550 1563884739 pancakces and syrup! +popping 350 1563884739 hotdogs? +popping 200 1563884736 milkshake! +popping 200 1563884738 dr peppers! +nothing to pop, queue is empty. +queue print: + -- cgit