Skip to content

Instantly share code, notes, and snippets.

@aibou
Created July 16, 2014 02:28
Show Gist options
  • Save aibou/24ceda1d5dbbe7806df0 to your computer and use it in GitHub Desktop.
Save aibou/24ceda1d5dbbe7806df0 to your computer and use it in GitHub Desktop.
ひっとあんどぶろーてきな
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