Skip to content

Commit 2099df1

Browse files
committed
Logic-2 solutions completed
1 parent 8962bda commit 2099df1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Logic-2/make_chocolate.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# We want make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each).
2+
# Return the number of small bars to use, assuming we always use big bars before small bars. Return -1 if it can't be
3+
# done.
4+
#
5+
#
6+
# make_chocolate(4, 1, 9) → 4
7+
# make_chocolate(4, 1, 10) → -1
8+
# make_chocolate(4, 1, 7) → 2
9+
10+
def make_chocolate(small, big, goal):
11+
if goal >= 5 * big:
12+
remainder = goal - 5 * big
13+
else:
14+
remainder = goal % 5
15+
if remainder <= small:
16+
return remainder
17+
return -1

0 commit comments

Comments
 (0)