#! /usr/bin/env python
# -*- coding: utf-8 -*- 

#=========================================================================
# Ejercicio en: http://www.pythonchallenge.com/pc/return/evil.html
# Solución: 5 imágenes, dis-pro-port-ional- 
# Obtenemos: http://www.pythonchallenge.com/pc/return/disproportional.html
#-------------------------------------------------------------------------
# FJA - neocipres@telefonica.net            Junio de 2007
# visto en: http://nberserk.tistory.com/39
#=========================================================================

#usuario: huge, password: file
#descarga http://www.pythonchallenge.com/pc/return/evil2.gfx

import Image

gfx = open('evil2.gfx')
files=[open('12-result'+str(i),'w') for i in range(5)]

count =0
while 1:
        byte = gfx.read(1)
        if not byte: break
        files[count%5].write(byte)
        count += 1
[file.close for file in files]

for i in range(5):
    try:
        img = Image.open("12-result"+str(i))
            
    except IOError, detalle:
        print detalle
    else:
        img.show()

# Da error de lectura, pero se crean las imágenes. La cuarta está corrupta,
# pero se puede abrir con firefox.
