Created
May 31, 2017 00:08
-
-
Save haru01/cd2565cbd699d8296298381798ede3f5 to your computer and use it in GitHub Desktop.
step7 returnの書き方のリファクタ
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
package roman | |
type Arabian uint16 | |
func (in Arabian) ToRoman() (out string) { | |
numbers := []struct { | |
arabian Arabian | |
roman string | |
}{ | |
{5, "V"}, | |
{1, "I"}, | |
} | |
for remain := in; remain != 0; { | |
for _, n := range numbers { | |
if remain >= n.arabian { | |
out += n.roman | |
remain = remain - n.arabian | |
} | |
} | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment