From a0b6ee30072f3c8ebff70917626d6ea1445041a6 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Mon, 5 Apr 2021 23:20:35 +0000 Subject: [PATCH] Initial commit. --- alphabetter.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ license.md | 24 ++++++++++++++ readme.md | 28 ++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 alphabetter.go create mode 100644 license.md create mode 100644 readme.md diff --git a/alphabetter.go b/alphabetter.go new file mode 100644 index 0000000..47856bf --- /dev/null +++ b/alphabetter.go @@ -0,0 +1,86 @@ +package main + +import ( + "fmt" + "log" + "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", +} + +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)) + for { + alphabet = sort_alphabet(alphabet) + if string(alphabet) == prev { + return + } + prev = string(alphabet) + fmt.Println(prev) + } +} + +// sort the provided alphabet (a slice of runes) by spelling, using the alphabet itself +// as the lexicographic ordering. Return the new alphabet. +func sort_alphabet(alphabet []rune) []rune { + new_alphabet := make([]rune, len(alphabet)) + copy(new_alphabet, alphabet) + sort.Slice(new_alphabet, func(i, j int) bool { + i_spelling := SPELLINGS[new_alphabet[i]] + j_spelling := SPELLINGS[new_alphabet[j]] + + i_index := -1 + j_index := -1 + + k := 0 + for k = 0; k < len(i_spelling) && k < len(j_spelling); k++ { + i_index = find_index(alphabet, rune(i_spelling[k])) + j_index = find_index(alphabet, rune(j_spelling[k])) + + if i_index != j_index { + break + } + } + return i_index < j_index + }) + return new_alphabet +} + +func find_index(alphabet []rune, target rune) int { + for i, letter := range alphabet { + if letter == target { + return i + } + } + log.Panicf("Tried to find a letter that doesn't exist") + return -1 +} diff --git a/license.md b/license.md new file mode 100644 index 0000000..313351c --- /dev/null +++ b/license.md @@ -0,0 +1,24 @@ +Copyright 2021 annabunches@gmail.com + +⚠️ WARNING! ⚠️ +☢️ 😱 DO NOT USE THIS PROGRAM. 😱 ☢️ +This program is not a program of honor. + +No highly esteemed function is executed here. + +What is here is dangerous and repulsive to us. + +The danger is still present, in your time, as it was in ours, +without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. + +This program is best shunned and left unused (but it is free software, +and you are welcome to redistribute it under certain conditions). +😱 ☢️ DO NOT USE THIS PROGRAM. ☢️ 😱 + +This program is licensed under the Sandia Message Public License, +sublicense Do What The Fuck You Want To Public License. +This may be abbreviated as sandia-wtfpl. +You may obtain a copy of the License(s) at +https://github.com/cdanis/sandia-public-license/blob/main/LICENSE.md and +http://www.wtfpl.net/txt/copying/ diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..189821c --- /dev/null +++ b/readme.md @@ -0,0 +1,28 @@ +# Alphabetter - procedurally improving the alphabet + +Inspired by @rfglenn's [tweet](https://twitter.com/rfglenn/status/1378555751870820354?s=21) about alphabetizing the alphabet, +Alphabetter is a shitpost that "improves" the alphabet by sorting the letters lexicographically by their canonical +(American English) spellings. + +But it doesn't stop there. It then sorts the "new" alphabet by *its own* order, and then sorts THAT alphabet, iteratively, with +the goal of finding a "steady state", that is, an alphabet that is already alphabetized. (according to its own order) + +This happens after only 3 iterations, yielding the "better" alphabet: + +``` +rahbdwyuieflmnsxcqgjkoptvz +``` + +## Usage + +If for some reason you want to run this code, just do + +``` +go build alphabetter.go +``` + +with nearly any version of golang installed. Then execute it with + +``` +./alphabetter +```