forked from manwar/perlweeklychallenge-club
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added template for Challenge manwar#69.
- Loading branch information
Showing
176 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by 3ter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Aaron Rowe. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Aaron Sherman. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Abigail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Adam Russell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Ailbhe Tweedie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Alex Daniel. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Alexander Karelas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Alicia Beilsa. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Andrezgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Anton Fedotov. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Antonio Gamiz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Arne Sommer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Arpad Toth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Athanasius |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Aubrey Quarcoo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Bill Palmer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Bob Kleemann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Bartosz Jarzyna. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Bruno Ramos. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Burkhard Nickels. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution(s) by bwva (Bruce Van Allen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Cheok-Yin Fung. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Clive Holloway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Colin Crain. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Craig. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Creewick. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Cristina Heredia. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Daniel Mantovani |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Daniel Mita |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Darren Bottin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Dave Cross |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Dave Jacoby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by David Kayal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Denis Yurashku. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Donald Hunter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Doug Schrag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Matthew Somerville. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Duane Powell. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by E. Choroba. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Eddy HS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Fabrizio Poggi. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Feng Chang. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Richard Hainsworth, aka finanalyst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Finley |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Francis Whittle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Fred Zinn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Freddie B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Giuseppe Di Terlizzi. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Guillermo Ramos. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Gustavo Chaves |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Hauke Dämpfling. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Ian Rifkin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by izifresh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jacques Guinnebault. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jaldhar H. Vyas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jared Martin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Javier Luque. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jeff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Myoungjin Jeon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jeremy Carman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jim Bacon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Jitu Keshwani. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by JJ Merelo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jo S. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jo Christian Oterhals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Joe Tym. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Joelle Maslak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by John Barrett |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Jan Ole Kraft. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Juan Caballero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Julien Fiegehenn. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solution by Khalid |
Oops, something went wrong.