diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2021-06-16 21:13:20 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2021-06-16 21:13:20 +0800 |
| commit | 5e631f4b325d6ef41562ec1ef955e49e7da4ab75 (patch) | |
| tree | 77cd0ba501ebc5d0c0fcb36764e55c98b4869b3c /challenge-116 | |
| parent | 1dd7eedea237292a3fb563ecff37d004c3bbc772 (diff) | |
| parent | 0aa46d7e327eb82bd447279a1891f0d1873c46ff (diff) | |
| download | perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.tar.gz perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.tar.bz2 perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-116')
107 files changed, 3781 insertions, 108 deletions
diff --git a/challenge-116/abigail/README.md b/challenge-116/abigail/README.md index 96adeb6d8f..eccf1a6b3b 100644 --- a/challenge-116/abigail/README.md +++ b/challenge-116/abigail/README.md @@ -1,27 +1,29 @@ # Solutions by Abigail -## [String Chain](https://perlweeklychallenge.org/blog/perl-weekly-challenge-115/#TASK1) +## [Number Sequence](https://perlweeklychallenge.org/blog/perl-weekly-challenge-116/#TASK1) -> You are given an array of strings. +> You are given a number `$N` >= `10`. > -> Write a script to find out if the given strings can be chained -> to form a circle. Print `1` if found otherwise `0`. -> -> > A string `$S` can be put before another string `$T` in circle -> > if the last character of `$S` is same as first character of `$T`. +> Write a script to split the given number such that the difference +> between two consecutive numbers is always 1 and it shouldn't have +> leading `0`. +> +> Print the given number if it impossible to split the number. ### Example ~~~~ -Input: @S = ("abc", "dea", "cd") -Output: 1 as we can form circle e.g. "abc", "cd", "dea". +Input: $N = 1234 +Output: 1,2,3,4 + +Input: $N = 91011 +Output: 9,10,11 -Input: @S = ("ade", "cbd", "fgh") -Output: 0 as we can't form circle. +Input: $N = 10203 +Output: 10203 as it is impossible to split satisfying the conditions. ~~~~ ### Solutions * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) -* [C](c/ch-1.c) * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) @@ -29,25 +31,26 @@ Output: 0 as we can't form circle. * [Ruby](ruby/ch-1.rb) ### Blog -[String Chain](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-115-1.html) +[Number Sequence](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-116-1.html) -## [Largest Multiple](https://perlweeklychallenge.org/blog/perl-weekly-challenge-115/#TASK2) +## [Sum of Squares](https://perlweeklychallenge.org/blog/perl-weekly-challenge-115/#TASK2) -> You are given a list of positive integers `(0-9)`, single digit. +> You are given a number $N >= 10. > -> Write a script to find the largest multiple of `2` that can be -> formed from the list. +> Write a script to find out if the given number `$N` is such that +> sum of squares of all digits is a perfect square. +> Print `1` if it is otherwise `0`. ### Examples ~~~~ -Input: @N = (1, 0, 2, 6) -Output: 6210 +Input: $N = 34 +Ouput: 1 as 3^2 + 4^2 => 9 + 16 => 25 => 5^2 -Input: @N = (1, 4, 2, 8) -Output: 8412 +Input: $N = 50 +Output: 1 as 5^2 + 0^2 => 25 + 0 => 25 => 5^2 -Input: @N = (4, 1, 7, 6) -Output: 7614 +Input: $N = 52 +Output: 0 as 5^2 + 2^2 => 25 + 4 => 29 ~~~~ ### Solutions @@ -61,4 +64,4 @@ Output: 7614 * [Ruby](ruby/ch-2.rb) ### Blog -[Largest Multiple](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-115-2.html) +[Sum of Squares](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-116-2.html) diff --git a/challenge-116/abigail/awk/ch-1.awk b/challenge-116/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..5e0379efb8 --- /dev/null +++ b/challenge-116/abigail/awk/ch-1.awk @@ -0,0 +1,37 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +function make_sequence (string, start) { + if (start == string) { + return start + } + if (1 == index (string, start)) { + tail = substr (string, length (start) + 1) + result = make_sequence(tail, start + 1) + if (result == "") { + result = make_sequence(tail, start - 1) + } + if (result == "") { + return "" + } + return start "," result + } + return "" +} + +{ + for (i = 1; i <= length ($1); i ++) { + result = make_sequence($1, substr ($1, 1, i)) + if (result != "") { + print result + next + } + } +} diff --git a/challenge-116/abigail/awk/ch-2.awk b/challenge-116/abigail/awk/ch-2.awk new file mode 100644 index 0000000000..6353b61eb8 --- /dev/null +++ b/challenge-116/abigail/awk/ch-2.awk @@ -0,0 +1,19 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-2.awk < input-file +# + +{ + sum_of_squares = 0 + for (i = 1; i <= length ($1); i ++) { + # Sum of squares + sum_of_squares += substr ($1, i, 1) * substr ($1, i, 1) + } |
