Last active
December 13, 2023 15:08
-
-
Save vojtechmares/df5aa04ee0c91714b3ff017b2321e0a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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
cool!! im a junior dev looking for that solution! thnx