Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,342 members, 7,811,991 topics. Date: Monday, 29 April 2024 at 05:22 AM

[AOC December 2023] - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / [AOC December 2023] (364 Views)

My Goal Of Earning $40k/month Before December 2023 Startup (2) (3) (4)

(1) (Reply) (Go Down)

[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 smiley
Re: [AOC December 2023] by Deicide: 7:42am On Dec 01, 2023
Day 1: Trebuchet?!

Writing the solution of this one in Go cool
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
}
Re: [AOC December 2023] by preciouswoman66(m): 2:57pm On Dec 06, 2023
Una dey try sha embarassed
Re: [AOC December 2023] by Loopdeeloopa: 7:54am On Feb 08
Deicide:
Day 1: Trebuchet?!

Writing the solution of this one in Go cool
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 cool
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.

(1) (Reply)

Javascripters Meetup Coming Up Saturday 11th Jul., 2020 / Reactjs Vs Angularjs / Are You A Codeigniter Developer?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.