Created
July 16, 2014 02:28
-
-
Save aibou/24ceda1d5dbbe7806df0 to your computer and use it in GitHub Desktop.
ひっとあんどぶろーてきな
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
package main | |
import ( | |
"fmt" | |
) | |
func countHit(a string, b string) (hits int) { | |
for i := 0; i < 10; i++ { | |
if a[i] == b[i] { | |
hits ++ | |
} | |
} | |
return | |
} | |
func calc(sequence string, candidate string) string { | |
result := make([]byte, 10000) | |
var num byte | |
beforeHit := countHit(sequence, candidate) | |
chars := []byte(candidate) | |
for index := 0; index < 10000; index++ { | |
if index % 10 == 0 { | |
fmt.Println(index) | |
} | |
tmp := chars[index] | |
for num = 49; num < 58; num++ { | |
chars[index] = num | |
afterHit := countHit(sequence, string(chars)) | |
if beforeHit > afterHit { | |
result[index] = 48 | |
break | |
} | |
if beforeHit < afterHit { | |
result[index] = num | |
break | |
} | |
} | |
chars[index] = tmp | |
} | |
return string(result) | |
} | |
func main() { | |
fmt.Println(calc("1万文字","めんどくせ")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment