Skip to content

Commit

Permalink
- Added template for Challenge manwar#69.
Browse files Browse the repository at this point in the history
  • Loading branch information
manwar committed Jul 13, 2020
1 parent b116940 commit 07c76e3
Show file tree
Hide file tree
Showing 176 changed files with 487 additions and 0 deletions.
1 change: 1 addition & 0 deletions challenge-069/3ter/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by 3ter.
1 change: 1 addition & 0 deletions challenge-069/aaron-rowe/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Aaron Rowe.
1 change: 1 addition & 0 deletions challenge-069/aaron-sherman/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Aaron Sherman.
1 change: 1 addition & 0 deletions challenge-069/abigail/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Abigail
1 change: 1 addition & 0 deletions challenge-069/adam-russell/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Adam Russell
1 change: 1 addition & 0 deletions challenge-069/ailbhe-tweedie/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Ailbhe Tweedie
1 change: 1 addition & 0 deletions challenge-069/alex-daniel/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Alex Daniel.
1 change: 1 addition & 0 deletions challenge-069/alexander-karelas/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Alexander Karelas
1 change: 1 addition & 0 deletions challenge-069/alicia-bielsa/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Alicia Beilsa.
1 change: 1 addition & 0 deletions challenge-069/andrezgz/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Andrezgz
1 change: 1 addition & 0 deletions challenge-069/anton-fedotov/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Anton Fedotov.
1 change: 1 addition & 0 deletions challenge-069/antonio-gamiz/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Antonio Gamiz
1 change: 1 addition & 0 deletions challenge-069/arne-sommer/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Arne Sommer.
1 change: 1 addition & 0 deletions challenge-069/arpad-toth/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Arpad Toth
3 changes: 3 additions & 0 deletions challenge-069/ash/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Solution by Andrew Shitov

Comments to the task 1: https://andrewshitov.com/2020/07/06/raku-challenge-week-68/
1 change: 1 addition & 0 deletions challenge-069/athanasius/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Athanasius
1 change: 1 addition & 0 deletions challenge-069/aubrey-quarcoo/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Aubrey Quarcoo
11 changes: 11 additions & 0 deletions challenge-069/ben-davies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Solution by Ben Davies

# Using the Solutions

- Install
[Idris](https://github.com/idris-lang/Idris-dev/wiki/Installation-Instructions)
and ensure its executable is in your path.
- Run `$ make -j2`. The executables for the challenges will be output to
`./ch-1` and `./ch-2`.
- Run `$ make clean` to remove compiled objects or `$ make distclean` to
remove the executables as well, if you wish.
1 change: 1 addition & 0 deletions challenge-069/bill-palmer/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Bill Palmer.
1 change: 1 addition & 0 deletions challenge-069/bob-kleemann/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Bob Kleemann
1 change: 1 addition & 0 deletions challenge-069/brtastic/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Bartosz Jarzyna.
1 change: 1 addition & 0 deletions challenge-069/bruno-ramos/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Bruno Ramos.
1 change: 1 addition & 0 deletions challenge-069/burkhard-nickels/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Burkhard Nickels.
1 change: 1 addition & 0 deletions challenge-069/bwva/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution(s) by bwva (Bruce Van Allen)
1 change: 1 addition & 0 deletions challenge-069/cheok-yin-fung/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Cheok-Yin Fung.
1 change: 1 addition & 0 deletions challenge-069/cliveholloway/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Clive Holloway
1 change: 1 addition & 0 deletions challenge-069/colin-crain/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Colin Crain.
1 change: 1 addition & 0 deletions challenge-069/craig/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Craig.
1 change: 1 addition & 0 deletions challenge-069/creewick/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Creewick.
1 change: 1 addition & 0 deletions challenge-069/cristian-heredia/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Cristina Heredia.
1 change: 1 addition & 0 deletions challenge-069/daniel-mantovani/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Daniel Mantovani
1 change: 1 addition & 0 deletions challenge-069/daniel-mita/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Daniel Mita
1 change: 1 addition & 0 deletions challenge-069/darren-bottin/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Darren Bottin.
1 change: 1 addition & 0 deletions challenge-069/dave-cross/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Dave Cross
1 change: 1 addition & 0 deletions challenge-069/dave-jacoby/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Dave Jacoby
1 change: 1 addition & 0 deletions challenge-069/david-kayal/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by David Kayal
1 change: 1 addition & 0 deletions challenge-069/denis-yurashku/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Denis Yurashku.
1 change: 1 addition & 0 deletions challenge-069/donald-hunter/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Donald Hunter.
1 change: 1 addition & 0 deletions challenge-069/doug-schrag/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Doug Schrag
1 change: 1 addition & 0 deletions challenge-069/dracos/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Matthew Somerville.
1 change: 1 addition & 0 deletions challenge-069/duane-powell/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Duane Powell.
41 changes: 41 additions & 0 deletions challenge-069/duncan-c-white/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Task 1: "Number Combinations

You are given two integers $m and $n. Write a script print all possible
combinations of $n numbers from the list 1 2 3 ... $m.

Every combination should be sorted i.e. [2,3] is a valid combination but
[3,2] is not.

Example:

Input: $m = 5, $n = 2

Output: [ [1,2], [1,3], [1,4], [1,5], [2,3], [2,4], [2,5], [3,4], [3,5], [4,5] ]
"

My notes: generally I hate permutation questions, but this looks ok.


Task 2: "Letter Phone

You are given a digit string $S. Write a script to print all possible letter combinations that the given digit string could represent.

(1 represents _ or @,
2 A,B or C,
3 D,E or F,
4 G, H or I,
5 J, K or L,
6 M, M or O,
7 P, Q, R or S,
8 T, U or V,
9 W, X, Y or Z
letters from a phone panel)

Example:

Input: $S = '35'

Output: ["dj", "dk", "dl", "ej", "ek", "el", "fj", "fk", "fl"].

My notes: sounds pretty easy. Lookup the set of possibilities for each
letter, then cross-product them.
1 change: 1 addition & 0 deletions challenge-069/e-choroba/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by E. Choroba.
1 change: 1 addition & 0 deletions challenge-069/eddy-hs/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Eddy HS
1 change: 1 addition & 0 deletions challenge-069/fabrizio-poggi/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Fabrizio Poggi.
1 change: 1 addition & 0 deletions challenge-069/feng-chang/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Feng Chang.
1 change: 1 addition & 0 deletions challenge-069/finanalyst/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Richard Hainsworth, aka finanalyst
1 change: 1 addition & 0 deletions challenge-069/finley/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Finley
1 change: 1 addition & 0 deletions challenge-069/fjwhittle/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Francis Whittle
1 change: 1 addition & 0 deletions challenge-069/fred-zinn/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Fred Zinn
1 change: 1 addition & 0 deletions challenge-069/freddie-b/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Freddie B
1 change: 1 addition & 0 deletions challenge-069/giuseppe-terlizzi/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Giuseppe Di Terlizzi.
1 change: 1 addition & 0 deletions challenge-069/guillermo-ramos/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Guillermo Ramos.
1 change: 1 addition & 0 deletions challenge-069/gustavo-chaves/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Gustavo Chaves
1 change: 1 addition & 0 deletions challenge-069/hauke-d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Hauke Dämpfling.
1 change: 1 addition & 0 deletions challenge-069/ianrifkin/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Ian Rifkin.
1 change: 1 addition & 0 deletions challenge-069/izifresh/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by izifresh
1 change: 1 addition & 0 deletions challenge-069/jacques-guinnebault/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jacques Guinnebault.
59 changes: 59 additions & 0 deletions challenge-069/jaime/README
Original file line number Diff line number Diff line change
@@ -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 `<STDIN>`.
1 change: 1 addition & 0 deletions challenge-069/jaldhar-h-vyas/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jaldhar H. Vyas
129 changes: 129 additions & 0 deletions challenge-069/james-smith/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
Solutions by James Smith.

# Challenge 1 - Counting letters

There are two ways to solve this -> split and count or using tr... one is short code - one is longer - but much faster.

## Version 1 - short code

Uses lc, split and grep to count the elements and put them in a hash... looping through each file a line at a time with <>

```perl
use feature 'say';
use strict;
my %T = map { $_=>0 } foreach 'a'..'z';
while(<>) {
$T{$_}++ foreach grep { /[a-z]/ } split m{}, lc $_;
}

say "$_: $T{$_}" foreach 'a'..'z';
```

Running this over 13Mbytes of PHP takes approximately 6.5 seconds...

## Version 2 - faster code

Now counting letters in a string is quickest using the tr or y operator - as this requires the number of characters
changed. Without using eval you can't unfortunately sub in a variable into the pattern unlike with m/s... So we
either need to use string eval (which is evIl) or manually replicate the loop - $T{'a'} =~ y/aA/aA/ etc - in this
code... Note we set $/ to undef so that we slurp the whole file in in one go (to improve performance of using tr)
and less modifications to the %T hash...

```perl
use feature 'say';
$/=undef;

while(<>) {
$T{'a'} += y/aA/aA/;
$T{'b'} += y/bB/bB/;
..
..
$T{'y'} += y/yY/yY/;
$T{'z'} += y/zZ/zZ/;
}

say $_,': ',$T{$_}||0 foreach 'a'..'z';

```
OK - so didn't want to type 26 lines so used this one liner to do it for me!

```bash
perl -E 'say " \$t{'"'"'$_'"'"'} += y/$_".uc($_)."/$_".uc($_)."/;" foreach "a".."z";'
```

This now runs in approxy 0.25 seconds a big improvement...

## Version 3 - nicer output...

The version 3 code just expands the version 2 code - but creates a "histogram" to show the distribution (and at the same time formats the totals better)

```
a : 584193 : ##########################
b : 108267 : ####
c : 287124 : #############
d : 272798 : ############
e : 877936 : ########################################
f : 209371 : #########
g : 152944 : ######
h : 200641 : #########
i : 546465 : ########################
j : 15133 :
k : 50049 : ##
l : 326976 : ##############
m : 214631 : #########
n : 438874 : ###################
o : 436059 : ###################
p : 282120 : ############
q : 19825 :
r : 551144 : #########################
s : 552344 : #########################
t : 724711 : #################################
u : 260233 : ###########
v : 68882 : ###
w : 80759 : ###
x : 57019 : ##
y : 115201 : #####
z : 11021 :
```

# Challenge 2 - multiplication square...

Again going to extend the challenge to make this generic (in case someone wants a different version)

Hidden in the solution above was getting the number of digits for a number (so we can format the totals) - we do this again to get the size of the left hand column and the main table columns.

```perl
my $sl = int(log($N)/log(10)+1); ## Get size of integer $N - defines the width of the LH column
my $sr = int(2*log($N)/log(10)+1); ## Get size of $N squared - defines the width of other columns
```
and we use this to tweak the formats and the padding/line drawing elements!
```perl
#!/usr/bin/perl

use strict;
use feature 'say';

## This solves more than the puzzle - but thought I would make it more generic!

## This gets the size of the square that we want to display...

my $N = shift =~ s{\D}{}gr || 11; ## Default to 11 - but use first parameter as size of square!
my @R = 1..$N; ## Create a "range array" - we use this 4 times!!!

## Get width of columns for use in the renderer..

my $sl = int( log($N) / log(10) + 1); ## Get size of integer $N - defines the width of the LH column
my $sr = int( 2 * log($N) / log(10) + 1); ## Get size of $N squared - defines the width of other columns
my $fl = sprintf ' %%%dd |', $sl; ## Create a template for the first column..
my $fr = sprintf ' %%%dd', $sr; ## .... and for the other columns!

## Finally we render - make a use of sprintf with the templates and '$' x $ to generate padding

say ' ' x $sl, 'x |', ## Header (LH side)
map { sprintf $fr, $_ } @R; ## (column headers)
say join '-', '-' x $sl, '-+', ## Separator (LH side)
map { '-' x $sr } @R; ## (RH side)
say sprintf( $fl, $a=$_ ), ## Body of table (LH headers)
map { $a>$_ ? ' ' x ($sr+1) : sprintf $fr, $a*$_ } @R ## (content of row)
foreach @R;
```
1 change: 1 addition & 0 deletions challenge-069/jaredor/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jared Martin
1 change: 1 addition & 0 deletions challenge-069/javier-luque/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Javier Luque.
1 change: 1 addition & 0 deletions challenge-069/jeff/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jeff
1 change: 1 addition & 0 deletions challenge-069/jeongoon/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Myoungjin Jeon
1 change: 1 addition & 0 deletions challenge-069/jeremy-carman/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jeremy Carman
1 change: 1 addition & 0 deletions challenge-069/jim-bacon/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jim Bacon
1 change: 1 addition & 0 deletions challenge-069/jitu-keshwani/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Jitu Keshwani.
1 change: 1 addition & 0 deletions challenge-069/jj-merelo/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by JJ Merelo
1 change: 1 addition & 0 deletions challenge-069/jo-37/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jo S.
1 change: 1 addition & 0 deletions challenge-069/jo-christian-oterhals/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jo Christian Oterhals
1 change: 1 addition & 0 deletions challenge-069/joe-tym/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Joe Tym.
1 change: 1 addition & 0 deletions challenge-069/joelle-maslak/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Joelle Maslak
1 change: 1 addition & 0 deletions challenge-069/john-barrett/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by John Barrett
1 change: 1 addition & 0 deletions challenge-069/jokraft/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Jan Ole Kraft.
1 change: 1 addition & 0 deletions challenge-069/juan-caballero/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Juan Caballero
1 change: 1 addition & 0 deletions challenge-069/julien-fiegehenn/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Julien Fiegehenn.
3 changes: 3 additions & 0 deletions challenge-069/kevin-colyer/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Solutions by Kevin Colyer.

I think there is some odd bug - my initial tries at rotating the matrix affected the original matrix even when I DIDN'T specify is rw in the sub.
1 change: 1 addition & 0 deletions challenge-069/khalid/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solution by Khalid
Loading

0 comments on commit 07c76e3

Please sign in to comment.