Skip to content

Instantly share code, notes, and snippets.

@vojtechmares
Last active December 13, 2023 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtechmares/df5aa04ee0c91714b3ff017b2321e0a6 to your computer and use it in GitHub Desktop.
Save vojtechmares/df5aa04ee0c91714b3ff017b2321e0a6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strconv"
)
func max(a, b int) int {
if a >= b {
return a
}
return b
}
// based on https://twitter.com/EmmaBostian/status/1449289480989462531?s=20
func main() {
s := ""
a := "1112031584"
aRune := []rune(a)
for i := 1; i < len(a); i++ {
ai, _ := strconv.Atoi(fmt.Sprintf("%c", aRune[i]))
ai1, _ := strconv.Atoi(fmt.Sprintf("%c", aRune[i-1]))
if ai%2 == ai1%2 {
s = fmt.Sprintf("%s%d", s, max(ai, ai1))
}
}
fmt.Printf("https://multisoft.se/%s/\n", s) // outputs https://multisoft.se/112358/
}
@georgekakarlis
Copy link

cool!! im a junior dev looking for that solution! thnx

@vojtechmares
Copy link
Author

@georgekakarlis If you know what modulo operator does, you can do it in your head or on paper. Which I did and I just got curious how it would look like in Go. Mostly, because the original ad has no type casting from string to integer and I wanted to do something fun this morning. Turned out I don't know type casting well in Go :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment