Here's my (slight naive) solution. A commented version may follow later, but 
right now, I'm too lazy.

Raja Mukherji

link factors

procedure getStates()
    return [
        "Alabama", "Alaska", "Arizona", "Arkansas",
        "California", "Colorado", "Connecticut",
        "Delaware",    ##  "District of Columbia",
        "Florida", "Georgia", "Hawaii",
        "Idaho", "Illinois", "Indiana", "Iowa",
        "Kansas", "Kentucky", "Louisiana",
        "Maine", "Maryland", "Massachusetts", "Michigan",
        "Minnesota", "Mississippi", "Missouri", "Montana",
        "Nebraska", "Nevada", "New Hampshire", "New Jersey",
        "New Mexico", "New York", "North Carolina", "North Dakota",
        "Ohio", "Oklahoma", "Oregon",
        "Pennsylvania", "Rhode Island",
        "South Carolina", "South Dakota", "Tennessee", "Texas",
        "Utah", "Vermont", "Virginia",
        "Washington", "West Virginia", "Wisconsin", "Wyoming"
    ]
end

procedure getValue(Word)
    static Primes, Letters
    local Value
    initial {
        Primes := []
        every put(Primes, prime() \ 26)
        Letters := table(1)
        every I := 1 to 26 do {
            insert(Letters, char(ord("A") + I - 1), Primes[I])
            insert(Letters, char(ord("a") + I - 1), Primes[I])
        }
    }
    Value := 1
    every Value *:= Letters[!Word]
    return Value
end

procedure getPairs(Words)
    local I, J, N
    local Values, Word, Value, Pairs, Pair, PairTable
    N := *Words
    Values := []
    every put(Values, getValue(!Words))
    PairTable := table()
    every I := 1 to N do {
        every J := I + 1 to N do {
            Value := Values[I] * Values[J]
            if member(PairTable, Value) then {
                put(PairTable[Value], [Words[I], Words[J]])
            } else {
                insert(PairTable, Value, [[Words[I], Words[J]]])
            }
        }
    }
    every Pairs := !PairTable do {
        N := *Pairs
        if N > 1 then {
            writes(Pairs[1][1], " + ", Pairs[1][2])
            every I := 2 to N do {
                writes(" = ", Pairs[I][1], " + ", Pairs[I][2])
            }
            write()
        }
    }
end

procedure main()
    getPairs(getStates())
end

       
---------------------------------
 Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for 
your freeaccount today.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to