fine, I'll put them on github
This commit is contained in:
commit
c3bc233d82
9 changed files with 472 additions and 0 deletions
51
2/2.2.go
Normal file
51
2/2.2.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import "os"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
import "strconv"
|
||||
import "bufio"
|
||||
|
||||
// cat input | go run 2.2.go
|
||||
|
||||
func main() {
|
||||
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
checksum := 0
|
||||
for scanner.Scan() {
|
||||
|
||||
s := strings.Split(scanner.Text(), "\t")
|
||||
fmt.Println(s)
|
||||
|
||||
for index, element := range s {
|
||||
fmt.Println(index, element)
|
||||
i, _ := strconv.Atoi(element)
|
||||
|
||||
for index2, e2 := range s {
|
||||
|
||||
i2, _ := strconv.Atoi(e2)
|
||||
|
||||
if index == index2 {
|
||||
continue
|
||||
}
|
||||
if i2 > i {
|
||||
continue
|
||||
}
|
||||
|
||||
result := float64(i) / float64(i2)
|
||||
ir := float64(int(result))
|
||||
|
||||
if result == ir {
|
||||
fmt.Println("yes!", i, i2, result)
|
||||
checksum += int(result)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("---")
|
||||
|
||||
}
|
||||
|
||||
fmt.Println(checksum)
|
||||
}
|
41
2/2.go
Normal file
41
2/2.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import "os"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
import "strconv"
|
||||
import "bufio"
|
||||
|
||||
// cat input | go run 2.go
|
||||
|
||||
func main() {
|
||||
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
checksum := 0
|
||||
for scanner.Scan() {
|
||||
|
||||
min := 9999999999999 // messy, but whatever.
|
||||
max := 0
|
||||
s := strings.Split(scanner.Text(), "\t")
|
||||
|
||||
for index, element := range s {
|
||||
fmt.Println(index, element)
|
||||
i, _ := strconv.Atoi(element)
|
||||
if i < min {
|
||||
min = i
|
||||
}
|
||||
if i > max {
|
||||
max = i
|
||||
}
|
||||
}
|
||||
|
||||
diff := max - min
|
||||
checksum += diff
|
||||
fmt.Println("min", min, "max", max, "diff", diff)
|
||||
fmt.Println("---")
|
||||
|
||||
}
|
||||
|
||||
fmt.Println(checksum)
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue