Skip to content

Commit

Permalink
Day 5
Browse files Browse the repository at this point in the history
  • Loading branch information
jpastoor committed Dec 12, 2016
1 parent 08effc3 commit b682c24
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
23 changes: 23 additions & 0 deletions day5/day5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"crypto/md5"
"fmt"
"strconv"
)

func main() {

input := "ojvtpuvg"
output := ""

for i := 0; len(output) < 8; i++ {
hashStr := fmt.Sprintf("%x", md5.Sum([]byte(input+strconv.Itoa(i))))
if hashStr[:5] == "00000" {
fmt.Println(hashStr)
output += string(hashStr[5])
}
}

fmt.Println(output)
}
35 changes: 35 additions & 0 deletions day5b/day5b.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"crypto/md5"
"fmt"
"strconv"
"strings"
)

func main() {

input := "ojvtpuvg"
output := make([]string, 8)
found := 0
for i := 0; found < 8; i++ {
hashStr := fmt.Sprintf("%x", md5.Sum([]byte(input+strconv.Itoa(i))))
if hashStr[:5] == "00000" {

pos := string(hashStr[5])
posInt, err := strconv.Atoi(pos)

// Only allow valids
if posInt < 8 && err == nil {
// Skip if value is already
if output[posInt] == "" {
output[posInt] = string(hashStr[6])
fmt.Println(output)
found++
}
}
}
}

fmt.Println(strings.Join(output, ""))
}

0 comments on commit b682c24

Please sign in to comment.