Created
December 4, 2023 14:57
-
-
Save AngelOnFira/86523b9f4d271aa80dd29b25cd5c536f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Find the number of matching numbers between the two vecs. This is | |
| // then worth 1/2/4/8/16 points. | |
| let mut points = 0; | |
| for num in &winning { | |
| if got.contains(num) { | |
| points += 1; | |
| } | |
| } | |
| // Add the score to the instances_count for the next cards | |
| let curr_cards = instances_count.entry(i).or_insert(1).to_owned(); | |
| for count in i + 1..i + 1 + points { | |
| *instances_count.entry(count).or_insert(1) += curr_cards; | |
| } | |
| } | |
| // Get the sum of all the values in the hashmap | |
| instances_count.values().sum() |
Author
Ahh that makes sense - I thought about doing that but then was too lazy and didn't think it would make too much of a diff if I used Python tuples... guess it does 😅
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basically we don't actually care what copies of cards are doing, we just care about how many there are. So if whenever we affect another card, we just change it by how many of the current card we have, we only need to store how many of each there are.