Created
May 31, 2017 00:14
-
-
Save haru01/aa50ce0b2e8606ffbd0cf467d3d83d66 to your computer and use it in GitHub Desktop.
numberの括りだし
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 | |
var numbers = []struct { | |
arabian Arabian | |
roman string | |
}{ | |
{5, "V"}, | |
{1, "I"}, | |
} | |
func (in Arabian) ToRoman() (out string) { | |
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