We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8962bda commit 2099df1Copy full SHA for 2099df1
Logic-2/make_chocolate.py
@@ -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