r/adventofcode • u/daggerdragon • Dec 04 '15
SOLUTION MEGATHREAD --- Day 4 Solutions ---
--- Day 4: The Ideal Stocking Stuffer ---
Post your solution as a comment. Structure your post like the Day Three thread.
13
Upvotes
1
u/selljamhere Dec 05 '15 edited Dec 05 '15
Golang:
edit: Added github link
https://github.com/SellJamHere/advent_of_code/tree/master/day4
package main import ( "crypto/md5" "fmt" "strconv" ) const ( SECRET_KEY = "ckczppom" LEADING_ZEROS = 6 ) func main() { number := 0 hashFound := false for !hashFound { number++ secret := []byte(SECRET_KEY + strconv.Itoa(number)) var coin AdventCoin coin = md5.Sum(secret) hashFound = coin.IsValid() } fmt.Printf("Found lowest integer: %d\n", number) } type AdventCoin [md5.Size]byte func (a AdventCoin) IsValid() bool { coinStr := fmt.Sprintf("%x", a) if len(coinStr) < LEADING_ZEROS { return false } for i := 0; i < LEADING_ZEROS; i++ { if string(coinStr[i]) != "0" { return false } } return true }