Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 12th, 2005, 4:13 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Alphamatics!

Alphamatics are math questions with the numbers replaced by letters.

So like:

Your + Mom = Hawt

Can be:

8736 + 474 = 9210

For fun I made a program that can figure out the small ones like those pretty easily via brute force (because I don't want to figure out an algorithm/pattern).

"Dr Sane's Alphamatic Solver: Only does addition of 1-2 items on either side so far..."

#<Dependants>
x1 = "YOU"
x2 = ""
y1 = "AN"
y2 = "ASS"
#</Dependants>


"""

That is equivelent to the alphamatic:
< You = An + Ass >

Run the program to see the numerical numbers replacing the letters to make the statement true.

"""



#Module Imports
import sys, random, time

#Organize all the characters into one, and remove duplicate letters, define as 'all'
all = x1+x2+y1+y2
for a in range(len(all)):
    for b in range(len(all)):
        if (a != b) and (all[a] == all[b]):
            all = str(all[:a]+' '+all[a+1:])
all = all.replace(" ","")
if len(all)>10:print'Error: Too many different characters!';sys.exit()

class Sections(object):
    def __init__(self, string, all=all):

        #Initiate Variables
        self.All = all
        self.Name = string
        self.amount = 0

        #Count the number of valid characters
        for a in range(len(string)):
            try:
                if string[a]:
                    self.amount += 1
            except: pass

    def Assign(self, combination):

        val = 0
        #Loop equal to the number of letters in the item
        for a in range(self.amount):
            #Loop equal to the number of different characters in the alphamatic
            for c in range(len(self.All)):
                #If it finds the same letter as found in the Universal All variable, it continues forming the number
                if self.All[c] == self.Name[a]:
                    #Add to the number the next digit
                    val += combination[c]*(10**(self.amount-a-1))

        #Value is now the numerical value of the item
        self.Value = val

def AddCombination(Combinations):

    Open = True
    while Open:

        #The possible number choices range from 0 through 9
        Choice = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        comb = []

        #Cycle through the choices, picking out one random and placing in a new list
        while Choice != []:
            c = random.choice(Choice)
            comb.append(c)
            Choice.remove(c)

        #Make sure the combination is not a duplicate            
        Open = False
        for b in range(len(Combinations)):
            if Combinations[b] == comb:
                Open = True

    return comb        

#Declare the Combinations, and the combination index (zz)
Combinations = [ range(10) ]
zz = 0

#Declare the classes for each item
x1val = Sections(x1)
x2val = Sections(x2)
y1val = Sections(y1)
y2val = Sections(y2)

#Assign valid integers to all the letters
x1val.Assign(Combinations[zz])
x2val.Assign(Combinations[zz])
y1val.Assign(Combinations[zz])
y2val.Assign(Combinations[zz])

#While the first two items added together do not equal the last two items added together...
while (x1val.Value + x2val.Value) != (y1val.Value + y2val.Value):

    #Get a new combination
    Combinations.append(AddCombination(Combinations))

    #Try assigning the new combination 
    x1val.Assign(Combinations[zz])
    x2val.Assign(Combinations[zz])
    y1val.Assign(Combinations[zz])
    y2val.Assign(Combinations[zz])

    #Update the index
    zz += 1

    #Keep IDLE from thinking it's stalled
    if zz%100 == 0:print '.',

#Tell the user the answer
if not x2:x2 = " "
if not y2:y2 = " "
print '\n\n\n\n'
print ' '.join([x1,x2,y1,y2])
print "0"*(len(x1)-len(str(x1val.Value)))+str(x1val.Value),
if x2 == ' ':print x2,
else:print "0"*(len(x2)-len(str(x2val.Value)))+str(x2val.Value),
print "0"*(len(y1)-len(str(y1val.Value)))+str(y1val.Value),
if y2 == ' ':print y2,
else:print "0"*(len(y2)-len(str(y2val.Value)))+str(y2val.Value)
raw_input('')
Sane is offline   Reply With Quote
Old Oct 28th, 2005, 1:08 PM   #2
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Ban tpdragon and remove all his posts please, mod (Big_K).
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Oct 28th, 2005, 1:21 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,464
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
telepathdragon, your style of comments are not welcome here.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Oct 28th, 2005, 1:58 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
why dont you kill yourself
IR is kind. Don't make posts like this. Don't even fuck up and ask me why.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 28th, 2005, 2:02 PM   #5
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Quote:
Originally Posted by iignotus
Ban tpdragon and remove all his posts please, mod (Big_K).
i second that iignotus.... most energetically!
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Old Oct 28th, 2005, 2:07 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Steven, your avatar almost makes me wish for the old days, with 4 daughters. Fortunately, I haven't forgotten what they turn into as teens, so I routinely decline fathering others (not the activity, the outcome). Not to discourage you, of course; I would adopt her on the spot.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 28th, 2005, 2:32 PM   #7
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
She is such a sweetheart . I have noticed that every now and then you mention the perils and trials of fatherhood in conjunction with female teendom (and pre-teendom). Beginning to worry, I had considered asking about the major things I might want to be on my toes for. My sister was a perfect angel 'til she turned about sixteen, so I was hoping for about fifteen more years of what you see in the photo before the you-know-what hits the fan.
With my brothers and I it was the other way around.
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Old Oct 28th, 2005, 2:44 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I am not a wise man. I can only tell you this, and it's ineffective, as you're faced with the facts of what you have at hand. With a boy, you worry about one penis. With a girl, you have to worry about them all.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 28th, 2005, 2:57 PM   #9
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
ROFLMAO. Excellent! I will definitely have to remember that bit of wisdom.

Uh-oh...I feel the onset of a slightly unsettling apprehensiveness...
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC