[AOC December 2023] by Deicide: 11:57am On Nov 20, 2023 |
I would be drooping my solution here, which would mostly be written in Golang (because I am learning the language) and Rust. Let's see how far I can go before Santa gets me |
Re: [AOC December 2023] by Deicide: 7:42am On Dec 01, 2023 |
Day 1: Trebuchet?!Writing the solution of this one in Go part 1func Trebuchet(input string) int { data, err := utils.ReadFile(input) if err != nil { fmt.Println(err) } sum := 0 v1 := strings.Split(data, "\n" ) for _, y := range v1 { left := 0 right := len(y) - 1 ptr := 0 a := 0 b := 0 for ptr <= len(y) { if y[left] >= 48 && y[left] <= 57 { a = int(y[left] - 48) } else { left++ } if y[right] >= 48 && y[right] <= 57 { b = int(y[right] - 48) } else { right-- } ptr++ } v2, _ := strconv.ParseInt(fmt.Sprintf("%d%d", a, b), 10, 64) sum += int(v2) } return sum } part 2Just add a function to transform the input because it was tricky, I have to do stuff I am not proud of func transform(word string) string { word = strings.ReplaceAll(word, "twone", "21" ) word = strings.ReplaceAll(word, "eightwo", "82" ) word = strings.ReplaceAll(word, "nineight", "98" ) word = strings.ReplaceAll(word, "eightthree", "83" ) word = strings.ReplaceAll(word, "threeight", "38" ) word = strings.ReplaceAll(word, "fiveight", "58" ) word = strings.ReplaceAll(word, "nineight", "98" ) word = strings.ReplaceAll(word, "oneight", "18" ) word = strings.ReplaceAll(word, "sevenine", "79" ) v := []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} for x := range v { word = strings.ReplaceAll(word, fmt.Sprintf("%d", x+1), v[x]) } p := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"} for x := range p { word = strings.ReplaceAll(word, v[x], p[x]) } return word } |
|
Re: [AOC December 2023] by preciouswoman66(m): 2:57pm On Dec 06, 2023 |
Una dey try sha |
Re: [AOC December 2023] by Loopdeeloopa: 7:54am On Feb 08 |
Deicide: Day 1: Trebuchet?!
Writing the solution of this one in Go part 1
func Trebuchet(input string) int { data, err := utils.ReadFile(input) if err != nil { fmt.Println(err) } sum := 0 v1 := strings.Split(data, "\n" ) for _, y := range v1 { left := 0 right := len(y) - 1 ptr := 0 a := 0 b := 0 for ptr <= len(y) { if y[left] >= 48 && y[left] <= 57 { a = int(y[left] - 48) } else { left++ } if y[right] >= 48 && y[right] <= 57 { b = int(y[right] - 48) } else { right-- } ptr++ } v2, _ := strconv.ParseInt(fmt.Sprintf("%d%d", a, b), 10, 64) sum += int(v2) } return sum }
part 2 Just add a function to transform the input because it was tricky, I have to do stuff I am not proud of
func transform(word string) string { word = strings.ReplaceAll(word, "twone", "21" ) word = strings.ReplaceAll(word, "eightwo", "82" ) word = strings.ReplaceAll(word, "nineight", "98" ) word = strings.ReplaceAll(word, "eightthree", "83" ) word = strings.ReplaceAll(word, "threeight", "38" ) word = strings.ReplaceAll(word, "fiveight", "58" ) word = strings.ReplaceAll(word, "nineight", "98" ) word = strings.ReplaceAll(word, "oneight", "18" ) word = strings.ReplaceAll(word, "sevenine", "79" ) v := []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} for x := range v { word = strings.ReplaceAll(word, fmt.Sprintf("%d", x+1), v[x]) } p := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"} for x := range p { word = strings.ReplaceAll(word, v[x], p[x]) } return word } Nice to see gophers |
Re: [AOC December 2023] by BBIA: 8:00am On Feb 08 |
Deicide: Day 1: Trebuchet?!
Writing the solution of this one in Go part 1
func Trebuchet(input string) int { data, err := utils.ReadFile(input) if err != nil { fmt.Println(err) } sum := 0 v1 := strings.Split(data, "\n" ) for _, y := range v1 { left := 0 right := len(y) - 1 ptr := 0 a := 0 b := 0 for ptr <= len(y) { if y[left] >= 48 && y[left] <= 57 { a = int(y[left] - 48) } else { left++ } if y[right] >= 48 && y[right] <= 57 { b = int(y[right] - 48) } else { right-- } ptr++ } v2, _ := strconv.ParseInt(fmt.Sprintf("%d%d", a, b), 10, 64) sum += int(v2) } return sum }
part 2 Just add a function to transform the input because it was tricky, I have to do stuff I am not proud of
func transform(word string) string { word = strings.ReplaceAll(word, "twone", "21" ) word = strings.ReplaceAll(word, "eightwo", "82" ) word = strings.ReplaceAll(word, "nineight", "98" ) word = strings.ReplaceAll(word, "eightthree", "83" ) word = strings.ReplaceAll(word, "threeight", "38" ) word = strings.ReplaceAll(word, "fiveight", "58" ) word = strings.ReplaceAll(word, "nineight", "98" ) word = strings.ReplaceAll(word, "oneight", "18" ) word = strings.ReplaceAll(word, "sevenine", "79" ) v := []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} for x := range v { word = strings.ReplaceAll(word, fmt.Sprintf("%d", x+1), v[x]) } p := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"} for x := range p { word = strings.ReplaceAll(word, v[x], p[x]) } return word } are you into systems or network programming? |
Re: [AOC December 2023] by Deicide: 3:49pm On Feb 14 |
BBIA:
are you into systems or network programming? both |
Re: [AOC December 2023] by BBIA: 5:06pm On Feb 14 |
Deicide: both no wonder you use golang. |