WordWhacker V0.2

PublishedActual
Birmingham New Street07:1007:10
London Euston08:3008:30

As previously covered, I have been trying to prove that there are some words and phrases that are equivalent to others in some way.

v0.2

The update to the process would be to generate the hash based on the ASCII charset, this added some extra complexity as spaces have a value and a capitalised letter is 32 smaller than its lower case equivalent, the ideal solution would be to write a bit of code, bring on the Java. The program I created was functional, in no way was it meant to be elegant, in no way was it supposed to live up to OO design, it’s a quick and dirty script.

 1package words;
 2
 3import java.util.HashMap;
 4import java.util.Map;
 5
 6/**
 7 * Class to generate numerical values for words and compare equivalence to other words.
 8 *
 9 * @author a
10 */
11public class WordWhackerV02 {
12
13    public enum Charset {
14        ASCII, UNICODE, POSITIONAL
15    }
16
17    public static Map<Character,Integer> letters = new HashMap<Character,Integer>();
18    public static Map<Character,Integer> asciiletters = new HashMap<Character,Integer>();
19    static {
20        asciiletters.put('A', 65);asciiletters.put('B', 66);asciiletters.put('C', 67);
21        asciiletters.put('D', 68);asciiletters.put('E', 69);asciiletters.put('F', 70);
22        asciiletters.put('G', 71);asciiletters.put('H', 72);asciiletters.put('I', 73);
23        asciiletters.put('J', 74);asciiletters.put('K', 75);asciiletters.put('L', 76);
24        asciiletters.put('M', 77);asciiletters.put('N', 78);asciiletters.put('O', 79);
25        asciiletters.put('P', 80);asciiletters.put('Q', 81);asciiletters.put('R', 82);
26        asciiletters.put('S', 83);asciiletters.put('T', 84);asciiletters.put('U', 85);
27        asciiletters.put('V', 86);asciiletters.put('W', 87);asciiletters.put('X', 88);
28        asciiletters.put('Y', 89);asciiletters.put('Z', 90);
29
30        asciiletters.put('a', 97); asciiletters.put('b', 98); asciiletters.put('c', 99);
31        asciiletters.put('d', 100);asciiletters.put('e', 101);asciiletters.put('f', 102);
32        asciiletters.put('g', 103);asciiletters.put('h', 104);asciiletters.put('i', 105);
33        asciiletters.put('j', 106);asciiletters.put('k', 107);asciiletters.put('l', 108);
34        asciiletters.put('m', 109);asciiletters.put('n', 110);asciiletters.put('o', 111);
35        asciiletters.put('p', 112);asciiletters.put('q', 113);asciiletters.put('r', 114);
36        asciiletters.put('s', 115);asciiletters.put('t', 116);asciiletters.put('u', 117);
37        asciiletters.put('v', 118);asciiletters.put('w', 119);asciiletters.put('x', 120);
38        asciiletters.put('y', 121);asciiletters.put('z', 122);asciiletters.put(' ', 20);
39
40        letters.put('a', 1); letters.put('b', 2); letters.put('c', 3); letters.put('d', 4);
41        letters.put('e', 5); letters.put('f', 6); letters.put('g', 7); letters.put('h', 8);
42        letters.put('i', 9); letters.put('j', 10);letters.put('k', 11);letters.put('l', 12);
43        letters.put('m', 13);letters.put('n', 14);letters.put('o', 15);letters.put('p', 16);
44        letters.put('q', 17);letters.put('r', 18);letters.put('s', 19);letters.put('t', 20);
45        letters.put('u', 21);letters.put('v', 22);letters.put('w', 23);letters.put('x', 24);
46        letters.put('y', 25);letters.put('z', 26);letters.put(' ', 0);
47    }
48
49    public Charset useCharset = Charset.ASCII;
50
51    /**
52     * @param args a {@link java.lang.String}[] of program arguments
53     */
54    public static void main(String[] args) {
55        WordWhackerV02 whacker = new WordWhackerV02();
56        whacker.useCharset = Charset.POSITIONAL;
57        String[] strings = new String[]{"Happiness", "Eternal Happiness",
58                            "Perpetual Happiness", "Happy Employees",
59                            "Motivational Happiness", "Creative Happiness",
60                            "Boundless Creativity"};
61        for(String val : strings) {
62            System.out.println(val + " " + whacker.getWordValue(val));
63        }
64    }
65
66    /**
67     * Method to return the numeric value for a given word
68     *
69     * @param word a {@link java.lang.String} containing the word
70     * @return an int representing the words numeric value
71     */
72    private int getWordValue(String word) {
73        int returnable = 0;
74        char[] chars = word.toCharArray();
75        for(char theChar : chars) {
76            Integer charValue = null;
77            switch(useCharset) {
78                case ASCII:
79                    charValue = asciiletters.get(theChar);
80                break;
81                case UNICODE:
82                    charValue = Character.getNumericValue(theChar);
83                break;
84                case POSITIONAL:
85                    charValue = letters.get(Character.toLowerCase(theChar));
86                break;
87                default:
88                break;
89            }
90            if(charValue != null) {
91                returnable = returnable + charValue;
92            }
93        }
94        return returnable;
95    }
96}

This script was useful for generating the values of input strings quickly but meant that I still had to think of phrases to compare against - surly an improvement to this would be to use a dictionary to search for numerically equivalent words.