https://github.com/reagentx/coin-counter
Coin counter code challenge
https://github.com/reagentx/coin-counter
Last synced: 4 days ago
JSON representation
Coin counter code challenge
- Host: GitHub
- URL: https://github.com/reagentx/coin-counter
- Owner: ReagentX
- Created: 2020-10-14T01:30:26.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-10T03:40:24.000Z (about 2 years ago)
- Last Synced: 2025-03-26T14:53:05.594Z (over 1 year ago)
- Language: Rust
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Coin Counter
Given an MxN array of “boxes”, where each box contains some number of coins `C[i][j]`, you want to maximize the number of coins you can take.
You take coins by traversing row by row, taking all of the coins from ONE box in each row. However, any time you change the index of the box you take coins from, you must pay a “change fee” equal to `ABS(x - y)` where `x` and `y` are the previous and new row indices.
Write a function that can determine the optimal set of boxes to take coins from in order to maximize your profit after change fees.
## Example
The matrix:
[
[5, 9, 2, 6, 4, 4, 9],
[4, 5, 7, 4, 6, 8, 8],
[8, 2, 9, 8, 8, 6, 5],
[2, 1, 1, 3, 5, 7, 1],
[1, 8, 1, 7, 1, 6, 8],
]
has optimal path:
Values: [9, 8, 8, 7, 8]
Indexes: [6, 6, 4, 5, 6]
## Performance
For a 10,000x10,000 matrix, `cargo run --release` results in the following timing:
Grid generated in: 644.20ms
Solution found in: 148.04ms
169,976 coins