aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2023-03-16 19:22:04 +0100
committerLubos Kolouch <lubos@kolouch.net>2023-03-16 19:22:04 +0100
commit4e2e50d29d3dfdcc15613ab3259f206681304ed1 (patch)
treecff26fa889d24938258ec7342809819b8c229564
parentf8fccce87c49ef9d9e5da19d23e4c8549ff024c9 (diff)
downloadperlweeklychallenge-club-4e2e50d29d3dfdcc15613ab3259f206681304ed1.tar.gz
perlweeklychallenge-club-4e2e50d29d3dfdcc15613ab3259f206681304ed1.tar.bz2
perlweeklychallenge-club-4e2e50d29d3dfdcc15613ab3259f206681304ed1.zip
Challenge 010 011 LK Perl Python
-rw-r--r--challenge-011/lubos-kolouch/perl/ch-1.pl15
-rw-r--r--challenge-011/lubos-kolouch/perl/ch-2.pl22
-rw-r--r--challenge-011/lubos-kolouch/python/ch-1.py10
-rw-r--r--challenge-011/lubos-kolouch/python/ch-2.py12
-rw-r--r--challenge-012/lubos-kolouch/perl/ch-1.pl25
-rw-r--r--challenge-012/lubos-kolouch/perl/ch-2.pl23
-rw-r--r--challenge-012/lubos-kolouch/python/ch-1.py25
-rw-r--r--challenge-012/lubos-kolouch/python/ch-2.py18
8 files changed, 150 insertions, 0 deletions
diff --git a/challenge-011/lubos-kolouch/perl/ch-1.pl b/challenge-011/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..fae93c59ab
--- /dev/null
+++ b/challenge-011/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+my $fahrenheit;
+my $celsius;
+
+for ( $fahrenheit = -100 ; $fahrenheit <= 212 ; $fahrenheit++ ) {
+ $celsius = ( $fahrenheit - 32 ) * 5 / 9;
+ if ( $fahrenheit == $celsius ) {
+ print
+"The equal point in the Fahrenheit and Celsius scales is $fahrenheit °F and $celsius °C.\n";
+ last;
+ }
+}
diff --git a/challenge-011/lubos-kolouch/perl/ch-2.pl b/challenge-011/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..5a6165c080
--- /dev/null
+++ b/challenge-011/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+my $size = 4; # change this to the desired size
+my @identity_matrix;
+
+for my $i ( 0 .. $size - 1 ) {
+ for my $j ( 0 .. $size - 1 ) {
+ if ( $i == $j ) {
+ $identity_matrix[$i][$j] = 1;
+ }
+ else {
+ $identity_matrix[$i][$j] = 0;
+ }
+ }
+}
+
+# print the identity matrix
+for my $row (@identity_matrix) {
+ print "@$row\n";
+}
diff --git a/challenge-011/lubos-kolouch/python/ch-1.py b/challenge-011/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..21e817e97c
--- /dev/null
+++ b/challenge-011/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+for fahrenheit in range(-100, 213):
+ celsius = (fahrenheit - 32) * 5 / 9
+ if fahrenheit == celsius:
+ print(
+ f"The equal point in the Fahrenheit and Celsius scales is {fahrenheit} °F and {celsius} °C."
+ )
+ break
diff --git a/challenge-011/lubos-kolouch/python/ch-2.py b/challenge-011/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..442bd8d82a
--- /dev/null
+++ b/challenge-011/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+size = 4 # change this to the desired size
+identity_matrix = [[0 for x in range(size)] for y in range(size)]
+
+for i in range(size):
+ identity_matrix[i][i] = 1
+
+# print the identity matrix
+for row in identity_matrix:
+ print(row)
diff --git a/challenge-012/lubos-kolouch/perl/ch-1.pl b/challenge-012/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..5fd044a666
--- /dev/null
+++ b/challenge-012/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+sub is_prime {
+ my $n = shift;
+ return 0 if $n < 2;
+ for ( my $i = 2 ; $i <= sqrt($n) ; $i++ ) {
+ return 0 if ( $n % $i == 0 );
+ }
+ return 1;
+}
+
+my $p = 2;
+my $euclid_number = 3;
+
+while ( is_prime($euclid_number) ) {
+ $p++;
+ while ( !is_prime($p) ) {
+ $p++;
+ }
+ $euclid_number = ( 2**( $p - 1 ) ) * ( ( 2**$p ) - 1 );
+}
+
+print "The smallest Euclid number that is not prime is: ", $euclid_number, "\n";
diff --git a/challenge-012/lubos-kolouch/perl/ch-2.pl b/challenge-012/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..af21886dc0
--- /dev/null
+++ b/challenge-012/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+my @paths = ( "/a/b/c/d", "/a/b/cd", "/a/b/cc", "/a/b/c/d/e" );
+my $separator = "/";
+
+my @common_path;
+for my $path (@paths) {
+ my @parts = split( $separator, $path );
+ if ( !@common_path ) {
+ @common_path = @parts;
+ }
+ else {
+ for ( my $i = 0 ; $i < @common_path ; $i++ ) {
+ if ( $common_path[$i] ne $parts[$i] ) {
+ splice( @common_path, $i );
+ last;
+ }
+ }
+ }
+}
+
+print "The common directory path is: ", join( $separator, @common_path ), "\n";
diff --git a/challenge-012/lubos-kolouch/python/ch-1.py b/challenge-012/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..d7f2eb96f4
--- /dev/null
+++ b/challenge-012/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from math import sqrt
+
+
+def is_prime(n):
+ if n < 2:
+ return False
+ for i in range(2, int(sqrt(n)) + 1):
+ if n % i == 0:
+ return False
+ return True
+
+
+p = 2
+euclid_number = 3
+
+while is_prime(euclid_number):
+ p += 1
+ while not is_prime(p):
+ p += 1
+ euclid_number = (2 ** (p - 1)) * ((2**p) - 1)
+
+print(f"The smallest Euclid number that is not prime is: {euclid_number}")
diff --git a/challenge-012/lubos-kolouch/python/ch-2.py b/challenge-012/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..43788cde70
--- /dev/null
+++ b/challenge-012/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+paths = ["/a/b/c/d", "/a/b/cd", "/a/b/cc", "/a/b/c/d/e"]
+separator = "/"
+
+common_path = []
+for path in paths:
+ parts = path.split(separator)
+ if not common_path:
+ common_path = parts
+ else:
+ for i in range(len(common_path)):
+ if common_path[i] != parts[i]:
+ common_path = common_path[:i]
+ break
+
+print(f"The common directory path is: {separator.join(common_path)}")