From 2f03f9ada6efe1f731d076e70fd80988148b2d1f Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Mon, 31 May 2021 10:45:54 +0100 Subject: Challenge #115 --- challenge-115/dave-cross/perl/ch-1.pl | 31 +++++++++++++++++++++++++ challenge-115/dave-cross/perl/ch-2.pl | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 challenge-115/dave-cross/perl/ch-1.pl create mode 100644 challenge-115/dave-cross/perl/ch-2.pl diff --git a/challenge-115/dave-cross/perl/ch-1.pl b/challenge-115/dave-cross/perl/ch-1.pl new file mode 100644 index 0000000000..1d02a3c6f4 --- /dev/null +++ b/challenge-115/dave-cross/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +my @words = get_words(); + +# For a list of words to be able to form a string chain, +# the set of first letters must be the same as the set of +# last letters. + +my (@first, @last); + +# Get arrays containing the first and last letters +for (@words) { + push @first, substr $_, 0, 1; + push @last, substr $_, -1, 1; +} + +# Sort the arrays, join them into string and see if they're +# the same. +say +(join('', sort @first) eq join('', sort @last)) ? 1 : 0; + +sub get_words { + my @input = map { lc } grep { ! /[^a-z]/i } @ARGV; + + die "Give me a list of words\n" unless @input; + + return @input; +} diff --git a/challenge-115/dave-cross/perl/ch-2.pl b/challenge-115/dave-cross/perl/ch-2.pl new file mode 100644 index 0000000000..cc1693046c --- /dev/null +++ b/challenge-115/dave-cross/perl/ch-2.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +# The naive approach is to just sort the input integers +# in reverse order and print the result. But this doesn't +# guarantee that the output is an even number. +# +# So, we find the smallest even integer in our list and +# remove it. We then sort the remaining list and add the +# smallest even number to the end. + +my @ints = get_ints(); + +my ($min_even, $min_even_idx); +# This is bigger than the bigger allowed input number +$min_even = 10; + +while (my ($i, $v) = each @ints) { + if ($v < $min_even and ! ($v % 2)) { + $min_even = $v; + $min_even_idx = $i; + } +} + +splice @ints, $min_even_idx, 1; + +print sort { $b <=> $a } @ints; +say $min_even; + +sub get_ints { + my @input = grep { /^\d$/ } @ARGV; + + die "Give me a list of positive integers under 10\n" unless @input; + + unless (grep { !($_ % 2) } @input) { + die "There must be at least one even number in the list\n"; + } + + return @input; +} -- cgit From bfbd9eea1b0f93c949d310cef1b59f9771b14773 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 31 May 2021 11:42:31 +0100 Subject: - Added folder for week 115. --- challenge-115/3ter/README | 1 + challenge-115/LoneWolfiNTj/README | 1 + challenge-115/aaron-rowe/README | 1 + challenge-115/aaron-sherman/README | 1 + challenge-115/aaronreidsmith/README | 1 + challenge-115/abigail/README.md | 58 +++++ challenge-115/adam-russell/README | 1 + challenge-115/ailbhe-tweedie/README | 1 + challenge-115/alex-daniel/README | 1 + challenge-115/alexander-karelas/README | 1 + challenge-115/alexander-pankoff/README | 1 + challenge-115/alicia-bielsa/README | 1 + challenge-115/andinus/README | 124 +++++++++++ challenge-115/andinus/README.org | 102 +++++++++ challenge-115/andrezgz/README | 1 + challenge-115/anton-fedotov/README | 1 + challenge-115/antonio-gamiz/README | 1 + challenge-115/arne-sommer/README | 1 + challenge-115/arpad-toth/README | 1 + challenge-115/ash/README | 1 + challenge-115/athanasius/README | 1 + challenge-115/aubrey-quarcoo/README | 1 + challenge-115/aviral-goel/README | 1 + challenge-115/ben-davies/README.md | 1 + challenge-115/bill-palmer/README | 1 + challenge-115/bkb/README | 1 + challenge-115/bob-kleemann/README | 1 + challenge-115/bob-lied/README | 3 + challenge-115/brtastic/README | 1 + challenge-115/bruno-ramos/README | 1 + challenge-115/burkhard-nickels/README | 1 + challenge-115/bwva/README | 1 + challenge-115/cheok-yin-fung/README | 1 + challenge-115/christian-jaeger/README | 1 + challenge-115/cliveholloway/README | 1 + challenge-115/colin-crain/README | 1 + challenge-115/craig/README | 1 + challenge-115/creewick/README | 1 + challenge-115/cristian-heredia/README | 1 + challenge-115/daniel-mantovani/README | 1 + challenge-115/daniel-mita/README | 1 + challenge-115/darren-bottin/README | 1 + challenge-115/dave-cross/README | 1 + challenge-115/dave-jacoby/README | 1 + challenge-115/david-kayal/README | 1 + challenge-115/ddobbelaere/README | 1 + challenge-115/deadmarshal/README | 1 + challenge-115/denis-yurashku/README | 1 + challenge-115/dms061/readme | 8 + challenge-115/donald-hunter/README | 1 + challenge-115/doug-schrag/README | 1 + challenge-115/dracos/README | 1 + challenge-115/duane-powell/README | 1 + challenge-115/duncan-c-white/README | 42 ++++ challenge-115/e-choroba/README | 1 + challenge-115/eddy-hs/README | 1 + challenge-115/fabrizio-poggi/README | 1 + challenge-115/feng-chang/README | 1 + challenge-115/finanalyst/README | 1 + challenge-115/finley/README | 1 + challenge-115/fjwhittle/README | 1 + challenge-115/frankivo/README | 1 + challenge-115/fred-zinn/README | 1 + challenge-115/freddie-b/README | 1 + challenge-115/garrett-goebel/README | 1 + challenge-115/giuseppe-terlizzi/README | 1 + challenge-115/gugod/README | 1 + challenge-115/gugod/rust/.gitignore | 2 + challenge-115/guillermo-ramos/README | 1 + challenge-115/gustavo-chaves/README | 1 + challenge-115/hatorikibble/README | 1 + challenge-115/hauke-d/README | 1 + challenge-115/henry-wong/README | 1 + challenge-115/hstejas/README | 1 + challenge-115/ianrifkin/README | 1 + challenge-115/izifresh/README | 1 + challenge-115/jacques-guinnebault/README | 1 + challenge-115/jaime/README | 59 +++++ challenge-115/jaldhar-h-vyas/README | 1 + challenge-115/james-smith/README.md | 239 +++++++++++++++++++++ challenge-115/jan-perl/README | 1 + challenge-115/jaredor/README | 1 + challenge-115/jason-messer/README | 1 + challenge-115/javier-luque/README | 1 + challenge-115/jcrosswh/README | 1 + challenge-115/jeff/README | 1 + challenge-115/jeongoon/.gitignore | 5 + challenge-115/jeongoon/README | 1 + challenge-115/jeremy-carman/README | 1 + challenge-115/jim-bacon/README | 1 + challenge-115/jitu-keshwani/README | 1 + challenge-115/jj-merelo/README | 1 + challenge-115/jluis/README | 1 + challenge-115/jo-37/README | 1 + challenge-115/jo-christian-oterhals/README | 1 + challenge-115/joe-tym/README | 1 + challenge-115/joelle-maslak/README | 1 + challenge-115/john-barrett/README | 1 + challenge-115/jokraft/README | 1 + challenge-115/juan-caballero/README | 1 + challenge-115/julien-fiegehenn/README | 1 + challenge-115/juliodcs/README | 1 + challenge-115/kai-burgdorf/README.md | 1 + challenge-115/kevin-colyer/README | 3 + challenge-115/khalid/README | 1 + challenge-115/kian-meng-ang/README | 1 + challenge-115/kiran-kumar/README | 1 + challenge-115/kivanc-yazan/.gitignore | 2 + challenge-115/kivanc-yazan/README | 1 + challenge-115/kordaff/README | 1 + challenge-115/kurkale6ka/README | 1 + challenge-115/lance-wicks/README | 1 + challenge-115/lars-balker/README | 1 + challenge-115/lars-thegler/README | 1 + challenge-115/laurent-rosenfeld/README | 1 + challenge-115/leoltron/README | 1 + challenge-115/lubos-kolouch/README | 1 + challenge-115/luca-ferrari/README | 1 + challenge-115/magnus-woldrich/README | 1 + challenge-115/manfredi/README | 1 + challenge-115/mano-chandar/README | 1 + challenge-115/mark-anderson/README | 1 + challenge-115/mark-senn/README | 1 + challenge-115/markjreed/README | 6 + challenge-115/markus-holzer/README | 1 + challenge-115/martin-barth/README | 1 + challenge-115/martin-mugeni/README | 1 + challenge-115/mathmauney/README | 1 + challenge-115/matt-latusek/README | 1 + challenge-115/matthew-persico/README | 1 + challenge-115/maxim-kolodyazhny/README | 1 + challenge-115/maxim-nechaev/README | 1 + challenge-115/michael-hamlin/README | 5 + challenge-115/michael-schaap/README | 1 + challenge-115/mihail-iosilevitch/README | 1 + challenge-115/mike-accardo/README | 1 + challenge-115/mimosinnet/README | 1 + challenge-115/mohammad-anwar/README | 1 + challenge-115/ndelucca/README | 1 + challenge-115/neil-bowers/README | 1 + challenge-115/nick-logan/README | 1 + challenge-115/nikhil-prasanna/README | 1 + challenge-115/noud/README | 1 + challenge-115/nunovieira220/README | 1 + challenge-115/ohmycloud/README | 1 + challenge-115/oleksii-tsvietnov/README | 1 + challenge-115/olli-antti/README | 1 + challenge-115/orestis-zekai/README | 1 + challenge-115/ozzy/README | 1 + challenge-115/p6steve/README | 1 + challenge-115/pablo-saavedra/README | 1 + challenge-115/paulo-custodio/README | 1 + challenge-115/pavel-jurca/README | 1 + challenge-115/pavel-starikov/README | 1 + challenge-115/pavel_kuptsov/README | 2 + challenge-115/perlboy1967/README | 1 + challenge-115/pete-houston/README | 1 + challenge-115/pete-sergeant/README | 1 + challenge-115/peter-meszaros/README | 1 + challenge-115/peter-scott/README | 1 + challenge-115/petr-roubicek/README | 1 + challenge-115/philippe-bruhat/README | 1 + challenge-115/phillip-harris/README | 1 + challenge-115/pjdurai/README | 1 + challenge-115/pkmnx/README | 1 + challenge-115/plis-acm/.gitignore | 1 + challenge-115/plis-acm/README | 1 + challenge-115/polettix/README | 1 + challenge-115/polettix/perl/.gitignore | 1 + challenge-115/prajith-p/README | 1 + challenge-115/rage311/README | 1 + challenge-115/rakulius/README | 1 + challenge-115/randy-lauen/README | 1 + challenge-115/richard-park/README | 1 + challenge-115/rnuttall/README | 1 + challenge-115/rob-van-dam/README | 1 + challenge-115/rob4t/README | 1 + challenge-115/roger-bell-west/README | 1 + challenge-115/ruben-westerberg/README | 9 + challenge-115/ryan-thompson/README.md | 19 ++ challenge-115/saiftynet/README | 1 + challenge-115/samir-parikh/README | 1 + challenge-115/sangeet-kar/README | 1 + challenge-115/sean-meininger/README | 1 + challenge-115/sergiotarxz/README | 1 + challenge-115/sgreen/README.md | 3 + challenge-115/shahed-nooshmand/README | 1 + challenge-115/shardiwal/README | 1 + challenge-115/shaun-pearce/README | 1 + challenge-115/shawak/README.md | 1 + challenge-115/shawn-wagner/README | 1 + challenge-115/simon-miner/README | 1 + challenge-115/simon-proctor/README | 1 + challenge-115/simon-reinhardt/README | 1 + challenge-115/sol-demuth/README | 1 + challenge-115/southpawgeek/README | 1 + challenge-115/stephanie-stein/README | 1 + challenge-115/steve-rogerson/README | 1 + challenge-115/steven-lembark/README | 1 + challenge-115/steven-wilson/README | 1 + challenge-115/stuart-little/README | 1 + challenge-115/svetlana-nesterova/README | 1 + challenge-115/swaggboi/README | 1 + challenge-115/ted-leahy/README | 1 + challenge-115/testerR59/README | 1 + challenge-115/tiago-stock/README | 1 + challenge-115/tim-smith/README | 1 + challenge-115/tore-andersson/README | 1 + challenge-115/trenton-langer/README | 1 + challenge-115/tyler-limkemann/README | 1 + challenge-115/tyler-wardhaugh/README | 1 + challenge-115/tyler-wardhaugh/clojure/.gitignore | 16 ++ challenge-115/tyler-wardhaugh/clojure/LICENSE | 214 ++++++++++++++++++ challenge-115/tyler-wardhaugh/clojure/README.md | 35 +++ challenge-115/tyler-wardhaugh/clojure/deps.edn | 14 ++ challenge-115/tyler-wardhaugh/clojure/pom.xml | 50 +++++ .../tyler-wardhaugh/clojure/resources/.keep | 0 challenge-115/tyler-wardhaugh/lua/README.md | 23 ++ challenge-115/tyler-wardhaugh/python/.gitignore | 24 +++ challenge-115/tyler-wardhaugh/python/Makefile | 13 ++ challenge-115/tyler-wardhaugh/python/README.md | 29 +++ challenge-115/ulrich-rieke/README | 1 + challenge-115/user-person/README | 1 + challenge-115/uzluisf/README | 1 + challenge-115/veesh-goldman/README | 1 + challenge-115/vinod-k/README | 1 + challenge-115/vinod-pal/README | 1 + challenge-115/vyacheslav-volgarev/README | 1 + challenge-115/walt-mankowski/README.md | 58 +++++ challenge-115/walt-mankowski/c/.gitignore | 2 + challenge-115/walt-mankowski/cpp/.gitignore | 2 + .../walt-mankowski/python/.python-version | 1 + challenge-115/wambash/README | 1 + challenge-115/wanderdoc/README | 1 + challenge-115/will-west/README | 1 + challenge-115/william-gilmore/README | 1 + challenge-115/wlmb/README | 1 + challenge-115/x1mandi/README | 1 + challenge-115/xkr47/README | 11 + challenge-115/xliff/README | 1 + challenge-115/yary-h/README | 1 + challenge-115/yet-ebreo/README | 1 + challenge-115/yozen-hernandez/README | 1 + challenge-115/ziameraj16/README.md | 47 ++++ .../ziameraj16/kotlin/META-INF/main.kotlin_module | Bin 0 -> 24 bytes 245 files changed, 1440 insertions(+) create mode 100644 challenge-115/3ter/README create mode 100755 challenge-115/LoneWolfiNTj/README create mode 100644 challenge-115/aaron-rowe/README create mode 100644 challenge-115/aaron-sherman/README create mode 100644 challenge-115/aaronreidsmith/README create mode 100644 challenge-115/abigail/README.md create mode 100644 challenge-115/adam-russell/README create mode 100644 challenge-115/ailbhe-tweedie/README create mode 100644 challenge-115/alex-daniel/README create mode 100644 challenge-115/alexander-karelas/README create mode 100644 challenge-115/alexander-pankoff/README create mode 100644 challenge-115/alicia-bielsa/README create mode 100644 challenge-115/andinus/README create mode 100644 challenge-115/andinus/README.org create mode 100644 challenge-115/andrezgz/README create mode 100644 challenge-115/anton-fedotov/README create mode 100644 challenge-115/antonio-gamiz/README create mode 100644 challenge-115/arne-sommer/README create mode 100644 challenge-115/arpad-toth/README create mode 100644 challenge-115/ash/README create mode 100644 challenge-115/athanasius/README create mode 100644 challenge-115/aubrey-quarcoo/README create mode 100644 challenge-115/aviral-goel/README create mode 100644 challenge-115/ben-davies/README.md create mode 100644 challenge-115/bill-palmer/README create mode 100644 challenge-115/bkb/README create mode 100644 challenge-115/bob-kleemann/README create mode 100644 challenge-115/bob-lied/README create mode 100644 challenge-115/brtastic/README create mode 100644 challenge-115/bruno-ramos/README create mode 100644 challenge-115/burkhard-nickels/README create mode 100644 challenge-115/bwva/README create mode 100644 challenge-115/cheok-yin-fung/README create mode 100644 challenge-115/christian-jaeger/README create mode 100644 challenge-115/cliveholloway/README create mode 100644 challenge-115/colin-crain/README create mode 100644 challenge-115/craig/README create mode 100644 challenge-115/creewick/README create mode 100644 challenge-115/cristian-heredia/README create mode 100644 challenge-115/daniel-mantovani/README create mode 100644 challenge-115/daniel-mita/README create mode 100644 challenge-115/darren-bottin/README create mode 100644 challenge-115/dave-cross/README create mode 100644 challenge-115/dave-jacoby/README create mode 100644 challenge-115/david-kayal/README create mode 100644 challenge-115/ddobbelaere/README create mode 100644 challenge-115/deadmarshal/README create mode 100644 challenge-115/denis-yurashku/README create mode 100644 challenge-115/dms061/readme create mode 100644 challenge-115/donald-hunter/README create mode 100644 challenge-115/doug-schrag/README create mode 100644 challenge-115/dracos/README create mode 100644 challenge-115/duane-powell/README create mode 100644 challenge-115/duncan-c-white/README create mode 100644 challenge-115/e-choroba/README create mode 100644 challenge-115/eddy-hs/README create mode 100644 challenge-115/fabrizio-poggi/README create mode 100644 challenge-115/feng-chang/README create mode 100644 challenge-115/finanalyst/README create mode 100644 challenge-115/finley/README create mode 100644 challenge-115/fjwhittle/README create mode 100644 challenge-115/frankivo/README create mode 100644 challenge-115/fred-zinn/README create mode 100644 challenge-115/freddie-b/README create mode 100644 challenge-115/garrett-goebel/README create mode 100644 challenge-115/giuseppe-terlizzi/README create mode 100644 challenge-115/gugod/README create mode 100644 challenge-115/gugod/rust/.gitignore create mode 100644 challenge-115/guillermo-ramos/README create mode 100644 challenge-115/gustavo-chaves/README create mode 100644 challenge-115/hatorikibble/README create mode 100644 challenge-115/hauke-d/README create mode 100644 challenge-115/henry-wong/README create mode 100644 challenge-115/hstejas/README create mode 100644 challenge-115/ianrifkin/README create mode 100644 challenge-115/izifresh/README create mode 100644 challenge-115/jacques-guinnebault/README create mode 100644 challenge-115/jaime/README create mode 100644 challenge-115/jaldhar-h-vyas/README create mode 100644 challenge-115/james-smith/README.md create mode 100644 challenge-115/jan-perl/README create mode 100644 challenge-115/jaredor/README create mode 100644 challenge-115/jason-messer/README create mode 100644 challenge-115/javier-luque/README create mode 100644 challenge-115/jcrosswh/README create mode 100644 challenge-115/jeff/README create mode 100644 challenge-115/jeongoon/.gitignore create mode 100644 challenge-115/jeongoon/README create mode 100644 challenge-115/jeremy-carman/README create mode 100644 challenge-115/jim-bacon/README create mode 100644 challenge-115/jitu-keshwani/README create mode 100644 challenge-115/jj-merelo/README create mode 100644 challenge-115/jluis/README create mode 100644 challenge-115/jo-37/README create mode 100644 challenge-115/jo-christian-oterhals/README create mode 100644 challenge-115/joe-tym/README create mode 100644 challenge-115/joelle-maslak/README create mode 100644 challenge-115/john-barrett/README create mode 100644 challenge-115/jokraft/README create mode 100644 challenge-115/juan-caballero/README create mode 100644 challenge-115/julien-fiegehenn/README create mode 100644 challenge-115/juliodcs/README create mode 100644 challenge-115/kai-burgdorf/README.md create mode 100644 challenge-115/kevin-colyer/README create mode 100644 challenge-115/khalid/README create mode 100644 challenge-115/kian-meng-ang/README create mode 100644 challenge-115/kiran-kumar/README create mode 100644 challenge-115/kivanc-yazan/.gitignore create mode 100644 challenge-115/kivanc-yazan/README create mode 100644 challenge-115/kordaff/README create mode 100644 challenge-115/kurkale6ka/README create mode 100644 challenge-115/lance-wicks/README create mode 100644 challenge-115/lars-balker/README create mode 100644 challenge-115/lars-thegler/README create mode 100644 challenge-115/laurent-rosenfeld/README create mode 100644 challenge-115/leoltron/README create mode 100644 challenge-115/lubos-kolouch/README create mode 100644 challenge-115/luca-ferrari/README create mode 100644 challenge-115/magnus-woldrich/README create mode 100644 challenge-115/manfredi/README create mode 100644 challenge-115/mano-chandar/README create mode 100644 challenge-115/mark-anderson/README create mode 100644 challenge-115/mark-senn/README create mode 100644 challenge-115/markjreed/README create mode 100644 challenge-115/markus-holzer/README create mode 100644 challenge-115/martin-barth/README create mode 100644 challenge-115/martin-mugeni/README create mode 100644 challenge-115/mathmauney/README create mode 100644 challenge-115/matt-latusek/README create mode 100644 challenge-115/matthew-persico/README create mode 100644 challenge-115/maxim-kolodyazhny/README create mode 100644 challenge-115/maxim-nechaev/README create mode 100644 challenge-115/michael-hamlin/README create mode 100644 challenge-115/michael-schaap/README create mode 100644 challenge-115/mihail-iosilevitch/README create mode 100644 challenge-115/mike-accardo/README create mode 100644 challenge-115/mimosinnet/README create mode 100644 challenge-115/mohammad-anwar/README create mode 100644 challenge-115/ndelucca/README create mode 100644 challenge-115/neil-bowers/README create mode 100644 challenge-115/nick-logan/README create mode 100644 challenge-115/nikhil-prasanna/README create mode 100644 challenge-115/noud/README create mode 100644 challenge-115/nunovieira220/README create mode 100644 challenge-115/ohmycloud/README create mode 100644 challenge-115/oleksii-tsvietnov/README create mode 100644 challenge-115/olli-antti/README create mode 100644 challenge-115/orestis-zekai/README create mode 100644 challenge-115/ozzy/README create mode 100644 challenge-115/p6steve/README create mode 100644 challenge-115/pablo-saavedra/README create mode 100644 challenge-115/paulo-custodio/README create mode 100644 challenge-115/pavel-jurca/README create mode 100644 challenge-115/pavel-starikov/README create mode 100644 challenge-115/pavel_kuptsov/README create mode 100644 challenge-115/perlboy1967/README create mode 100644 challenge-115/pete-houston/README create mode 100644 challenge-115/pete-sergeant/README create mode 100644 challenge-115/peter-meszaros/README create mode 100644 challenge-115/peter-scott/README create mode 100644 challenge-115/petr-roubicek/README create mode 100644 challenge-115/philippe-bruhat/README create mode 100644 challenge-115/phillip-harris/README create mode 100644 challenge-115/pjdurai/README create mode 100644 challenge-115/pkmnx/README create mode 100644 challenge-115/plis-acm/.gitignore create mode 100644 challenge-115/plis-acm/README create mode 100644 challenge-115/polettix/README create mode 100644 challenge-115/polettix/perl/.gitignore create mode 100644 challenge-115/prajith-p/README create mode 100644 challenge-115/rage311/README create mode 100644 challenge-115/rakulius/README create mode 100644 challenge-115/randy-lauen/README create mode 100644 challenge-115/richard-park/README create mode 100644 challenge-115/rnuttall/README create mode 100644 challenge-115/rob-van-dam/README create mode 100644 challenge-115/rob4t/README create mode 100644 challenge-115/roger-bell-west/README create mode 100644 challenge-115/ruben-westerberg/README create mode 100644 challenge-115/ryan-thompson/README.md create mode 100644 challenge-115/saiftynet/README create mode 100644 challenge-115/samir-parikh/README create mode 100644 challenge-115/sangeet-kar/README create mode 100644 challenge-115/sean-meininger/README create mode 100644 challenge-115/sergiotarxz/README create mode 100644 challenge-115/sgreen/README.md create mode 100644 challenge-115/shahed-nooshmand/README create mode 100644 challenge-115/shardiwal/README create mode 100644 challenge-115/shaun-pearce/README create mode 100644 challenge-115/shawak/README.md create mode 100644 challenge-115/shawn-wagner/README create mode 100644 challenge-115/simon-miner/README create mode 100644 challenge-115/simon-proctor/README create mode 100644 challenge-115/simon-reinhardt/README create mode 100644 challenge-115/sol-demuth/README create mode 100644 challenge-115/southpawgeek/README create mode 100644 challenge-115/stephanie-stein/README create mode 100644 challenge-115/steve-rogerson/README create mode 100644 challenge-115/steven-lembark/README create mode 100644 challenge-115/steven-wilson/README create mode 100644 challenge-115/stuart-little/README create mode 100644 challenge-115/svetlana-nesterova/README create mode 100644 challenge-115/swaggboi/README create mode 100644 challenge-115/ted-leahy/README create mode 100644 challenge-115/testerR59/README create mode 100644 challenge-115/tiago-stock/README create mode 100644 challenge-115/tim-smith/README create mode 100644 challenge-115/tore-andersson/README create mode 100644 challenge-115/trenton-langer/README create mode 100644 challenge-115/tyler-limkemann/README create mode 100644 challenge-115/tyler-wardhaugh/README create mode 100644 challenge-115/tyler-wardhaugh/clojure/.gitignore create mode 100644 challenge-115/tyler-wardhaugh/clojure/LICENSE create mode 100644 challenge-115/tyler-wardhaugh/clojure/README.md create mode 100644 challenge-115/tyler-wardhaugh/clojure/deps.edn create mode 100644 challenge-115/tyler-wardhaugh/clojure/pom.xml create mode 100644 challenge-115/tyler-wardhaugh/clojure/resources/.keep create mode 100644 challenge-115/tyler-wardhaugh/lua/README.md create mode 100644 challenge-115/tyler-wardhaugh/python/.gitignore create mode 100644 challenge-115/tyler-wardhaugh/python/Makefile create mode 100644 challenge-115/tyler-wardhaugh/python/README.md create mode 100644 challenge-115/ulrich-rieke/README create mode 100644 challenge-115/user-person/README create mode 100644 challenge-115/uzluisf/README create mode 100644 challenge-115/veesh-goldman/README create mode 100644 challenge-115/vinod-k/README create mode 100644 challenge-115/vinod-pal/README create mode 100644 challenge-115/vyacheslav-volgarev/README create mode 100644 challenge-115/walt-mankowski/README.md create mode 100644 challenge-115/walt-mankowski/c/.gitignore create mode 100644 challenge-115/walt-mankowski/cpp/.gitignore create mode 100644 challenge-115/walt-mankowski/python/.python-version create mode 100644 challenge-115/wambash/README create mode 100644 challenge-115/wanderdoc/README create mode 100644 challenge-115/will-west/README create mode 100644 challenge-115/william-gilmore/README create mode 100644 challenge-115/wlmb/README create mode 100644 challenge-115/x1mandi/README create mode 100644 challenge-115/xkr47/README create mode 100644 challenge-115/xliff/README create mode 100644 challenge-115/yary-h/README create mode 100644 challenge-115/yet-ebreo/README create mode 100644 challenge-115/yozen-hernandez/README create mode 100644 challenge-115/ziameraj16/README.md create mode 100644 challenge-115/ziameraj16/kotlin/META-INF/main.kotlin_module diff --git a/challenge-115/3ter/README b/challenge-115/3ter/README new file mode 100644 index 0000000000..8c594431f3 --- /dev/null +++ b/challenge-115/3ter/README @@ -0,0 +1 @@ +Solutions by 3ter. diff --git a/challenge-115/LoneWolfiNTj/README b/challenge-115/LoneWolfiNTj/README new file mode 100755 index 0000000000..bf42ad2482 --- /dev/null +++ b/challenge-115/LoneWolfiNTj/README @@ -0,0 +1 @@ +Solution by Robbie Hatley (github user "LoneWolfiNTj"). \ No newline at end of file diff --git a/challenge-115/aaron-rowe/README b/challenge-115/aaron-rowe/README new file mode 100644 index 0000000000..e14e0782fb --- /dev/null +++ b/challenge-115/aaron-rowe/README @@ -0,0 +1 @@ +Solutions by Aaron Rowe. diff --git a/challenge-115/aaron-sherman/README b/challenge-115/aaron-sherman/README new file mode 100644 index 0000000000..14ec31f570 --- /dev/null +++ b/challenge-115/aaron-sherman/README @@ -0,0 +1 @@ +Solutions by Aaron Sherman. diff --git a/challenge-115/aaronreidsmith/README b/challenge-115/aaronreidsmith/README new file mode 100644 index 0000000000..2fcfe1fdcc --- /dev/null +++ b/challenge-115/aaronreidsmith/README @@ -0,0 +1 @@ +Solution by Aaron Smith diff --git a/challenge-115/abigail/README.md b/challenge-115/abigail/README.md new file mode 100644 index 0000000000..7548aee37d --- /dev/null +++ b/challenge-115/abigail/README.md @@ -0,0 +1,58 @@ +# Solutions by Abigail +## [Next Palindrome Number](https://perlweeklychallenge.org/blog/perl-weekly-challenge-114/#TASK1) + +> You are given a positive integer `$N`. +> +> Write a script to find out the next Palindrome Number higher than +> the given integer `$N`. + +### Example +~~~~ +Input: $N = 1234 +Output: 1331 + +Input: $N = 999 +Output: 1001 +~~~~ + +### Solutions +* [AWK](awk/ch-1.awk) +* [Bash](bash/ch-1.sh) +* [C](c/ch-1.c) +* [Perl](perl/ch-1.pl) + +### Blog +[Next Palindrome Number](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-114-1.html) + +## [Higher Integer Set Bits](https://perlweeklychallenge.org/blog/perl-weekly-challenge-114/#TASK2) + +> You are given a positive integer `$N`. +> +> Write a script to find the next higher integer having the same number of +> `1` bits in binary representation as `$N`. + +### Examples +~~~~ +Input: $N = 3 +Output: 5 +~~~~ + +Binary representation of `$N` is `011`. There are two `1` bits. So the next +higher integer is `5` having the same the number of `1` bits i.e. `101`. + +~~~~ +Input: $N = 12 +Output: 17 +~~~~ + +Binary representation of `$N` is `1100`. There are two `1` bits. So the next +higher integer is `17` having the same number of `1` bits i.e. `10001`. + +### Solutions +* [GNU AWK](awk/ch-2.gawk) +* [Bash](bash/ch-2.sh) +* [C](c/ch-2.c) +* [Perl](perl/ch-2.pl) + +### Blog +[Higher Integet Set Bits](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-114-2.html) diff --git a/challenge-115/adam-russell/README b/challenge-115/adam-russell/README new file mode 100644 index 0000000000..1d2e2957c5 --- /dev/null +++ b/challenge-115/adam-russell/README @@ -0,0 +1 @@ +Solution by Adam Russell diff --git a/challenge-115/ailbhe-tweedie/README b/challenge-115/ailbhe-tweedie/README new file mode 100644 index 0000000000..36d4034b70 --- /dev/null +++ b/challenge-115/ailbhe-tweedie/README @@ -0,0 +1 @@ +Solution by Ailbhe Tweedie diff --git a/challenge-115/alex-daniel/README b/challenge-115/alex-daniel/README new file mode 100644 index 0000000000..65550789bd --- /dev/null +++ b/challenge-115/alex-daniel/README @@ -0,0 +1 @@ +Solution by Alex Daniel. diff --git a/challenge-115/alexander-karelas/README b/challenge-115/alexander-karelas/README new file mode 100644 index 0000000000..3de9fce8d9 --- /dev/null +++ b/challenge-115/alexander-karelas/README @@ -0,0 +1 @@ +Solution by Alexander Karelas diff --git a/challenge-115/alexander-pankoff/README b/challenge-115/alexander-pankoff/README new file mode 100644 index 0000000000..41f67807ac --- /dev/null +++ b/challenge-115/alexander-pankoff/README @@ -0,0 +1 @@ +Solution by Alexander Pankoff diff --git a/challenge-115/alicia-bielsa/README b/challenge-115/alicia-bielsa/README new file mode 100644 index 0000000000..c5187874c3 --- /dev/null +++ b/challenge-115/alicia-bielsa/README @@ -0,0 +1 @@ +Solution by Alicia Beilsa. diff --git a/challenge-115/andinus/README b/challenge-115/andinus/README new file mode 100644 index 0000000000..cef31723b7 --- /dev/null +++ b/challenge-115/andinus/README @@ -0,0 +1,124 @@ + ━━━━━━━━━━━━━━━ + CHALLENGE 110 + + Andinus + ━━━━━━━━━━━━━━━ + + + 2021-04-29 + + +Table of Contents +───────────────── + +Task 1 - Valid Phone Numbers +Task 2 - Transpose File + + + + + +Task 1 - Valid Phone Numbers +════════════════════════════ + + You are given a text file. + + Write a script to display all valid phone numbers in the given text + file. + + Acceptable Phone Number Formats: + ┌──── + │ +nn nnnnnnnnnn + │ (nn) nnnnnnnnnn + │ nnnn nnnnnnnnnn + └──── + + Input File: + ┌──── + │ 0044 1148820341 + │ +44 1148820341 + │ 44-11-4882-0341 + │ (44) 1148820341 + │ 00 1148820341 + └──── + + Output: + ┌──── + │ 0044 1148820341 + │ +44 1148820341 + │ (44) 1148820341 + └──── + + +Raku +──── + + • Program: + + `PhoneNumber' grammar parses each entry one by one. `country-code' + handles the 3 cases for country codes & `number' handles the other + part. + + We just loop over every entry & print it if it's a valid phone number. + + ┌──── + │ grammar PhoneNumber { + │ token TOP { \s* \s+ } + │ token country-code { '+' \d \d | '(' \d \d ')' | \d ** 4 } + │ token number { \d ** 10 } + │ } + │ + │ for $file.IO.lines -> $entry { + │ say $entry if PhoneNumber.parse($entry); + │ } + └──── + + +Task 2 - Transpose File +═══════════════════════ + + You are given a text file. + + Write a script to transpose the contents of the given file. + + Input File: + ┌──── + │ name,age,sex + │ Mohammad,45,m + │ Joe,20,m + │ Julie,35,f + │ Cristina,10,f + └──── + + Output: + ┌──── + │ name,Mohammad,Joe,Julie,Cristina + │ age,45,20,35,10 + │ sex,m,m,f,f + └──── + + +Raku +──── + + • Program: + + `.IO.lines' part creates a list of lines in the files, then we split + it at ",". `zip' then returns a list which is formatted the way we + want it to be. + + From the documentation: + Creates a supply that emits combined values as soon as + there is a new value seen on all of the supplies. + + zip iterates through each of the input lists + synchronously, 'Zipping' them together, so that elements + are grouped according to their input list index, in the + order that the lists are provided. + + We then join the entries with ",", loop over the formatted lines & + print them. + + ┌──── + │ .say for zip($file.IO.lines.map(*.split(","))).map(*.join(",")); + └──── diff --git a/challenge-115/andinus/README.org b/challenge-115/andinus/README.org new file mode 100644 index 0000000000..221092d3f0 --- /dev/null +++ b/challenge-115/andinus/README.org @@ -0,0 +1,102 @@ +#+title: Challenge 110 +#+date: 2021-04-29 +#+html_link_up: ../index.html +#+export_file_name: index +#+setupfile: ~/.emacs.d/org-templates/level-2.org + +* Task 1 - Valid Phone Numbers + +You are given a text file. + +Write a script to display all valid phone numbers in the given text file. + +Acceptable Phone Number Formats: +#+begin_src ++nn nnnnnnnnnn +(nn) nnnnnnnnnn +nnnn nnnnnnnnnn +#+end_src + +Input File: +#+begin_src +0044 1148820341 + +44 1148820341 + 44-11-4882-0341 +(44) 1148820341 + 00 1148820341 +#+end_src + +Output: +#+begin_src +0044 1148820341 + +44 1148820341 +(44) 1148820341 +#+end_src + +** Raku + +- Program: [[file:raku/ch-1.raku]] + +~PhoneNumber~ grammar parses each entry one by one. ~country-code~ handles +the 3 cases for country codes & ~number~ handles the other part. + +We just loop over every entry & print it if it's a valid phone number. + +#+begin_src raku +grammar PhoneNumber { + token TOP { \s* \s+ } + token country-code { '+' \d \d | '(' \d \d ')' | \d ** 4 } + token number { \d ** 10 } +} + +for $file.IO.lines -> $entry { + say $entry if PhoneNumber.parse($entry); +} +#+end_src + +* Task 2 - Transpose File + +You are given a text file. + +Write a script to transpose the contents of the given file. + +Input File: +#+begin_src +name,age,sex +Mohammad,45,m +Joe,20,m +Julie,35,f +Cristina,10,f +#+end_src + +Output: +#+begin_src +name,Mohammad,Joe,Julie,Cristina +age,45,20,35,10 +sex,m,m,f,f +#+end_src + +** Raku + +- Program: [[file:raku/ch-2.raku]] + +~.IO.lines~ part creates a list of lines in the files, then we split it at +",". ~zip~ then returns a list which is formatted the way we want it to +be. + +From the documentation: https://docs.raku.org/routine/zip +#+begin_quote +Creates a supply that emits combined values as soon as there is a new +value seen on all of the supplies. + +zip iterates through each of the input lists synchronously, 'Zipping' +them together, so that elements are grouped according to their input +list index, in the order that the lists are provided. +#+end_quote + +We then join the entries with ",", loop over the formatted lines & print +them. + +#+begin_src raku +.say for zip($file.IO.lines.map(*.split(","))).map(*.join(",")); +#+end_src diff --git a/challenge-115/andrezgz/README b/challenge-115/andrezgz/README new file mode 100644 index 0000000000..f4fd0da88e --- /dev/null +++ b/challenge-115/andrezgz/README @@ -0,0 +1 @@ +Solution by Andrezgz diff --git a/challenge-115/anton-fedotov/README b/challenge-115/anton-fedotov/README new file mode 100644 index 0000000000..f7c4f6deed --- /dev/null +++ b/challenge-115/anton-fedotov/README @@ -0,0 +1 @@ +Solutions by Anton Fedotov. diff --git a/challenge-115/antonio-gamiz/README b/challenge-115/antonio-gamiz/README new file mode 100644 index 0000000000..1f5ed5871a --- /dev/null +++ b/challenge-115/antonio-gamiz/README @@ -0,0 +1 @@ +Solution by Antonio Gamiz diff --git a/challenge-115/arne-sommer/README b/challenge-115/arne-sommer/README new file mode 100644 index 0000000000..b5d88e4df4 --- /dev/null +++ b/challenge-115/arne-sommer/README @@ -0,0 +1 @@ +Solution by Arne Sommer. diff --git a/challenge-115/arpad-toth/README b/challenge-115/arpad-toth/README new file mode 100644 index 0000000000..6661dd82c1 --- /dev/null +++ b/challenge-115/arpad-toth/README @@ -0,0 +1 @@ +Solution by Arpad Toth diff --git a/challenge-115/ash/README b/challenge-115/ash/README new file mode 100644 index 0000000000..318b1bfb41 --- /dev/null +++ b/challenge-115/ash/README @@ -0,0 +1 @@ +Solutions by Andrew Shitov diff --git a/challenge-115/athanasius/README b/challenge-115/athanasius/README new file mode 100644 index 0000000000..cc357fda4a --- /dev/null +++ b/challenge-115/athanasius/README @@ -0,0 +1 @@ +Solution by Athanasius diff --git a/challenge-115/aubrey-quarcoo/README b/challenge-115/aubrey-quarcoo/README new file mode 100644 index 0000000000..8e63a2c1f5 --- /dev/null +++ b/challenge-115/aubrey-quarcoo/README @@ -0,0 +1 @@ +Solution by Aubrey Quarcoo diff --git a/challenge-115/aviral-goel/README b/challenge-115/aviral-goel/README new file mode 100644 index 0000000000..e64ee14512 --- /dev/null +++ b/challenge-115/aviral-goel/README @@ -0,0 +1 @@ +Solutions by Aviral Goel. diff --git a/challenge-115/ben-davies/README.md b/challenge-115/ben-davies/README.md new file mode 100644 index 0000000000..77158344c9 --- /dev/null +++ b/challenge-115/ben-davies/README.md @@ -0,0 +1 @@ +Solution by Ben Davies diff --git a/challenge-115/bill-palmer/README b/challenge-115/bill-palmer/README new file mode 100644 index 0000000000..08ec849a41 --- /dev/null +++ b/challenge-115/bill-palmer/README @@ -0,0 +1 @@ +Solution by Bill Palmer. diff --git a/challenge-115/bkb/README b/challenge-115/bkb/README new file mode 100644 index 0000000000..4721993bb3 --- /dev/null +++ b/challenge-115/bkb/README @@ -0,0 +1 @@ +Solution by Ben Bullock. diff --git a/challenge-115/bob-kleemann/README b/challenge-115/bob-kleemann/README new file mode 100644 index 0000000000..78680e4035 --- /dev/null +++ b/challenge-115/bob-kleemann/README @@ -0,0 +1 @@ +Solution by Bob Kleemann diff --git a/challenge-115/bob-lied/README b/challenge-115/bob-lied/README new file mode 100644 index 0000000000..8417e3a7f7 --- /dev/null +++ b/challenge-115/bob-lied/README @@ -0,0 +1,3 @@ +Solutions to weekly challenge 103 by Bob Lied. + +https://perlweeklychallenge.org/blog/perl-weekly-challenge-103/ diff --git a/challenge-115/brtastic/README b/challenge-115/brtastic/README new file mode 100644 index 0000000000..0fbe79fd6f --- /dev/null +++ b/challenge-115/brtastic/README @@ -0,0 +1 @@ +Solutions by Bartosz Jarzyna. diff --git a/challenge-115/bruno-ramos/README b/challenge-115/bruno-ramos/README new file mode 100644 index 0000000000..9d631dad8f --- /dev/null +++ b/challenge-115/bruno-ramos/README @@ -0,0 +1 @@ +Solutions by Bruno Ramos. diff --git a/challenge-115/burkhard-nickels/README b/challenge-115/burkhard-nickels/README new file mode 100644 index 0000000000..f5e16bb98b --- /dev/null +++ b/challenge-115/burkhard-nickels/README @@ -0,0 +1 @@ +Solutions by Burkhard Nickels. diff --git a/challenge-115/bwva/README b/challenge-115/bwva/README new file mode 100644 index 0000000000..ee6a7d7dc1 --- /dev/null +++ b/challenge-115/bwva/README @@ -0,0 +1 @@ +Solution(s) by bwva (Bruce Van Allen) diff --git a/challenge-115/cheok-yin-fung/README b/challenge-115/cheok-yin-fung/README new file mode 100644 index 0000000000..4413b13ada --- /dev/null +++ b/challenge-115/cheok-yin-fung/README @@ -0,0 +1 @@ +Solutions by Cheok-Yin Fung. diff --git a/challenge-115/christian-jaeger/README b/challenge-115/christian-jaeger/README new file mode 100644 index 0000000000..4ef4f11c10 --- /dev/null +++ b/challenge-115/christian-jaeger/README @@ -0,0 +1 @@ +Solution by Christian Jaeger diff --git a/challenge-115/cliveholloway/README b/challenge-115/cliveholloway/README new file mode 100644 index 0000000000..b69201296e --- /dev/null +++ b/challenge-115/cliveholloway/README @@ -0,0 +1 @@ +Solution by Clive Holloway diff --git a/challenge-115/colin-crain/README b/challenge-115/colin-crain/README new file mode 100644 index 0000000000..2a5d87e97d --- /dev/null +++ b/challenge-115/colin-crain/README @@ -0,0 +1 @@ +Solutions by Colin Crain. diff --git a/challenge-115/craig/README b/challenge-115/craig/README new file mode 100644 index 0000000000..18088481eb --- /dev/null +++ b/challenge-115/craig/README @@ -0,0 +1 @@ +Solutions by Craig. diff --git a/challenge-115/creewick/README b/challenge-115/creewick/README new file mode 100644 index 0000000000..c490e4fb80 --- /dev/null +++ b/challenge-115/creewick/README @@ -0,0 +1 @@ +Solutions by Creewick. diff --git a/challenge-115/cristian-heredia/README b/challenge-115/cristian-heredia/README new file mode 100644 index 0000000000..c53da8a54c --- /dev/null +++ b/challenge-115/cristian-heredia/README @@ -0,0 +1 @@ +Solutions by Cristina Heredia. diff --git a/challenge-115/daniel-mantovani/README b/challenge-115/daniel-mantovani/README new file mode 100644 index 0000000000..ed538216f2 --- /dev/null +++ b/challenge-115/daniel-mantovani/README @@ -0,0 +1 @@ +Solution by Daniel Mantovani diff --git a/challenge-115/daniel-mita/README b/challenge-115/daniel-mita/README new file mode 100644 index 0000000000..37339f491f --- /dev/null +++ b/challenge-115/daniel-mita/README @@ -0,0 +1 @@ +Solution by Daniel Mita diff --git a/challenge-115/darren-bottin/README b/challenge-115/darren-bottin/README new file mode 100644 index 0000000000..6c792afe8e --- /dev/null +++ b/challenge-115/darren-bottin/README @@ -0,0 +1 @@ +Solutions by Darren Bottin. diff --git a/challenge-115/dave-cross/README b/challenge-115/dave-cross/README new file mode 100644 index 0000000000..04b1b0623b --- /dev/null +++ b/challenge-115/dave-cross/README @@ -0,0 +1 @@ +Solution by Dave Cross diff --git a/challenge-115/dave-jacoby/README b/challenge-115/dave-jacoby/README new file mode 100644 index 0000000000..7c06689f16 --- /dev/null +++ b/challenge-115/dave-jacoby/README @@ -0,0 +1 @@ +Solution by Dave Jacoby diff --git a/challenge-115/david-kayal/README b/challenge-115/david-kayal/README new file mode 100644 index 0000000000..66f8615260 --- /dev/null +++ b/challenge-115/david-kayal/README @@ -0,0 +1 @@ +Solution by David Kayal diff --git a/challenge-115/ddobbelaere/README b/challenge-115/ddobbelaere/README new file mode 100644 index 0000000000..36f8cdcd67 --- /dev/null +++ b/challenge-115/ddobbelaere/README @@ -0,0 +1 @@ +Solution by Dieter Dobbelaere diff --git a/challenge-115/deadmarshal/README b/challenge-115/deadmarshal/README new file mode 100644 index 0000000000..243097dede --- /dev/null +++ b/challenge-115/deadmarshal/README @@ -0,0 +1 @@ +Solution by Ali Moradi \ No newline at end of file diff --git a/challenge-115/denis-yurashku/README b/challenge-115/denis-yurashku/README new file mode 100644 index 0000000000..2fea994000 --- /dev/null +++ b/challenge-115/denis-yurashku/README @@ -0,0 +1 @@ +Solutions by Denis Yurashku. diff --git a/challenge-115/dms061/readme b/challenge-115/dms061/readme new file mode 100644 index 0000000000..e2684c7d25 --- /dev/null +++ b/challenge-115/dms061/readme @@ -0,0 +1,8 @@ +Solutions by David Schwartz +Last updated: 5/16/2021 + +Contains: + Solutions for questions 1 and 2 in perl. + +The folders also contain examples of output generated from running the program. + diff --git a/challenge-115/donald-hunter/README b/challenge-115/donald-hunter/README new file mode 100644 index 0000000000..2eef878f17 --- /dev/null +++ b/challenge-115/donald-hunter/README @@ -0,0 +1 @@ +Solutions by Donald Hunter. diff --git a/challenge-115/doug-schrag/README b/challenge-115/doug-schrag/README new file mode 100644 index 0000000000..bf8a10ffb4 --- /dev/null +++ b/challenge-115/doug-schrag/README @@ -0,0 +1 @@ +Solution by Doug Schrag diff --git a/challenge-115/dracos/README b/challenge-115/dracos/README new file mode 100644 index 0000000000..a9a6517a03 --- /dev/null +++ b/challenge-115/dracos/README @@ -0,0 +1 @@ +Solutions by Matthew Somerville. diff --git a/challenge-115/duane-powell/README b/challenge-115/duane-powell/README new file mode 100644 index 0000000000..3445422743 --- /dev/null +++ b/challenge-115/duane-powell/README @@ -0,0 +1 @@ +Solutions by Duane Powell. diff --git a/challenge-115/duncan-c-white/README b/challenge-115/duncan-c-white/README new file mode 100644 index 0000000000..de73e12315 --- /dev/null +++ b/challenge-115/duncan-c-white/README @@ -0,0 +1,42 @@ +Task 1: "Next Palindrome Number + +You are given a positive integer $N. + +Write a script to find out the next Palindrome Number higher than the given integer $N. + +Example + + Input: $N = 1234 + Output: 1331 + + Input: $N = 999 + Output: 1001 +" + +My notes: sounds very simple. Generate and test for palindromic-ness. + + +Task 2: "Higher Integer Set Bits + +You are given a positive integer $N. + +Write a script to find the next higher integer having the same number +of 1 bits in binary representation as $N. + +Example + +Input: $N = 3 +Output: 5 + +Binary representation of 3 is 011. There are two 1 bits. So the next +higher integer is 5 having the same the number of 1 bits i.e. 101. + +Input: $N = 12 +Output: 17 + +Binary representation of 12 is 1100. There are two 1 bits. So the next +higher integer is 17 having the same number of 1 bits i.e. 10001. +" + +My notes: also sounds pretty simple. Generate and test for "having B +bits set in the binary representation". diff --git a/challenge-115/e-choroba/README b/challenge-115/e-choroba/README new file mode 100644 index 0000000000..efff637bcb --- /dev/null +++ b/challenge-115/e-choroba/README @@ -0,0 +1 @@ +Solutions by E. Choroba. diff --git a/challenge-115/eddy-hs/README b/challenge-115/eddy-hs/README new file mode 100644 index 0000000000..0ed51d222d --- /dev/null +++ b/challenge-115/eddy-hs/README @@ -0,0 +1 @@ +Solution by Eddy HS diff --git a/challenge-115/fabrizio-poggi/README b/challenge-115/fabrizio-poggi/README new file mode 100644 index 0000000000..3c17b29182 --- /dev/null +++ b/challenge-115/fabrizio-poggi/README @@ -0,0 +1 @@ +Solutions by Fabrizio Poggi. diff --git a/challenge-115/feng-chang/README b/challenge-115/feng-chang/README new file mode 100644 index 0000000000..74e56de3ed --- /dev/null +++ b/challenge-115/feng-chang/README @@ -0,0 +1 @@ +Solutions by Feng Chang. diff --git a/challenge-115/finanalyst/README b/challenge-115/finanalyst/README new file mode 100644 index 0000000000..15f7652e32 --- /dev/null +++ b/challenge-115/finanalyst/README @@ -0,0 +1 @@ +Solution by Richard Hainsworth, aka finanalyst diff --git a/challenge-115/finley/README b/challenge-115/finley/README new file mode 100644 index 0000000000..f08a121076 --- /dev/null +++ b/challenge-115/finley/README @@ -0,0 +1 @@ +Solution by Finley diff --git a/challenge-115/fjwhittle/README b/challenge-115/fjwhittle/README new file mode 100644 index 0000000000..7dcc95e189 --- /dev/null +++ b/challenge-115/fjwhittle/README @@ -0,0 +1 @@ +Solution by Francis Whittle diff --git a/challenge-115/frankivo/README b/challenge-115/frankivo/README new file mode 100644 index 0000000000..681b15b36c --- /dev/null +++ b/challenge-115/frankivo/README @@ -0,0 +1 @@ +Solution by Frank Oosterhuis. diff --git a/challenge-115/fred-zinn/README b/challenge-115/fred-zinn/README new file mode 100644 index 0000000000..17bac4f094 --- /dev/null +++ b/challenge-115/fred-zinn/README @@ -0,0 +1 @@ +Solution by Fred Zinn diff --git a/challenge-115/freddie-b/README b/challenge-115/freddie-b/README new file mode 100644 index 0000000000..823d7474b5 --- /dev/null +++ b/challenge-115/freddie-b/README @@ -0,0 +1 @@ +Solution by Freddie B diff --git a/challenge-115/garrett-goebel/README b/challenge-115/garrett-goebel/README new file mode 100644 index 0000000000..a8aa246dbb --- /dev/null +++ b/challenge-115/garrett-goebel/README @@ -0,0 +1 @@ +Solution by Garrett Goebel diff --git a/challenge-115/giuseppe-terlizzi/README b/challenge-115/giuseppe-terlizzi/README new file mode 100644 index 0000000000..0bff2a945c --- /dev/null +++ b/challenge-115/giuseppe-terlizzi/README @@ -0,0 +1 @@ +Solutions by Giuseppe Di Terlizzi. diff --git a/challenge-115/gugod/README b/challenge-115/gugod/README new file mode 100644 index 0000000000..509fd4c50c --- /dev/null +++ b/challenge-115/gugod/README @@ -0,0 +1 @@ +Solutions by Kang-min Liu. diff --git a/challenge-115/gugod/rust/.gitignore b/challenge-115/gugod/rust/.gitignore new file mode 100644 index 0000000000..ac77297bfe --- /dev/null +++ b/challenge-115/gugod/rust/.gitignore @@ -0,0 +1,2 @@ +ch-1 +ch-2 diff --git a/challenge-115/guillermo-ramos/README b/challenge-115/guillermo-ramos/README new file mode 100644 index 0000000000..a39eb01bff --- /dev/null +++ b/challenge-115/guillermo-ramos/README @@ -0,0 +1 @@ +Solution by Guillermo Ramos. diff --git a/challenge-115/gustavo-chaves/README b/challenge-115/gustavo-chaves/README new file mode 100644 index 0000000000..a66bbbf8a3 --- /dev/null +++ b/challenge-115/gustavo-chaves/README @@ -0,0 +1 @@ +Solution by Gustavo Chaves diff --git a/challenge-115/hatorikibble/README b/challenge-115/hatorikibble/README new file mode 100644 index 0000000000..51a9cd4411 --- /dev/null +++ b/challenge-115/hatorikibble/README @@ -0,0 +1 @@ +Solution by Peter Mayr diff --git a/challenge-115/hauke-d/README b/challenge-115/hauke-d/README new file mode 100644 index 0000000000..e201aa0abc --- /dev/null +++ b/challenge-115/hauke-d/README @@ -0,0 +1 @@ +Solutions by Hauke Dämpfling. diff --git a/challenge-115/henry-wong/README b/challenge-115/henry-wong/README new file mode 100644 index 0000000000..3d63a6f0be --- /dev/null +++ b/challenge-115/henry-wong/README @@ -0,0 +1 @@ +Solution by Henry Wong diff --git a/challenge-115/hstejas/README b/challenge-115/hstejas/README new file mode 100644 index 0000000000..969c5c0569 --- /dev/null +++ b/challenge-115/hstejas/README @@ -0,0 +1 @@ +Solution by Tejas diff --git a/challenge-115/ianrifkin/README b/challenge-115/ianrifkin/README new file mode 100644 index 0000000000..2d26297fb9 --- /dev/null +++ b/challenge-115/ianrifkin/README @@ -0,0 +1 @@ +Solution by Ian Rifkin. \ No newline at end of file diff --git a/challenge-115/izifresh/README b/challenge-115/izifresh/README new file mode 100644 index 0000000000..aedce7c408 --- /dev/null +++ b/challenge-115/izifresh/README @@ -0,0 +1 @@ +Solution by izifresh \ No newline at end of file diff --git a/challenge-115/jacques-guinnebault/README b/challenge-115/jacques-guinnebault/README new file mode 100644 index 0000000000..9d3e7c037f --- /dev/null +++ b/challenge-115/jacques-guinnebault/README @@ -0,0 +1 @@ +Solution by Jacques Guinnebault. diff --git a/challenge-115/jaime/README b/challenge-115/jaime/README new file mode 100644 index 0000000000..007cb58459 --- /dev/null +++ b/challenge-115/jaime/README @@ -0,0 +1,59 @@ +# Task #1 + +Write a script to display months from the year 1900 to 2019 where you +find 5 weekends i.e. 5 Friday, 5 Saturday and 5 Sunday. + +## Solution + +Months that contain five full weekends have 31 days and start on a Friday. Use `cal` to display March 2019 as an example. + +``` +#$ cal -h -m 3 2019 # cal is a UNIX utility + March 2019 +Su Mo Tu We Th Fr Sa + 1 2 + 3 4 5 6 7 8 9 +10 11 12 13 14 15 16 +17 18 19 20 21 22 23 +24 25 26 27 28 29 30 +31 +``` + +The solution runs `cal` and displays months that match this unique +layout. + +# Task #2 + +Write a script that can wrap the given paragraph at a specified column +using the greedy algorithm. + +A simple way to do word wrapping is to use a greedy algorithm that +puts as many words on a line as possible, then moving on to the next +line to do the same until there are no more words left to place. This +method is used by many modern word processors, such as OpenOffice.org +Writer and Microsoft Word[citation needed]. This algorithm always uses +the minimum possible number of lines but may lead to lines of widely +varying lengths. The following pseudocode implements this algorithm: + +``` +SpaceLeft := LineWidth +for each Word in Text + if (Width(Word) + SpaceWidth) > SpaceLeft + insert line break before Word in Text + SpaceLeft := LineWidth - Width(Word) + else + SpaceLeft := SpaceLeft - (Width(Word) + SpaceWidth) +``` + +Where LineWidth is the width of a line, SpaceLeft is the remaining +width of space on the line to fill, SpaceWidth is the width of a +single space character, Text is the input text to iterate over and +Word is a word in this text. + +## Solution + +The solution follows the recommended pseudocode. Minor improvements +avoid trailing whitespace. + +The script uses `Text::ParseWords::shellwords` from the standard +library to extract chunks of words from ``. diff --git a/challenge-115/jaldhar-h-vyas/README b/challenge-115/jaldhar-h-vyas/README new file mode 100644 index 0000000000..7dce927eca --- /dev/null +++ b/challenge-115/jaldhar-h-vyas/README @@ -0,0 +1 @@ +Solution by Jaldhar H. Vyas diff --git a/challenge-115/james-smith/README.md b/challenge-115/james-smith/README.md new file mode 100644 index 0000000000..95ca983fee --- /dev/null +++ b/challenge-115/james-smith/README.md @@ -0,0 +1,239 @@ +# Perl Weekly Challenge #114 + +# What no regexs or loops.... + +You can find more information about this weeks, and previous weeks challenges at: + + https://perlweeklychallenge.org/ + +If you are not already doing the challenge - it is a good place to practise your +**perl** or **raku**. If it is not **perl** or **raku** you develop in - you can +submit solutions in whichever language you feel comfortable with. + +You can find the solutions here on github at: + +https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-114/james-smith/perl + +# Challenge 1 - Next highest palindrome + +***You are given a positive integer `$N`. Write a script to find out +the next Palindrome Number higher than the given integer `$N`.*** + +## The solution - naive + +We will see this again for the next challenge we just increment `$N` +until we find another palindrome. + +```perl +sub next_palindrome_naive { + my ($n) = @_; + 1 until ++$n eq reverse $n; + return $n +} +``` + +## The solution - optimized + +First we note that it is easier to compute the palindrome greater than +equal to itself {so we just incremement the passed parameter}. + +We should then be able to do away with the loop entirely as the +palindromic number will either have the same first half as itself OR +will have this value incrememented by 1 as the first half.... No loop +requried.. + +### The cases.. + +There are two cases we need to consider: + + * There are an even number of digits + * There are an odd number of digits.. + +The first case is slightly easiers as we just check to see if the +palindrome created by reversing the first digits and putting them +at the end is greater than or equal to the number, and if not +increment and try again. + +The second case is slightly more interesting as we have the middle +digit to consider. In the 2nd half above we can increment the middle +digit if (less than 9) OR incremennt the first digits.. + +```perl +sub next_palindrome { + my $p = 1 + shift; + my $x = substr $p, 0, (length $p)>>1; + if( 1 & length $p ) { + my $y = substr $p, (length$p)>>1, 1; + return $x.$y.reverse $x if $p <= $x.$y.reverse $x; + return $x.($y+1).reverse $x if $y<9; + $x++; + return $x.'0'.reverse $x; + } else { + $x++ if $p > $x.reverse $x; + return $x.reverse $x; + } +} +``` + +## Notes and Summary + +You will note I've used the "Yoda" form of some of the expressions +inequalities. It is much easier for instance to realise that: +`1 & length $p` is "and"ing `1` with the length of `$p` rather than +"and"ing `1` with `$p` and then taking the length (which will be 1) if +you were to write `length $p & 1`... + +There were some cases where I thought assigning the result of +`reverse$x` and `length$p` would speed things up - but it seemed to +slow things down by 10% or so - So I'm assuming there is some neat +code in the interpreter/compiler does this cacheing for you. + +For small numbers of `$N` there is little difference in the performance +15% - but as soon as numbers are up to 3/4 digits then the optimised +version is 6 times faster, for 5/6 digits 80 times faster, for 7/8 +approximately 1000 times faster... + +# Challenge 2 - Higher Integer Set Bits + +***You are given a positive integer `$N`. Write a script to find +the next higher integer having the same number of 1 bits in binary +representation as `$N`.*** + + +## The solution - naive + +There is a simple solution we can try - and that is to take the number, +count the number of 1-bits, and then just increment repeatedly until we +get a number with the same amount of 1-bits. + +```perl +sub next_bin { + my $n = shift; + my $c = (sprintf '%b', $n) =~ tr/1/1/; + while(++$n) { + return $n if $c == ( (sprintf '%b', $n) =~ tr/1/1/ ); + } +} +``` + + * We convert the number to binary using sprintf with the format `'%b'`; + * We count the number of "1"s in the string using `tr`. `tr/1/1/` leaves + the string unchanged but returns the number of "1"s that were replaced. + +## The solution - optimized + +We can easily find a solution to this problem. + +If the number contains a pair of digits "01" then we can find a number +that is larger but has the same number of digits by swapping the "01" to "10". +(Note we can force the binary representation to always have a "01" by prefixing +the binary representation with "0") + +So e.g. `174 = 1010 1110` - you can replace either of the `01`s to give either: + + * `1100 1110 = 206` + * `1011 0110 = 182` + +We note that to minimize the number we start by replacing the last `01` by `10` + +So we have: `182 = 1011 0110 > 174 = 1010 1100` + +The digits after the last `01` will be of the form `1...10..0`, so we can again +reduce the value by flipping this string around to be `0...01...1`; + +So now we have: `179 = 1011 0011 > 174 = 1010 110` + +The code then becomes either: + +```perl +sub next_bin_rex { + return oct '0b'.sprintf('0%b',shift) =~ s{01(1*)(0*)$}{10$2$1}r; +} +``` +or + +```perl +sub next_bin_rrev { + my $t = rindex my $s = sprintf('0%b',shift),'01'; + return oct '0b'.substr($s,0,$t).'10'.reverse substr $s,$t+2; +} +``` + +depending on whether or not you use a regular expression to find +the last "`01`" in the binary representaiton. + +## The solution - with go faster stripes... + +After a discussion on facebook with Eliza Skr, about whether or not +to use regexs rather than `rindex` she supplied a different algorithm +for finding the next number - which didn't involve manipulating the +binary string but by working out the arithmetic to make the changes. + + * The number is of the form is `0 1111 00000000` + * The next hightest number is `1 000000000 111` + * To map `0 1111 00000000` to `1 000000000 000` we need to add + `1 00000000` (which is 2^#zeros) + * To map `1 000000000 000` to `1 000000000 111` we need to add `111` + which is 2^(#ones -1) -1 + +Eliza's solution was to obtain counts of `0`s and `1`s using a simple +regex `/(1+)(0*)$/` which works - but is still a regular expression, +which as we discussed above is a slow operation. + +We can replace this again with using `rindex`... Also rather than +using `2**$n` we replace it with the much quicker bit-shift operator +`1<<$n` - which achieves the same effect. + +This gives us: + +```perl +sub next_bin_rin