Skip to content

Commit

Permalink
minor changes to some files
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Angel Julian Aguilar committed May 7, 2012
1 parent 70ea0d9 commit 2e6bf26
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 83 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
TuentiChallenge2
================

TuentiChallenge 2
TuentiChallenge 2

Solutions to the 2nd edition of the TuentiChallenge in Python.
12 changes: 1 addition & 11 deletions Reto13/lasVegas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#e-mail: [email protected]

import sys
from time import sleep

def find_gcf(dividend,divisor):
reminder=-1
Expand All @@ -24,9 +23,6 @@ def find_lcm(x,y,gcf):
lines=sys.stdin.readlines()
nCases=int(lines.pop(0).strip())

#lines=[]
#lines.append('100 50')

lineCount=1
for line in lines:
lineData=line.strip().split()
Expand Down Expand Up @@ -69,8 +65,6 @@ def find_lcm(x,y,gcf):
nChanges=[]
rs=1

#print 'comienzo la busqueda'

checked=[]
for i in range(nCards):
nCh=0
Expand All @@ -79,19 +73,15 @@ def find_lcm(x,y,gcf):
checked.append(su)
nCh=nCh+1
su=su+indexChanges[su]
#print len(checked)
if nCh>rs:
dividend=nCh
divisor=rs
else:
dividend=rs
divisor=nCh
#print 'i',

gcf=find_gcf(dividend,divisor)
rs=find_lcm(nCh,rs,gcf)
#print 'o'
#if i%100 is 0:
#print i

print 'Case #%d: %d' % (lineCount,rs)
lineCount+=1
118 changes: 47 additions & 71 deletions Reto4/karts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#Autor: Miguel Angel Julian Aguilar
#e-mail: [email protected]

#Not so proud of this one

import sys

lines=sys.stdin.readlines()
Expand All @@ -14,80 +16,54 @@
exit()

for caso in range(numero_de_casos):
#try:
pista=lines.pop(0).strip()
#print pista
grupos=lines.pop(0).strip()
pistaDatos=pista.split()
grupos=grupos.split()
races=int(pistaDatos[0])
karts=int(pistaDatos[1])
groupsN=int(pistaDatos[2])
litros=0
gruposEnCarrera=[]

#gruposDeCarrera=[int(grupos[0])]
gruposDeCarrera=[0]
#indice=1%groupsN
indice=0
#freeKarts=karts-gruposDeCarrera[0]
freeKarts=karts
#gruposAdded=1
gruposAdded=0
freeKarts1=[]
indicesCarrerasIndex0=[]
pista=lines.pop(0).strip()
grupos=lines.pop(0).strip()
pistaDatos=pista.split()
grupos=grupos.split()
races=int(pistaDatos[0])
karts=int(pistaDatos[1])
groupsN=int(pistaDatos[2])
litros=0
gruposEnCarrera=[]

gruposDeCarrera=[0]
indice=0
freeKarts=karts
gruposAdded=0
freeKarts1=[]
indicesCarrerasIndex0=[]

while len(gruposDeCarrera)<=races:
#print freeKarts
if indice==0:
#print 'karts libres: ',freeKarts,' carreras: ',len(gruposDeCarrera)
if freeKarts in freeKarts1:
#print 'fin por subconjunto encontrado'
#print 'bucle'
#print 'indice de aparicion en el bucle:',freeKarts1.index(freeKarts)
#print 'tengo',len(gruposDeCarrera),'carreras diferentes'
racesBeforeLoop=indicesCarrerasIndex0[freeKarts1.index(freeKarts)]
if freeKarts is not 0:
racesBeforeLoop=racesBeforeLoop-1
gruposDeCarrera.pop(-1)
#print 'llevaba',racesBeforeLoop,'antes del bucle'
loopSize=len(gruposDeCarrera)-racesBeforeLoop
loopRaces=gruposDeCarrera[(len(gruposDeCarrera)-loopSize):]
#print 'me quedo con un conjunto de',loopSize,'carreras'
#print 'numero de veces que se repite el subconjunto: ',(races-racesBeforeLoop)/loopSize
#print 'carreras que faltan: ',(races-racesBeforeLoop)%loopSize
#print 'karts:',freeKarts,'lista freeKarts:',freeKarts1,'indice:',indicesCarrerasIndex0,'loop:',loopRaces,'carreras:',gruposDeCarrera
litros=sum(gruposDeCarrera[:racesBeforeLoop])+((races-racesBeforeLoop)/loopSize)*sum(loopRaces)+sum(loopRaces[:(races-racesBeforeLoop)%loopSize])
break
else:
freeKarts1.append(freeKarts)
indicesCarrerasIndex0.append(len(gruposDeCarrera))
if freeKarts>=int(grupos[indice]) and gruposAdded<groupsN:
freeKarts=freeKarts-int(grupos[indice])
gruposDeCarrera[-1]=gruposDeCarrera[-1]+int(grupos[indice])
while len(gruposDeCarrera)<=races:
if indice==0:
if freeKarts in freeKarts1:
racesBeforeLoop=indicesCarrerasIndex0[freeKarts1.index(freeKarts)]
if freeKarts is not 0:
racesBeforeLoop=racesBeforeLoop-1
gruposDeCarrera.pop(-1)
loopSize=len(gruposDeCarrera)-racesBeforeLoop
loopRaces=gruposDeCarrera[(len(gruposDeCarrera)-loopSize):]
litros=sum(gruposDeCarrera[:racesBeforeLoop])+((races-racesBeforeLoop)/loopSize)*sum(loopRaces)+sum(loopRaces[:(races-racesBeforeLoop)%loopSize])
break
else:
if indice==0:
#print 'fin por conjunto encontrado'
#print 'tengo',len(gruposDeCarrera),'carreras diferentes'
#print 'numero de veces que se repite el conjunto: ',races/len(gruposDeCarrera)
#print 'carreras que faltan: ',races%len(gruposDeCarrera)
#print 'litros del grupo:',sum(gruposDeCarrera)
litros=(races/len(gruposDeCarrera))*sum(gruposDeCarrera)+sum(gruposDeCarrera[0:races%len(gruposDeCarrera)])
#print 'litros totales:',litros
break
gruposDeCarrera.append(int(grupos[indice]))
freeKarts=karts-int(grupos[indice])
gruposAdded=0
indice=(indice+1)%groupsN
gruposAdded=gruposAdded+1
#print indice,gruposDeCarrera[-1],len(gruposDeCarrera)
if len(gruposDeCarrera)>races:
#print 'fin por limite de carreras'
litros=sum(gruposDeCarrera[:races])
freeKarts1.append(freeKarts)
indicesCarrerasIndex0.append(len(gruposDeCarrera))
if freeKarts>=int(grupos[indice]) and gruposAdded<groupsN:
freeKarts=freeKarts-int(grupos[indice])
gruposDeCarrera[-1]=gruposDeCarrera[-1]+int(grupos[indice])
else:
if indice==0:
litros=(races/len(gruposDeCarrera))*sum(gruposDeCarrera)+sum(gruposDeCarrera[0:races%len(gruposDeCarrera)])
break
gruposDeCarrera.append(int(grupos[indice]))
freeKarts=karts-int(grupos[indice])
gruposAdded=0
indice=(indice+1)%groupsN
gruposAdded=gruposAdded+1

if len(gruposDeCarrera)>races:
litros=sum(gruposDeCarrera[:races])

print litros
#except Exception, e:
#print e
print litros



0 comments on commit 2e6bf26

Please sign in to comment.