aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-160/lubos-kolouch/perl/ch-1.pl36
-rw-r--r--challenge-160/lubos-kolouch/perl/ch-2.pl29
-rw-r--r--challenge-160/lubos-kolouch/python/ch-1.py27
-rw-r--r--challenge-160/lubos-kolouch/python/ch-2.py20
4 files changed, 112 insertions, 0 deletions
diff --git a/challenge-160/lubos-kolouch/perl/ch-1.pl b/challenge-160/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..0f29c79d59
--- /dev/null
+++ b/challenge-160/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,36 @@
+package main;
+use strict;
+use warnings;
+use Lingua::EN::Numbers qw(num2en);
+
+sub four_magic {
+ my $what = shift;
+
+ my @output;
+
+ while (1) {
+ my $new_num = length( num2en($what) );
+
+ if ( $what == 4 ) {
+ push @output, num2en($what) . " is magic.";
+ last;
+ }
+ push @output, num2en($what) . " is " . num2en($new_num);
+ $what = $new_num;
+ }
+
+ my $out_str = join ", ", @output;
+ $out_str =~ s/(^.)/\U$1/msx;
+
+ return $out_str;
+}
+
+use Test::More;
+
+is( four_magic(5), "Five is four, four is magic.", 'Test 5' );
+is( four_magic(7), "Seven is five, five is four, four is magic.", 'Test 7' );
+is( four_magic(6),
+ "Six is three, three is five, five is four, four is magic.",
+ 'Test 6' );
+done_testing;
+1;
diff --git a/challenge-160/lubos-kolouch/perl/ch-2.pl b/challenge-160/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..928b29bdbb
--- /dev/null
+++ b/challenge-160/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,29 @@
+package main;
+use strict;
+use warnings;
+use List::Util qw/sum/;
+
+sub get_eq_index {
+ my @what = @_;
+
+ my $elem_count = scalar @what;
+
+ for my $i ( 1 .. $elem_count - 2 ) {
+ if ( sum( @what[ 0 .. $i - 1 ] )
+ == sum( @what[ $i + 1 .. $elem_count - 1 ] ) )
+ {
+ return $i;
+ }
+ }
+
+ return -1;
+}
+
+use Test::More;
+is( get_eq_index( 1, 3, 5, 7, 9 ), 3, 'Test 1 3 5 7 9' );
+is( get_eq_index( 1, 2, 3, 4, 5 ), -1, 'Test 1 2 3 4 5 ' );
+is( get_eq_index( 2, 4, 2 ), 1, 'Test 2 4 2' );
+
+is( get_eq_index(2), -1, 'Test 2' );
+done_testing;
+1;
diff --git a/challenge-160/lubos-kolouch/python/ch-1.py b/challenge-160/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..9103fe6c84
--- /dev/null
+++ b/challenge-160/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,27 @@
+""" Challenge 160 Task 1"""
+
+from num2words import num2words
+
+
+def four_magic(what: int) -> str:
+ """Do the conversion magic"""
+
+ output = []
+
+ while 1:
+ new_num = len(num2words(what))
+
+ if what == 4:
+ output.append(num2words(what) + " is magic.")
+ break
+ output.append(num2words(what) + " is " + num2words(new_num))
+ what = new_num
+
+ out_str = ", ".join(output)
+
+ return out_str.capitalize()
+
+
+assert four_magic(5) == "Five is four, four is magic."
+assert four_magic(7) == "Seven is five, five is four, four is magic."
+assert four_magic(6) == "Six is three, three is five, five is four, four is magic."
diff --git a/challenge-160/lubos-kolouch/python/ch-2.py b/challenge-160/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..dd95012303
--- /dev/null
+++ b/challenge-160/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,20 @@
+""" Challenge 160 Task 2 """
+
+
+def get_eq_index(what: list) -> int:
+ """Get the Equilibrium Index"""
+
+ elem_count = len(what)
+
+ for i in range(1, elem_count - 1):
+ if sum(what[0:i]) == sum(what[i + 1 : elem_count]):
+ return i
+
+ return -1
+
+
+assert get_eq_index([1, 3, 5, 7, 9]) == 3
+assert get_eq_index([1, 2, 3, 4, 5]) == -1
+assert get_eq_index([2, 4, 2]) == 1
+
+assert get_eq_index([2]) == -1