48 lines
810 B
Go
48 lines
810 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"crypto/md5"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"log"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
var readInp string
|
||
|
for {
|
||
|
_, err := fmt.Scan(&readInp)
|
||
|
if err != nil {
|
||
|
if err != io.EOF {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
firstCoin := searchChunk(readInp, 0, 1000000000)
|
||
|
fmt.Printf("\n%s%d :: %d\n", readInp, firstCoin, firstCoin)
|
||
|
}
|
||
|
|
||
|
func searchChunk(key string, start, end int) int {
|
||
|
// So we know it's still running
|
||
|
for i := start; i <= end; i++ {
|
||
|
coin := key + strconv.Itoa(i)
|
||
|
coinMd5 := fmt.Sprintf("%x", md5.Sum([]byte(coin)))
|
||
|
if isCoin(coinMd5, "000000") {
|
||
|
return i
|
||
|
}
|
||
|
}
|
||
|
return -1
|
||
|
}
|
||
|
|
||
|
func isCoin(s string, moneyMaker string) bool {
|
||
|
if len(s) < len(moneyMaker) {
|
||
|
return false
|
||
|
}
|
||
|
for i := 0; i < len(moneyMaker); i++ {
|
||
|
if s[i] != moneyMaker[i] {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
return true
|
||
|
}
|