aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/packy-anderson/python/ch-2.py
blob: e10d6230fe63edcde9026303b886e6759e46e934 (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
#!/usr/bin/env python

def finalPrice(prices):
  discounts = []
  while prices:
    current = prices.pop(0)
    lower = next((p for p in prices if p <= current), 0)
    current -= lower
    discounts.append(current)
  return discounts

def int_join(joiner, arr):
  return joiner.join(map(lambda i: str(i), arr))

def solution(prices):
  print(f'Input: @nums = ({int_join(", ", prices)})')
  discounts = finalPrice(prices)
  print(f'Output: ({int_join(", ", discounts)})')


print('Example 1:')
solution([8, 4, 6, 2, 3])

print('\nExample 2:')
solution([1, 2, 3, 4, 5])

print('\nExample 3:')
solution([7, 1, 1, 5])