diff options
Diffstat (limited to 'challenge-080/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-080/lubos-kolouch/python/ch-1.py | 43 |
1 files changed, 43 insertions, 0 deletions
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 |
