Created
September 11, 2014 19:57
-
-
Save jfuerth/c51dcf8c2e1b29539b5b 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
23456431 | |
zeekoomes | |
213412345 | |
pyhooduku | |
234234 | |
rykeew | |
123123 | |
hydom | |
11223344 | |
bifaveek | |
494746215 | |
mujyjysud | |
657234865 | |
dimifipif |
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 ca.fuerth.misc; | |
import static java.lang.Long.*; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Memorator { | |
public static void main(String[] args) throws IOException { | |
for (String arg : args) { | |
System.out.println(arg + ": " + toMemorableString(parseLong(arg))); | |
} | |
if (args.length == 0) { | |
System.err.println("Reading stdin. Use blank line to abort."); | |
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | |
for (;;) { | |
String s = in.readLine(); | |
if (s.equals("")) { | |
break; | |
} | |
System.out.println(toMemorableString(parseLong(s))); | |
} | |
} | |
} | |
/** The code requires this list to have 16 entries */ | |
private static final String[] CONSONANTS = { | |
"b", "d", "f", "h", | |
"j", "k", "l", "m", | |
"n", "p", "r", "s", | |
"t", "v", "w", "z" }; | |
/** The code requires this list to have 8 entries */ | |
private static final String[] VOWELS = { | |
"a", "e", "ee", "i", | |
"o", "oo", "u", "y" }; | |
/** | |
* Makes a reasonably easy-to-pronounce gibberish word from the given number. On average, the word will have about as | |
* many characters as the number would have when printed as a decimal, but (especially for large numbers) it will be | |
* easier to remember as a single word. | |
* | |
* @param num The number to convert. | |
* @return The memorable string, unique to the given number. Never null. | |
*/ | |
public static String toMemorableString(long num) { | |
StringBuilder memorable = new StringBuilder(); | |
for (;;) { | |
memorable.append(CONSONANTS[(int) (num & 0xf)]); | |
num >>= 4; | |
if (num == 0) break; | |
memorable.append(VOWELS[(int) (num & 7)]); | |
num >>= 3; | |
if (num == 0) break; | |
} | |
return memorable.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment