aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-01 10:12:56 +0100
committerGitHub <noreply@github.com>2020-10-01 10:12:56 +0100
commitc204ee2ac5e1568f732770a7c093c863cbd38190 (patch)
treea3a4b19feb39ef2f7526b54582b252655d8c21cc
parent236626df73f6a77ffa3a9ef434b6a05b88896698 (diff)
parentd40cd33cbab3a1b0bb767c6bb5cdbebc48210dab (diff)
downloadperlweeklychallenge-club-c204ee2ac5e1568f732770a7c093c863cbd38190.tar.gz
perlweeklychallenge-club-c204ee2ac5e1568f732770a7c093c863cbd38190.tar.bz2
perlweeklychallenge-club-c204ee2ac5e1568f732770a7c093c863cbd38190.zip
Merge pull request #2423 from LubosKolouch/chal_080_LK
Python solutions challenge 080
-rw-r--r--challenge-080/lubos-kolouch/perl/ch-2.pl2
-rw-r--r--challenge-080/lubos-kolouch/python/ch-1.py43
-rw-r--r--challenge-080/lubos-kolouch/python/ch-2.py34
3 files changed, 78 insertions, 1 deletions
diff --git a/challenge-080/lubos-kolouch/perl/ch-2.pl b/challenge-080/lubos-kolouch/perl/ch-2.pl
index 3c01308c37..b0e676ee9b 100644
--- a/challenge-080/lubos-kolouch/perl/ch-2.pl
+++ b/challenge-080/lubos-kolouch/perl/ch-2.pl
@@ -6,7 +6,7 @@
# USAGE: ./ch_2.pl
#
# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-080/
-# Challenge #1
+# Challenge #2
# Count Candies
#
# AUTHOR: Lubos Kolouch
diff --git a/challenge-080/lubos-kolouch/python/ch-1.py b/challenge-080/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..812337313a
--- /dev/null
+++ b/challenge-080/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,43 @@
+#!/bin/env python
+"""
+#===============================================================================
+#
+# FILE: ch_1.py
+#
+# USAGE: ./ch_1.py
+#
+# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-080/
+# Challenge #1
+# Smallest Positive Number Bits
+#
+# AUTHOR: Lubos Kolouch
+#===============================================================================
+"""
+
+
+def get_smallest_missing(arr: list):
+ """ Find if there is any number missing and return it """
+
+ # Let's see if are lucky and the minimum -1 is >0
+ arr_min = min(n for n in arr if n > 0)
+
+ if arr_min - 1 > 0:
+ return arr_min-1
+
+ # Not lucky, arr_min is 0, so need to iterate
+ # NOTE: the excercise does not say what to do if there is nothing missing
+ # so let's just return 0 as per Twitter confirmation
+
+ while arr_min < max(arr):
+ arr_min += 1
+
+ if arr_min not in arr:
+ return arr_min
+ return 0
+
+
+assert get_smallest_missing([5, 2, -2, 0]) == 1
+assert get_smallest_missing([1, 8, -1]) == 2
+assert get_smallest_missing([2, 0, -1]) == 1
+assert get_smallest_missing([2, 0, 1]) == 0
+assert get_smallest_missing([2, 0, 1, 3, 4, 5]) == 0
diff --git a/challenge-080/lubos-kolouch/python/ch-2.py b/challenge-080/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..1496b407d5
--- /dev/null
+++ b/challenge-080/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,34 @@
+#!/bin/env pythoon
+"""
+#===============================================================================
+#
+# FILE: ch_2.py
+#
+# USAGE: ./ch_2.py
+#
+# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-080/
+# Challenge #2
+# Count Candies
+#
+# AUTHOR: Lubos Kolouch
+#===============================================================================
+"""
+
+
+def get_candle_count(arr: list):
+ """ Count the candles """
+
+ # We need to give 1 candy to everyone
+ count = len(arr)
+
+ # and then find out number of unique elements as they will be certainly
+ # bigger than neighbor... -1 (the initial poor one)
+
+ count += len(set(arr))
+ count -= 1
+
+ return count
+
+
+assert get_candle_count([1, 2, 2]) == 4
+assert get_candle_count([1, 4, 3, 2]) == 7