Skip to content

Commit

Permalink
All code up
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Angel Julian Aguilar committed May 7, 2012
1 parent 2d950a2 commit 70ea0d9
Show file tree
Hide file tree
Showing 40 changed files with 236,694 additions and 0 deletions.
Binary file added CANTTF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 141 additions & 0 deletions Reto1/phone_keyboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/python

#Autor: Miguel Angel Julian Aguilar
#e-mail: [email protected]

import sys
import string

class Key:
def __init__(self,keys):
self.keys=keys
def pressToKey(self,key):
if not key in self.keys: return 0
else: return 1+self.keys.index(key)

keys={}
keys[1]=Key([' ','1'])
keys[2]=Key(['a','b','c','2'])
keys[3]=Key(['d','e','f','3'])
keys[4]=Key(['g','h','i','4'])
keys[5]=Key(['j','k','l','5'])
keys[6]=Key(['m','n','o','6'])
keys[7]=Key(['p','q','r','s','7'])
keys[8]=Key(['t','u','v','8'])
keys[9]=Key(['w','x','y','z','9'])
keys[0]=Key(['0'])
keys['may']=Key(['may'])

charToKey={}
charToKey['0']=0
charToKey['1']=1
charToKey['2']=2
charToKey['3']=3
charToKey['4']=4
charToKey['5']=5
charToKey['6']=6
charToKey['7']=7
charToKey['8']=8
charToKey['9']=9
charToKey[' ']=1
charToKey['a']=2
charToKey['b']=2
charToKey['c']=2
charToKey['d']=3
charToKey['e']=3
charToKey['f']=3
charToKey['g']=4
charToKey['h']=4
charToKey['i']=4
charToKey['j']=5
charToKey['k']=5
charToKey['l']=5
charToKey['m']=6
charToKey['n']=6
charToKey['o']=6
charToKey['p']=7
charToKey['q']=7
charToKey['r']=7
charToKey['s']=7
charToKey['t']=8
charToKey['u']=8
charToKey['v']=8
charToKey['w']=9
charToKey['x']=9
charToKey['y']=9
charToKey['x']=9
charToKey['may']='may'

keysToRowCol={}
keysToRowCol[1]={'c':0, 'r':0}
keysToRowCol[2]={'c':1, 'r':0}
keysToRowCol[3]={'c':2, 'r':0}
keysToRowCol[4]={'c':0, 'r':1}
keysToRowCol[5]={'c':1, 'r':1}
keysToRowCol[6]={'c':2, 'r':1}
keysToRowCol[7]={'c':0, 'r':2}
keysToRowCol[8]={'c':1, 'r':2}
keysToRowCol[9]={'c':2, 'r':2}
keysToRowCol[0]={'c':1, 'r':3}
keysToRowCol['may']={'c':2, 'r':3}

def movesFromKeyToKey(start,end):
global keysToRowCol
diffCols=abs(keysToRowCol[start]['c']-keysToRowCol[end]['c'])
diffRows=abs(keysToRowCol[start]['r']-keysToRowCol[end]['r'])
diag=min(diffCols,diffRows)
vert=diffRows-diag
horiz=diffCols-diag
return [horiz,vert,diag]

timeVert=300
timeHori=200
timeDiag=350
timePres=100
timeSame=500

lineCount=0
for line in sys.stdin:
if lineCount is 0:
lineCount=1
continue
actual_key=0
capsLoc=False
changeCapsLoc=False
horiz=0
vert=0
diag=0
pulses=0
sameKeyWait=0
for char in line:
if charToKey.has_key(char.lower()):
k=charToKey[char.lower()]
if char in string.ascii_lowercase and capsLoc:
changeCapsLoc=True
elif char in string.ascii_uppercase and not capsLoc:
changeCapsLoc=True
else:
changeCapsLoc=False
char=char.lower()
if(changeCapsLoc):
moves=movesFromKeyToKey(actual_key,'may')
horiz=horiz+moves[0]
vert=vert+moves[1]
diag=diag+moves[2]
pulses=pulses+1
actual_key='may'
capsLoc=not capsLoc
if actual_key==k:
sameKeyWait=sameKeyWait+1
else:
moves=movesFromKeyToKey(actual_key,k)
horiz=horiz+moves[0]
vert=vert+moves[1]
diag=diag+moves[2]
actual_key=k
pulses=pulses+keys[k].pressToKey(char)
print horiz*timeHori+vert*timeVert+diag*timeDiag+pulses*timePres+sameKeyWait*timeSame




8 changes: 8 additions & 0 deletions Reto1/testIn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
7
One a robot may not injure a human being or through inaction allow a human being to come to harm
Two a robot must obey the orders given it by human beings except where such orders would conflict with the First Law
Three a robot must protect its own existence as long as such protection does not conflict with the First or Second Laws
The conflict between the various rules is ironed out by the different positronic potentials in the brain
Well say that a robot is walking into danger and knows it The automatic potential that Rule 3 sets up turns him back
But suppose you order him to walk into that danger
In that case Rule 2 sets up a counterpotential higher than the previous one and the robot follows orders at the risk of existence
54 changes: 54 additions & 0 deletions Reto10/lenguaje.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python

#Autor: Miguel Angel Julian Aguilar
#e-mail: [email protected]


import sys

for line in sys.stdin:
numbers=[]
elements_chars = line.strip().split()
for element in elements_chars:
try:
n=int(element)
numbers.append(n)
except Exception, e:
if element=='@':
lastNum=numbers.pop()
antLasNum=numbers.pop()
numbers.append(lastNum+antLasNum)
elif element=='$':
lastNum=numbers.pop()
antLasNum=numbers.pop()
numbers.append(antLasNum-lastNum)
elif element=='&':
lastNum=numbers.pop()
antLasNum=numbers.pop()
numbers.append(antLasNum/lastNum)
elif element=='#':
lastNum=numbers.pop()
antLasNum=numbers.pop()
numbers.append(antLasNum*lastNum)
elif element=='mirror':
lastNum=numbers.pop()
numbers.append(-lastNum)
elif element=='dance':
lastNum=numbers.pop()
antLasNum=numbers.pop()
numbers.append(lastNum)
numbers.append(antLasNum)
elif element=='fire':
lastNum=numbers.pop()
elif element=='breadandfish':
numbers.append(numbers[-1])
elif element=='conquer':
lastNum=numbers.pop()
antLasNum=numbers.pop()
numbers.append(antLasNum%lastNum)
elif element=='.':
print numbers[-1]




9 changes: 9 additions & 0 deletions Reto10/testIn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
4 mirror .
3 breadandfish # .
5 3 fire .
3 1 $ .
3 1 dance $ .
4 2 conquer .
4 2 & .
1 1 @ .
2 3 @ 1 $ .
147 changes: 147 additions & 0 deletions Reto11/scrab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/python

#########################################################################
# Program will create words for scrabble given letters and words already
# Date Created: 6/15/11
# Date Finished: TBA
# FileName: Scrabble.py
#########################################################################

#Modificado por: Miguel Angel Julian Aguilar
#Ajustado para el Tuenti contest
#e-mail: [email protected]


import itertools
from sets import Set
import sys


getPoints={}
getPoints['a']=1
getPoints['e']=1
getPoints['i']=1
getPoints['l']=1
getPoints['n']=1
getPoints['o']=1
getPoints['r']=1
getPoints['s']=1
getPoints['t']=1
getPoints['u']=1
getPoints['d']=2
getPoints['g']=2
getPoints['b']=3
getPoints['c']=3
getPoints['m']=3
getPoints['p']=3
getPoints['f']=4
getPoints['h']=4
getPoints['v']=4
getPoints['w']=4
getPoints['y']=4
getPoints['k']=5
getPoints['j']=8
getPoints['x']=8
getPoints['q']=10
getPoints['z']=10

def getWordPoints(word):
global getPoints
points=0
for letter in word:
points=points+getPoints[letter.lower()]
return points

#########################################################################
# Class implements program mechanics
# Such as setting up global variables and...
# Handling events and procedures used in the program
#########################################################################
class Program:
# CTOR and Set up values
def __init__(self):
self.words = []
self.letters = []
# Load words in dictionary file
self.maxLength=0
self.dictionaryEntries = Set(x.strip() for x in open('descrambler_wordlist.txt', 'r').readlines())
for w in self.dictionaryEntries: self.maxLength=max(self.maxLength, len(w))




#####################################################################
# FindWords - Find Words give letters user has and...
# Words on the board
# Returns a list of possible words
#####################################################################
def FindWords(self, words, letters):
self.words = words
self.letters = letters
possibleResults = [('',0)]
possibleWords = ['']
letterCombinations = self.Rotate()
combo = ''

# Check if possible to add on word on to existing word
for x in letterCombinations:
# Convert tuple of letters to one continuous string
combo = ''.join(x)
for word in self.words:
# Check if combination can be added on, before...
# Or inbetween
for i in range(len(combo) + 1):
#if combo[:len(combo) - i] + word + combo[len(combo) - i:] in self.dictionaryEntries:
# possibleWords.append(combo[:len(combo) - i] + word + combo[len(combo) - i:])

for letter in word:
newWord=combo[:len(combo) - i] + letter + combo[len(combo) - i:]
if newWord in self.dictionaryEntries and newWord not in possibleWords:
wordPoints=getWordPoints(newWord)
if wordPoints>possibleResults[0][1]:
possibleResults=[(newWord,wordPoints)]
possibleWords=[newWord]
elif wordPoints==possibleResults[0][1]:
possibleResults.append((newWord,wordPoints))
possibleWords.append(newWord)


combo = ''

return possibleResults



#####################################################################
# Rotate - Find different combinations of letters passed in as...
# Member of class
# Returns a list of the letter combinations
#####################################################################
def Rotate(self):
# Contains letter combinations
x = []

# Find all possible letter combinations
for i in range(1, len(self.letters) + 1):
for j in itertools.permutations(self.letters, min(i,self.maxLength)):
x.append(j)

return x



lines=sys.stdin.readlines()
nCases=int(lines.pop(0).strip())
program = Program()

for line in lines:
lineData=line.strip().split()
myletters=list(lineData[0].upper())
deskWords=[lineData[1].upper()]


res=program.FindWords(deskWords, myletters)
res=sorted(res, key=lambda word: (word[0],word[1]))
print '%s %d' % res[0]


11 changes: 11 additions & 0 deletions Reto11/testIn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10
GDC POA
DL ARENIG
DUJ CELLULOTOXIC
IGG UNHUMOURED
RD COLTHOOD
MM GREENCOAT
CMH PANNERY
RH HUNTSWOMAN
LXYTA INTERLEAVER
MOCMH FACULTATIVELY
Loading

0 comments on commit 70ea0d9

Please sign in to comment.