Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Least Change #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

JimmyQuenichet
Copy link
Contributor

No description provided.


s.add(equation_1 == target,
equation_2 == min_coins,
min_coins > 0,
Copy link
Contributor

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):
Copy link
Contributor

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 *
Copy link
Contributor

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, "
Copy link
Contributor

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)):
Copy link
Contributor

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):
Copy link
Contributor

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants