aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-05-24 17:42:23 +0100
committerGitHub <noreply@github.com>2023-05-24 17:42:23 +0100
commit42a066d2210210663bf7bf7dcbcbafc954839a5b (patch)
treedba28147dcf7c671b041e705d805356446f46ec8
parentf88ec70a8f56f1d4e7ecf28b0062d46b82f8b030 (diff)
parent889859b18e16b8adb5e11986d63f29e80de2e4ef (diff)
downloadperlweeklychallenge-club-42a066d2210210663bf7bf7dcbcbafc954839a5b.tar.gz
perlweeklychallenge-club-42a066d2210210663bf7bf7dcbcbafc954839a5b.tar.bz2
perlweeklychallenge-club-42a066d2210210663bf7bf7dcbcbafc954839a5b.zip
Merge pull request #8130 from LubosKolouch/master
feat(challenge-105,107/lubos-kolouch/perl,python/): Challenges 105, 107 LK Perl Python
-rw-r--r--challenge-105/lubos-kolouch/perl/ch-1.pl10
-rw-r--r--challenge-105/lubos-kolouch/perl/ch-2.pl14
-rw-r--r--challenge-105/lubos-kolouch/python/ch-1.pl6
-rw-r--r--challenge-105/lubos-kolouch/python/ch-2.py15
-rw-r--r--challenge-107/lubos-kolouch/perl/ch-1.pl28
-rw-r--r--challenge-107/lubos-kolouch/perl/ch-2.pl25
-rw-r--r--challenge-107/lubos-kolouch/python/ch-1.py26
-rw-r--r--challenge-107/lubos-kolouch/python/ch-2.py21
8 files changed, 145 insertions, 0 deletions
diff --git a/challenge-105/lubos-kolouch/perl/ch-1.pl b/challenge-105/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..985223e7ec
--- /dev/null
+++ b/challenge-105/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+
+sub nth_root {
+ my ( $n, $k ) = @_;
+ return sprintf( "%.2f", $k**( 1 / $n ) );
+}
+
+print nth_root( 5, 248832 ); # Output: 12.00
+print nth_root( 5, 34 ); # Output: 2.02
diff --git a/challenge-105/lubos-kolouch/perl/ch-2.pl b/challenge-105/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..2c84eb42de
--- /dev/null
+++ b/challenge-105/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+
+sub name_game {
+ my $name = shift;
+ my $rest_of_name = substr $name, 1;
+ print "$name, $name, bo-b$rest_of_name,\n";
+ print "Bonana-fanna fo-f$rest_of_name\n";
+ print "Fee fi mo-m$rest_of_name\n";
+ print "$name!\n";
+}
+
+name_game('Katie')
+ ; # Output: Katie, Katie, bo-batie, Bonana-fanna fo-fatie, Fee fi mo-matie, Katie!
diff --git a/challenge-105/lubos-kolouch/python/ch-1.pl b/challenge-105/lubos-kolouch/python/ch-1.pl
new file mode 100644
index 0000000000..7dd834b6d4
--- /dev/null
+++ b/challenge-105/lubos-kolouch/python/ch-1.pl
@@ -0,0 +1,6 @@
+def nth_root(n: int, k: float) -> float:
+ return round(k ** (1/n), 2)
+
+print(nth_root(5, 248832)) # Output: 12.0
+print(nth_root(5, 34)) # Output: 2.02
+
diff --git a/challenge-105/lubos-kolouch/python/ch-2.py b/challenge-105/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..bb4858f939
--- /dev/null
+++ b/challenge-105/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def name_game(name: str) -> None:
+ rest_of_name = name[1:]
+ print(f"{name}, {name}, bo-b{rest_of_name},")
+ print(f"Bonana-fanna fo-f{rest_of_name}")
+ print(f"Fee fi mo-m{rest_of_name}")
+ print(f"{name}!")
+
+
+name_game(
+ "Katie"
+) # Output: Katie, Katie, bo-batie, Bonana-fanna fo-fatie, Fee fi mo-matie, Katie!
diff --git a/challenge-107/lubos-kolouch/perl/ch-1.pl b/challenge-107/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..92d830b172
--- /dev/null
+++ b/challenge-107/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,28 @@
+sub is_self_descriptive {
+ my $num = shift;
+ my $str_num = "$num";
+ my $length = length($str_num);
+
+ for my $i ( 0 .. ( $length - 1 ) ) {
+ my $digit = substr( $str_num, $i, 1 );
+ my $count = () = $str_num =~ /\Q$i/g;
+ return 0 if $count != $digit;
+ }
+
+ return 1;
+}
+
+sub find_self_descriptive {
+ my $n = shift;
+ my $found = 0;
+ my $num = 0;
+ while ( $found < $n ) {
+ if ( is_self_descriptive($num) ) {
+ print "$num\n";
+ $found++;
+ }
+ $num++;
+ }
+}
+
+find_self_descriptive(3);
diff --git a/challenge-107/lubos-kolouch/perl/ch-2.pl b/challenge-107/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..5cab44cada
--- /dev/null
+++ b/challenge-107/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,25 @@
+package Calc;
+
+use strict;
+use warnings;
+
+sub new { bless {}, shift; }
+sub add { }
+sub mul { }
+sub div { }
+
+1;
+
+package main;
+
+{
+ no strict 'refs';
+
+ my $class = 'Calc';
+ for my $name ( sort keys %{ $class . '::' } ) {
+ next if $name eq 'BEGIN'; # skip special symbol
+ next if $name eq 'import'; # skip import() method
+ next unless defined &{ $class . '::' . $name };
+ print "$name\n";
+ }
+}
diff --git a/challenge-107/lubos-kolouch/python/ch-1.py b/challenge-107/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..6f4a858204
--- /dev/null
+++ b/challenge-107/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def is_self_descriptive(num):
+ str_num = str(num)
+ length = len(str_num)
+
+ for i in range(length):
+ if str_num.count(str(i)) != int(str_num[i]):
+ return False
+
+ return True
+
+
+def find_self_descriptive(n):
+ found = 0
+ num = 0
+ while found < n:
+ if is_self_descriptive(num):
+ print(num)
+ found += 1
+ num += 1
+
+
+find_self_descriptive(3)
diff --git a/challenge-107/lubos-kolouch/python/ch-2.py b/challenge-107/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..b71e9c5358
--- /dev/null
+++ b/challenge-107/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import inspect
+
+
+class Calc:
+ def add(self):
+ pass
+
+ def mul(self):
+ pass
+
+ def div(self):
+ pass
+
+
+# Get all methods in class Calc
+methods = inspect.getmembers(Calc, predicate=inspect.isfunction)
+for method in methods:
+ print(method[0])