![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() ![]() |
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('')
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
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;} |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#4 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
Quote:
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|