Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class State(val adults: Int, val youngs: Int, val children: Int) {
- override def toString(): String = "(a: " + adults + ", y: " + youngs + ", c: " + children + ")"
- }
- def evolve(prevState: State): State = {
- val childenPerAdult = 6 / 2 // Six children for each couple
- new State(prevState.adults + prevState.youngs, prevState.children, prevState.adults * childenPerAdult)
- }
- def stateAtTime(timeZero: State, time: Int): State = {
- time match {
- case 0 => timeZero
- case t => evolve(stateAtTime(timeZero, t - 1))
- }
- }
- stateAtTime(new State(10, 0, 0), 3*3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement