From 72befa7c5d2de9e9a9029baccb6d49d81b5dd9db Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 11 May 2020 08:27:44 +0200 Subject: Task 1 done. --- challenge-060/luca-ferrari/raku/ch-1.p6 | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 challenge-060/luca-ferrari/raku/ch-1.p6 diff --git a/challenge-060/luca-ferrari/raku/ch-1.p6 b/challenge-060/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..f052ce5bb4 --- /dev/null +++ b/challenge-060/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,52 @@ +#!env raku + +# Write a script that accepts a number and returns the Excel Column Name it represents and vice-versa. + +# Excel columns start at A and increase lexicographically +# using the 26 letters of the English alphabet, +# A..Z. After Z, the columns pick up an extra “digit”, +# going from AA, AB, etc., +# which could (in theory) continue to an arbitrary number of digits. +# In practice, Excel sheets are limited to 16,384 columns. +# +# +# Example +# Input Number: 28 Output: AB +# Input Column Name: AD Output: 30 + + + +sub MAIN( $what ) { + my @letters = 'A' .. 'Z'; + my @column-name; + + + # numeric value to be converted into a letter + if $what ~~ Int && $what > 0 && $what <= 16_384 { + my $column = $what.Int; + + + while ( $column > @letters.elems ) { + @column-name.push: @letters[ $column / @letters.elems - 1 ]; + $column = $column % @letters.elems; + } + + @column-name.push: @letters[ $column - 1 ]; + say "Cell $what is { @column-name.join }"; + } + elsif $what ~~ Str { + my $column; + my $multiplier = 0; + # string, try to find the cell number + for $what.comb.reverse -> $current_letter { + $column += @letters.first( $current_letter, :k ) + 1 + ( @letters.elems - 1 ) * $multiplier++; + } + + say "Cell $what is $column"; + } + + + + + +} -- cgit From d43a46c6e7193b40c1ea7ca38adcef829bc8f3b9 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 11 May 2020 08:46:31 +0200 Subject: Task 2 done. --- challenge-060/luca-ferrari/raku/ch-2.p6 | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 challenge-060/luca-ferrari/raku/ch-2.p6 diff --git a/challenge-060/luca-ferrari/raku/ch-2.p6 b/challenge-060/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..72d024e444 --- /dev/null +++ b/challenge-060/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,42 @@ +#!env raku + + + + +# Write a script that accepts list of positive numbers (@L) and two positive numbers $X and $Y. +# +# The script should print all possible numbers made by concatenating +# the numbers from @L, whose length is exactly $X +# but value is less than $Y. +# Example +# +# Input: +# +# @L = (0, 1, 2, 5); +# $X = 2; +# $Y = 21; +# +# Output: +# +# 10, 11, 12, 15, 20 + + + +sub MAIN ( ){ + my @L = (0, 1, 2, 5); + my $x = 2; + my $y = 21; + my @LL; + + # start from the very beginning of the list limiting + # the numbers in the range of $y + for ( 1 x $x ) - 1 ..^ $y { + + # see if the numbers "grep" the list + my $found = 0; + $found++ if $_ == any( @L ) for $_.comb; + @LL.push: $_ if $_.comb.elems == $found; + } + + say @LL.join( ', ' ); +} -- cgit From 2ba20ad6932958c5f8d4f26e88517b574a489136 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 11 May 2020 09:50:50 +0200 Subject: Blog references --- challenge-060/luca-ferrari/blog-1.txt | 1 + challenge-060/luca-ferrari/blog-2.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 challenge-060/luca-ferrari/blog-1.txt create mode 100644 challenge-060/luca-ferrari/blog-2.txt diff --git a/challenge-060/luca-ferrari/blog-1.txt b/challenge-060/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..65897b37c5 --- /dev/null +++ b/challenge-060/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2020/05/11/PerlWeeklyChallenge60.html#task1 diff --git a/challenge-060/luca-ferrari/blog-2.txt b/challenge-060/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..7fd82f71f4 --- /dev/null +++ b/challenge-060/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2020/05/11/PerlWeeklyChallenge60.html#task2 -- cgit