move unit64 back to int
This commit is contained in:
@@ -12,9 +12,9 @@ import (
|
||||
)
|
||||
|
||||
type Map struct {
|
||||
dest_range_start uint64
|
||||
src_range_start uint64
|
||||
range_len uint64
|
||||
dest_range_start int
|
||||
src_range_start int
|
||||
range_len int
|
||||
}
|
||||
|
||||
type Almanac struct {
|
||||
@@ -28,16 +28,16 @@ type Almanac struct {
|
||||
}
|
||||
|
||||
type SeedMap struct {
|
||||
seed uint64
|
||||
range_len uint64
|
||||
seed int
|
||||
range_len int
|
||||
}
|
||||
|
||||
func Part1(input string) uint64 {
|
||||
func Part1(input string) int {
|
||||
seeds, almanac, _ := parseInput1(input)
|
||||
fmt.Println(seeds)
|
||||
fmt.Println(almanac)
|
||||
|
||||
minLoc := uint64(utils.MaxInt)
|
||||
minLoc := int(utils.MaxInt)
|
||||
for _, seed := range seeds {
|
||||
soil := lookup_dest(seed, almanac.seed2soil)
|
||||
fert := lookup_dest(soil, almanac.soil2fert)
|
||||
@@ -59,7 +59,7 @@ func Part2(input string) int {
|
||||
seedsmap, almanac, _ := parseInput2(input)
|
||||
|
||||
for i:=0;i<utils.MaxInt;i++{
|
||||
humid := lookup_src(uint64(i), almanac.humid2loc)
|
||||
humid := lookup_src(int(i), almanac.humid2loc)
|
||||
temp := lookup_src(humid, almanac.temp2humid)
|
||||
light := lookup_src(temp, almanac.light2temp)
|
||||
water := lookup_src(light, almanac.water2light)
|
||||
@@ -76,7 +76,7 @@ func Part2(input string) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func lookup_dest(entity uint64, data []Map) uint64 {
|
||||
func lookup_dest(entity int, data []Map) int {
|
||||
for _, dataMap := range data {
|
||||
if entity >= dataMap.src_range_start && entity <= dataMap.src_range_start + dataMap.range_len {
|
||||
return dataMap.dest_range_start + entity - dataMap.src_range_start
|
||||
@@ -85,7 +85,7 @@ func lookup_dest(entity uint64, data []Map) uint64 {
|
||||
return entity
|
||||
}
|
||||
|
||||
func lookup_src(entity uint64, data []Map) uint64 {
|
||||
func lookup_src(entity int, data []Map) int {
|
||||
for _, dataMap := range data {
|
||||
if entity >= dataMap.dest_range_start && entity <= dataMap.dest_range_start + dataMap.range_len {
|
||||
return dataMap.src_range_start + entity - dataMap.dest_range_start
|
||||
@@ -94,16 +94,16 @@ func lookup_src(entity uint64, data []Map) uint64 {
|
||||
return entity
|
||||
}
|
||||
|
||||
func parseInput1(input string) ([]uint64, Almanac, error) {
|
||||
func parseInput1(input string) ([]int, Almanac, error) {
|
||||
|
||||
var almanac Almanac
|
||||
var seeds []uint64
|
||||
var seeds []int
|
||||
|
||||
lines := strings.Split(input, "\n")
|
||||
seedLine := string(lines[0])
|
||||
tokens := strings.Fields(seedLine)
|
||||
for _, token := range tokens[1:] {
|
||||
seeds = append(seeds, uint64(utils.MustAtoi(token)))
|
||||
seeds = append(seeds, int(utils.MustAtoi(token)))
|
||||
}
|
||||
|
||||
blocks := strings.Split(input, "\n\n")
|
||||
@@ -140,8 +140,8 @@ func parseInput2(input string) ([]SeedMap, Almanac, error) {
|
||||
seedLine := string(lines[0])
|
||||
tokens := strings.Fields(seedLine)
|
||||
for i:=1;i<len(tokens);i=i+2 {
|
||||
seedStart := uint64(utils.MustAtoi(tokens[i]))
|
||||
seedRange := uint64(utils.MustAtoi(tokens[i+1]))
|
||||
seedStart := int(utils.MustAtoi(tokens[i]))
|
||||
seedRange := int(utils.MustAtoi(tokens[i+1]))
|
||||
seeds = append(seeds, SeedMap{seedStart, seedRange})
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ func getMap(input []string) []Map {
|
||||
var out []Map
|
||||
for _, line := range input {
|
||||
tokens := strings.Fields(line)
|
||||
out = append(out, Map{uint64(utils.MustAtoi(tokens[0])), uint64(utils.MustAtoi(tokens[1])),uint64(utils.MustAtoi(tokens[2]))})
|
||||
out = append(out, Map{int(utils.MustAtoi(tokens[0])), int(utils.MustAtoi(tokens[1])),int(utils.MustAtoi(tokens[2]))})
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user