The “How Much Snow” problem is loosely based off of a question I encountered during a programing interview.
This project was created as a simple golang demo and possible programing interview prep. The two solutions I came up
with are not the only ways to solve the problem. Have fun and create your own solutions!
Problem:
Given an array of ints that describes the topography of a mountain, how much snow could fall on it before sliding off?.
Rules:
1. Snow will slide off the mountain when the difference between two adjacent areas is greater than one.
2. The first and last elements of the array will only ever support a maximum of one unit of snow.
Note:
- The mountain is randomly generated
- the mountain only has positive ints
EX:
Mountain := [1,2,1,3,4,5,3,2,1,1] can hold 17 blocks of snow
Before Snow: After Snow:
| | | |
| | | ss |
| M | | ssMs |
| MM | | ssMMss |
| MMMM | | ssMMMMss |
| M MMMMM | |sMsMMMMMss|
|MMMMMMMMMM| |MMMMMMMMMM|
If you use my main...
Usage:
Run twopass and multipass with the mounted generated by seed 9001 and print the mountain with snow on it:
./howMuchSnow -m -t -p -s 9001
Run demo 1:
./howMuchSnow -d 1
Compare multipass and twopass with mountains ranging from 10 to 100 wide using the average of 100 runs at each
width and dump that to a file called “runs.csv”:
./howMuchSnow -l 100 -w 10 -W 100 -s 1 -f runs.csv