diff options
| author | 冯昶 <seaker@qq.com> | 2020-10-10 18:34:15 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2020-10-10 18:34:15 +0800 |
| commit | f0a88ea2365d8ae7dfb90c969d83368a18b53f9a (patch) | |
| tree | 64665b115f1023519b48f3f366bb743ab68375d8 /challenge-080/lubos-kolouch/python/ch-2.py | |
| parent | 353a66fe9f75298e44b27d692109259646e7d09f (diff) | |
| parent | a8ea1576ec8f1801e4c90d906c5d3c18ebde5ca6 (diff) | |
| download | perlweeklychallenge-club-f0a88ea2365d8ae7dfb90c969d83368a18b53f9a.tar.gz perlweeklychallenge-club-f0a88ea2365d8ae7dfb90c969d83368a18b53f9a.tar.bz2 perlweeklychallenge-club-f0a88ea2365d8ae7dfb90c969d83368a18b53f9a.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-080/lubos-kolouch/python/ch-2.py')
| -rw-r--r-- | challenge-080/lubos-kolouch/python/ch-2.py | 34 |
1 files changed, 34 insertions, 0 deletions
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 |
