Last active
December 20, 2019 11:45
-
-
Save Xjs/7f178d5278580a0c4dfdc224edf2af69 to your computer and use it in GitHub Desktop.
BauCH :o)
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" | |
"math/rand" | |
"os" | |
"strings" | |
"time" | |
"unicode" | |
) | |
const maxLen = 4 | |
func main() { | |
rand.Seed(int64(time.Now().Nanosecond())) | |
if len(os.Args) < 2 { | |
fmt.Println("uSAgE: bauch Nachricht in Nicht-Bauch-Format") | |
os.Exit(2) | |
} | |
input := strings.Join(os.Args[1:], " ") | |
output := make([]rune, len(input)) | |
nUpper := 0 | |
i := -1 | |
for _, c := range input { | |
i++ | |
if !unicode.IsLetter(c) { | |
output[i] = c | |
continue | |
} | |
if rand.Intn(2*maxLen) > maxLen+nUpper { | |
output[i] = unicode.ToUpper(c) | |
if nUpper >= 0 { | |
nUpper++ | |
} else { | |
nUpper = 0 | |
} | |
} else { | |
output[i] = unicode.ToLower(c) | |
if nUpper <= 0 { | |
nUpper-- | |
} else { | |
nUpper = 0 | |
} | |
} | |
} | |
output = output[:i+1] | |
fmt.Println(string(output), ":o)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment