Combine AoC Repos
This commit is contained in:
1
2015/day04/input
Normal file
1
2015/day04/input
Normal file
@@ -0,0 +1 @@
|
||||
yzbqklnj
|
48
2015/day04/main.go
Normal file
48
2015/day04/main.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
61
2015/day04/problem
Normal file
61
2015/day04/problem
Normal file
@@ -0,0 +1,61 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen 40*
|
||||
|
||||
• [About]
|
||||
• [Stats]
|
||||
• [Leaderboard]
|
||||
• [Settings]
|
||||
• [Log out]
|
||||
|
||||
--- Day 4: The Ideal Stocking Stuffer ---
|
||||
|
||||
Santa needs help mining some AdventCoins (very similar to bitcoins) to use as gifts for all the
|
||||
economically forward-thinking little girls and boys.
|
||||
|
||||
To do this, he needs to find MD5 hashes which, in hexadecimal, start with at least five zeroes.
|
||||
The input to the MD5 hash is some secret key (your puzzle input, given below) followed by a
|
||||
number in decimal. To mine AdventCoins, you must find Santa the lowest positive number (no
|
||||
leading zeroes: 1, 2, 3, ...) that produces such a hash.
|
||||
|
||||
For example:
|
||||
|
||||
• If your secret key is abcdef, the answer is 609043, because the MD5 hash of abcdef609043
|
||||
starts with five zeroes (000001dbbfa...), and it is the lowest such number to do so.
|
||||
• If your secret key is pqrstuv, the lowest number it combines with to make an MD5 hash
|
||||
starting with five zeroes is 1048970; that is, the MD5 hash of pqrstuv1048970 looks like
|
||||
000006136ef....
|
||||
|
||||
Your puzzle answer was 282749.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Now find one that starts with six zeroes.
|
||||
|
||||
Your puzzle answer was 9962624.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||
|
||||
At this point, you should return to your advent calendar and try another puzzle.
|
||||
|
||||
Your puzzle input was yzbqklnj.
|
||||
|
||||
You can also [Shareon Twitter Google+ Reddit] this puzzle.
|
||||
|
||||
References
|
||||
|
||||
Visible links
|
||||
. http://adventofcode.com/
|
||||
. http://adventofcode.com/about
|
||||
. http://adventofcode.com/stats
|
||||
. http://adventofcode.com/leaderboard
|
||||
. http://adventofcode.com/settings
|
||||
. http://adventofcode.com/auth/logout
|
||||
. https://en.wikipedia.org/wiki/Bitcoin#Mining
|
||||
. https://en.wikipedia.org/wiki/Bitcoin
|
||||
. https://en.wikipedia.org/wiki/MD5
|
||||
. https://en.wikipedia.org/wiki/Hexadecimal
|
||||
. http://adventofcode.com/
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22The+Ideal+Stocking+Stuffer%22+%2D+Day+4+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F4&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F4
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F4&title=I%27ve+completed+%22The+Ideal+Stocking+Stuffer%22+%2D+Day+4+%2D+Advent+of+Code
|
Reference in New Issue
Block a user