blob: 1496b407d5c7f964a43260eaf0e7adf90df063b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
|