-
-
Notifications
You must be signed in to change notification settings - Fork 13
Least Change #67
base: main
Are you sure you want to change the base?
Least Change #67
Conversation
|
||
s.add(equation_1 == target, | ||
equation_2 == min_coins, | ||
min_coins > 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comma be removed if this is the last item in .add()?
@@ -0,0 +1,27 @@ | |||
from z3 import * | |||
|
|||
def least_change(coins, target): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be empty for the user to write their code in
@@ -0,0 +1,49 @@ | |||
import unittest | |||
from z3 import * | |||
from .least_change import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is a relative import?
|
||
class ChangeTest(unittest.TestCase): | ||
def test_single_coin_change(self): | ||
self.assertEqual(str(least_change([1, 5, 10, 25, 100], 25)), "[10 = 0, 25 = 1, 100 = 0, 5 = 0, min_coins = 1, " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you're converting it to a string rather than making a direct comparison between two lists? Seems a little error prone if the formatting was to change
min_coins = Int("min_coins") | ||
|
||
# Fill in the solver with the necessary constraints | ||
for i in range(len(coins)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend using zip()
and/or enumerate()
rather than indexing
def test_another_possible_change_without_unit_coins_available(self): | ||
self.assertEqual(str(least_change([4, 5], 27)), "[4 = 3, 5 = 3, min_coins = 6]") | ||
|
||
def test_no_coins_make_0_change(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intuitively, I would this a solver should return 0 for every coin rather than None (for not solveable)
No description provided.