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.
This commit is contained in:
Anna Rose 2021-04-06 03:02:18 +00:00
parent 60d463a546
commit 48d1a97acd
2 changed files with 67 additions and 33 deletions

View File

@ -3,49 +3,80 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"os"
"sort" "sort"
) )
var SPELLINGS = map[rune]string{ var SPELLINGS = map[rune]string{
'a': "ay", 'A': "AY",
'b': "bee", 'B': "BEE",
'c': "see", 'C': "SEE",
'd': "dee", 'D': "DEE",
'e': "ee", 'E': "EE",
'f': "eff", 'F': "EFF",
'g': "gee", 'G': "GEE",
'h': "aitch", 'H': "AITCH",
'i': "eye", 'I': "EYE",
'j': "jay", 'J': "JAY",
'k': "kay", 'K': "KAY",
'l': "ell", 'L': "ELL",
'm': "emm", 'M': "EMM",
'n': "enn", 'N': "ENN",
'o': "oh", 'O': "OH",
'p': "pee", 'P': "PEE",
'q': "cue", 'Q': "CUE",
'r': "arr", 'R': "ARR",
's': "ess", 'S': "ESS",
't': "tee", 'T': "TEE",
'u': "ewe", 'U': "EWE",
'v': "vee", 'V': "VEE",
'w': "double ewe", 'W': "DOUBLE EWE",
'x': "ecks", 'X': "ECKS",
'y': "why", 'Y': "WHY",
'z': "zee", 'Z': "ZEE",
} }
func main() { 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'} random := false
prev := string(alphabet) infinite := false
fmt.Println(string(prev)) for i := 1; i < len(os.Args); i++ {
if os.Args[i] == "--random" {
random = true
}
if os.Args[i] == "--infinite" {
infinite = true
}
}
for { for {
alphabet = sort_alphabet(alphabet) var alphabet []rune
if string(alphabet) == prev { 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 return
} }
prev = string(alphabet)
fmt.Println(prev)
} }
} }

View File

@ -26,3 +26,6 @@ with nearly any version of golang installed. Then execute it with
``` ```
./alphabetter ./alphabetter
``` ```
To loop forever, run with `--infinite`.