From 48d1a97acd1b7c356a4e3a745abaaa72a0b7cb63 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Tue, 6 Apr 2021 03:02:18 +0000 Subject: [PATCH] Several improvements and new features: * Use uppercase letters. * Print number of iterations it took to reach a steady state. * Add a --infinite mode that loops forever, and only prints the final outcome. * [WIP] Start with a random alphabet. --- alphabetter.go | 97 +++++++++++++++++++++++++++++++++----------------- readme.md | 3 ++ 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/alphabetter.go b/alphabetter.go index 47856bf..bfdbb53 100644 --- a/alphabetter.go +++ b/alphabetter.go @@ -3,49 +3,80 @@ package main import ( "fmt" "log" + "os" "sort" ) var SPELLINGS = map[rune]string{ - 'a': "ay", - 'b': "bee", - 'c': "see", - 'd': "dee", - 'e': "ee", - 'f': "eff", - 'g': "gee", - 'h': "aitch", - 'i': "eye", - 'j': "jay", - 'k': "kay", - 'l': "ell", - 'm': "emm", - 'n': "enn", - 'o': "oh", - 'p': "pee", - 'q': "cue", - 'r': "arr", - 's': "ess", - 't': "tee", - 'u': "ewe", - 'v': "vee", - 'w': "double ewe", - 'x': "ecks", - 'y': "why", - 'z': "zee", + 'A': "AY", + 'B': "BEE", + 'C': "SEE", + 'D': "DEE", + 'E': "EE", + 'F': "EFF", + 'G': "GEE", + 'H': "AITCH", + 'I': "EYE", + 'J': "JAY", + 'K': "KAY", + 'L': "ELL", + 'M': "EMM", + 'N': "ENN", + 'O': "OH", + 'P': "PEE", + 'Q': "CUE", + 'R': "ARR", + 'S': "ESS", + 'T': "TEE", + 'U': "EWE", + 'V': "VEE", + 'W': "DOUBLE EWE", + 'X': "ECKS", + 'Y': "WHY", + 'Z': "ZEE", } func main() { - alphabet := []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'} - prev := string(alphabet) - fmt.Println(string(prev)) + random := false + infinite := false + for i := 1; i < len(os.Args); i++ { + if os.Args[i] == "--random" { + random = true + } + if os.Args[i] == "--infinite" { + infinite = true + } + } + for { - alphabet = sort_alphabet(alphabet) - if string(alphabet) == prev { + var alphabet []rune + if random { + // todo + } else { + alphabet = []rune{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'} + } + prev := string(alphabet) + fmt.Println(string(prev)) + i := 0 + for { + alphabet = sort_alphabet(alphabet) + if string(alphabet) == prev { + if infinite { + fmt.Println(prev) + } + break + } + prev = string(alphabet) + if !infinite { + fmt.Println(prev) + } + i++ + } + fmt.Println("Iterations:", i) + + if !infinite { return } - prev = string(alphabet) - fmt.Println(prev) } } diff --git a/readme.md b/readme.md index 189821c..522d130 100644 --- a/readme.md +++ b/readme.md @@ -26,3 +26,6 @@ with nearly any version of golang installed. Then execute it with ``` ./alphabetter ``` + +To loop forever, run with `--infinite`. +