aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2022-04-23 16:40:54 +0200
committerLubos Kolouch <lubos@kolouch.net>2022-04-23 16:40:54 +0200
commit93d99055be7e6d642ff592950cd43449a06180da (patch)
treed5ea9454459d5b1da52f49f5cee738647e629efc
parentd53579ac9e38e2183e3f799cd638c7960dfe4867 (diff)
downloadperlweeklychallenge-club-93d99055be7e6d642ff592950cd43449a06180da.tar.gz
perlweeklychallenge-club-93d99055be7e6d642ff592950cd43449a06180da.tar.bz2
perlweeklychallenge-club-93d99055be7e6d642ff592950cd43449a06180da.zip
feat(challenge-161/lubos-kolouch/python/ch-{12}.py,-perl/ch-2.pl-fix): Challenge 161 in Python, fix check for abcdrian in Perl
-rw-r--r--challenge-161/lubos-kolouch/perl/ch-2.pl5
-rw-r--r--challenge-161/lubos-kolouch/python/ch-1.py17
-rw-r--r--challenge-161/lubos-kolouch/python/ch-2.py52
3 files changed, 71 insertions, 3 deletions
diff --git a/challenge-161/lubos-kolouch/perl/ch-2.pl b/challenge-161/lubos-kolouch/perl/ch-2.pl
index c813084ceb..ddde2dbfe0 100644
--- a/challenge-161/lubos-kolouch/perl/ch-2.pl
+++ b/challenge-161/lubos-kolouch/perl/ch-2.pl
@@ -38,9 +38,8 @@ sub get_abcdrian_pangram {
while (<$file>) {
chomp;
+ next unless is_abcd($_);
process_word($_);
-
- # seen all letters?
return join( ' ', @output ) if scalar keys %seen_letters == 26;
}
close $file;
@@ -50,7 +49,7 @@ sub get_abcdrian_pangram {
use Test::More;
is( get_abcdrian_pangram(),
- 'a ad added adds ado adobe adore adorn adverb adversaries adversary adversely adversest advertisement advertising advice aerospace aesthetic afar affix affluence afterward agonize ajar akin antiquate'
+ 'a ad adds ado ago ah ahoy all allot allow almost amp an art ax blot buy buzz cc cell chi deft envy jot knot qt'
);
done_testing;
diff --git a/challenge-161/lubos-kolouch/python/ch-1.py b/challenge-161/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..7627473c05
--- /dev/null
+++ b/challenge-161/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,17 @@
+""" glory for best belly boy! """
+
+
+def is_abcd(what: str) -> bool:
+ """Check if the str is in the right order"""
+
+ return what == "".join(sorted(what))
+
+
+with open("dictionary.txt") as in_file:
+ line = in_file.readline()
+
+ if is_abcd(line):
+ print(f"{line} is abcdrian")
+
+assert is_abcd("knotty") is True
+assert is_abcd("knotts") is False
diff --git a/challenge-161/lubos-kolouch/python/ch-2.py b/challenge-161/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..7936fc9117
--- /dev/null
+++ b/challenge-161/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,52 @@
+""" Challenge 161 LK Python """
+
+
+class Pangram:
+ """Challenge 161 Task 2"""
+
+ def __init__(self) -> None:
+ self.seen_letters: dict = {}
+ self.output: list = []
+
+ @staticmethod
+ def is_abcd(what: str) -> bool:
+ """Check if the file is in the right order"""
+ return what == "".join(sorted(what))
+
+ def process_word(self, what: str) -> None:
+ """Check if the word matches"""
+
+ this_run_letters = dict(self.seen_letters)
+
+ for char in what:
+ this_run_letters[char] = 1
+
+ if len(self.seen_letters.keys()) == len(this_run_letters.keys()) - 1:
+ # we added a letter
+ self.output.append(what)
+ self.seen_letters = dict(this_run_letters)
+
+ return
+
+ def get_abcdrian_pangram(self) -> str:
+ """only abecederian words solving exactly one letter"""
+ with open("dictionary.txt") as in_file:
+
+ while line := in_file.readline().strip():
+ if not self.is_abcd(line):
+ continue
+
+ self.process_word(line)
+
+ # seen all letters?
+ if len(self.seen_letters.keys()) == 26:
+ return " ".join(self.output)
+
+ return ""
+
+
+pangram = Pangram()
+assert (
+ pangram.get_abcdrian_pangram()
+ == "a ad adds ado ago ah ahoy all allot allow almost amp an art ax blot buy buzz cc cell chi deft envy jot knot qt"
+)