-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
puzzles/solutions/2015: Implement day01 part2
- Loading branch information
1 parent
9b3ef6b
commit 566c9ae
Showing
4 changed files
with
111 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package day01 | ||
|
||
type move string | ||
|
||
const ( | ||
up move = "(" | ||
down move = ")" | ||
|
||
basement = -1 | ||
) | ||
|
||
type elevator struct { | ||
floor int | ||
} | ||
|
||
func newElevator() *elevator { | ||
return &elevator{ | ||
floor: 0, | ||
} | ||
} | ||
|
||
func (e *elevator) Up() { | ||
e.floor++ | ||
} | ||
|
||
func (e *elevator) Down() { | ||
e.floor-- | ||
} | ||
|
||
func (e elevator) Floor() int { | ||
return e.floor | ||
} | ||
|
||
func (e *elevator) Move(m move) { | ||
switch m { | ||
case up: | ||
e.Up() | ||
case down: | ||
e.Down() | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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