aboutsummaryrefslogtreecommitdiff
path: root/challenge-004
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2023-03-10 20:16:08 +0100
committerLubos Kolouch <lubos@kolouch.net>2023-03-10 20:16:08 +0100
commit5d6aa430b0aef716b216cc1e8de2297b576c8d72 (patch)
treeedc9685bd9ddfe18b5691ca3e7f479a134139995 /challenge-004
parentf2e33c0038917ad43651d0c4e8b0bb310eaed541 (diff)
downloadperlweeklychallenge-club-5d6aa430b0aef716b216cc1e8de2297b576c8d72.tar.gz
perlweeklychallenge-club-5d6aa430b0aef716b216cc1e8de2297b576c8d72.tar.bz2
perlweeklychallenge-club-5d6aa430b0aef716b216cc1e8de2297b576c8d72.zip
Challenges 2 3 4 LK Perl Python
Diffstat (limited to 'challenge-004')
-rw-r--r--challenge-004/lubos-kolouch/perl/ch-1.pl4
-rw-r--r--challenge-004/lubos-kolouch/perl/ch-2.pl29
-rw-r--r--challenge-004/lubos-kolouch/python/ch-1.py6
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-004/lubos-kolouch/perl/ch-1.pl b/challenge-004/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..57f17649ca
--- /dev/null
+++ b/challenge-004/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,4 @@
+my $pi =
+ "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
+
+print substr( $pi, 0, -1 * ( -s $0 ) );
diff --git a/challenge-004/lubos-kolouch/perl/ch-2.pl b/challenge-004/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..adad77eb43
--- /dev/null
+++ b/challenge-004/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+# Read in the list of letters
+my $letters = shift;
+my %letter_counts;
+for my $char ( split '', lc $letters ) {
+ $letter_counts{$char}++;
+}
+
+# Read in the file of words and print out the matching ones
+while ( my $word = <> ) {
+ chomp $word;
+ my %word_counts;
+ for my $char ( split '', lc $word ) {
+ $word_counts{$char}++;
+ }
+ my $matches = 1;
+ for my $char ( keys %word_counts ) {
+ unless ( $word_counts{$char} <= $letter_counts{$char} ) {
+ $matches = 0;
+ last;
+ }
+ }
+ print "$word\n" if $matches;
+}
diff --git a/challenge-004/lubos-kolouch/python/ch-1.py b/challenge-004/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..207ba38b08
--- /dev/null
+++ b/challenge-004/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,6 @@
+import os
+
+script_size = os.path.getsize(__file__)
+pi = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
+print(pi[:script_size])
+