Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add knapsack exercise #183

Merged
merged 5 commits into from
May 15, 2024
Merged

Add knapsack exercise #183

merged 5 commits into from
May 15, 2024

Conversation

ErikSchierboom
Copy link
Member

@ErikSchierboom ErikSchierboom commented May 14, 2024

Another weird one. When I run the test code in a REPL, they're fine:

For example

"example.8th" f:include G:reset  10 [{"weight": 2, "value": 5}, {"weight": 2, "value": 5}, {"weight": 2, "value": 5}, {"weight": 2, "value": 5}, {"weight": 10, "value": 21}] maximum-value .s
 0 n: 000000010c6f4e50 2  21

and

"example.8th" f:include G:reset 10 [{"weight": 2, "value": 20}, {"weight": 2, "value": 20}, {"weight": 2, "value": 20}, {"weight": 2, "value": 20}, {"weight": 10, "value": 50}] maximum-value .s
 0 n: 000000010c6f4a90 3  80

But when I run bin/test-no-docker -r knapsack the tests fail. I see two possible problems:

  • Working with maps somehow trips things up, as I also suspected this to fail food-chain
  • Our test library messes things up when using maps

I'm at a loss how to fix it. Could you please take a look?

@ErikSchierboom ErikSchierboom changed the title knapsack Add knapsack exercise May 14, 2024
@ErikSchierboom ErikSchierboom requested review from glennj and axtens May 14, 2024 13:38
@glennj
Copy link
Contributor

glennj commented May 14, 2024

I'll try to dig into it this evening.

@glennj
Copy link
Contributor

glennj commented May 15, 2024

This might be the same problem with JSON literals that I saw in phone-number: repeating the same sequence produces different results.

$ 8th
8th 24.02 LIN64 Free (98b29c8c/2024-03-11) custid: 44e5dc98

ok> "example.8th" f:include

ok> 10 [{"weight": 5, "value": 10}, {"weight": 4, "value": 40}, {"weight": 6, "value": 30}, {"weight": 4, "value": 50}] maximum-value

ok> .s
 0 n: 00007f4c42b93b30 2  90

ok> drop

ok> 10 [{"weight": 5, "value": 10}, {"weight": 4, "value": 40}, {"weight": 6, "value": 30}, {"weight": 4, "value": 50}] maximum-value

ok> .s
 0 n: 00007f4c42b933e0 2  100

@ErikSchierboom ErikSchierboom merged commit 709639a into main May 15, 2024
2 checks passed
@ErikSchierboom ErikSchierboom deleted the knapsack branch May 15, 2024 06:59
@ErikSchierboom
Copy link
Member Author

Thanks @glennj for your help!

@axtens
Copy link
Member

axtens commented May 15, 2024

I take all questions like that to the 8th forum. Ron is very helpful

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

Successfully merging this pull request may close these issues.

3 participants