Solució del lliurament 1 G20 d’Ampliació d’Informàtica

Organització:

Secció ETSEIB, Departament de Ciències de la Computació, UPC

Data:

2 d’octubre de 2024

Durada:

30 minuts

Copyright:

Reconeixement-CompartirIgual 3.0 No adaptada de Creative Commons

Jocs de proves

Els exemples que compten per la nota són només els que van seguits de # doctesttag: +TAG=

>>> from itertools import *

Tests per a posicions_robot

>>> from robot import posicions_robot
>>> lm = [('N',100), ('E',30), ('O',10), ('S',15), ('O',10)]
>>> it2 = posicions_robot(iter(lm))
>>> for x in it2:   # doctesttag: +TAG=1_posicions_robot
...    print(x, end='/')
(0, 0)/(0, 100)/(30, 100)/(20, 100)/(20, 85)/(10, 85)/
>>> d = 'NOSESONENOENSOEONSE'
>>> p = [20-10*i for i in range(1, 30)]
>>> it1 = zip(d[5:10], p)
>>> for x in posicions_robot(it1):   # doctesttag: +TAG=1_posicions_robot
...     print(x, end='/')
(0, 0)/(-10, 0)/(-10, 0)/(-20, 0)/(-20, -20)/(10, -20)/
>>> it1 = zip(d, p)
>>> for x in posicions_robot(it1):   # doctesttag: +TAG=1_posicions_robot
...     print(x, end='/')
(0, 0)/(0, 10)/(0, 10)/(0, 20)/(-20, 20)/(-20, 50)/(20, 50)/(20, 0)/(-40, 0)/(-40, -70)/(40, -70)/(-50, -70)/(-50, -170)/(-50, -60)/(70, -60)/(-60, -60)/(80, -60)/(80, -210)/(80, -50)/(-90, -50)/
>>> it1 = zip(d, p[::-1])
>>> for x in posicions_robot(it1):   # doctesttag: +TAG=1_posicions_robot
...     print(x, end='/')
(0, 0)/(0, -270)/(260, -270)/(260, -20)/(20, -20)/(20, 210)/(240, 210)/(240, 0)/(40, 0)/(40, -190)/(220, -190)/(50, -190)/(50, -350)/(50, -200)/(190, -200)/(60, -200)/(180, -200)/(180, -310)/(180, -210)/(90, -210)/
>>> it1 = zip(d[::-1], map(abs, p))
>>> for x in posicions_robot(it1):   # doctesttag: +TAG=1_posicions_robot
...     print(x, end='/')
(0, 0)/(10, 0)/(10, 0)/(10, 10)/(-10, 10)/(20, 10)/(-20, 10)/(-20, -40)/(-20, 20)/(50, 20)/(-30, 20)/(-30, 110)/(70, 110)/(70, 220)/(-50, 220)/(-50, 90)/(90, 90)/(90, -60)/(-70, -60)/(-70, 110)/
>>> it2 = islice(posicions_robot(cycle(lm)), 50, 55)
>>> for x in it2:
...    print(x, end='/')    # doctesttag: +TAG=1_posicions_robot
(100, 850)/(100, 950)/(130, 950)/(120, 950)/(120, 935)/

Tests per a elmina_de_seq

>>> from elimina import elimina_de_seq
>>> ln = [111, 222, 333, 444, 555, 666, 777]
>>> it1 = iter(ln)
>>> it2 = elimina_de_seq(it1, 3)
>>> for x in it2:
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
111/222/333/555/666/777/
>>> for x in elimina_de_seq(iter(ln), 0):
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
222/333/444/555/666/777/
>>> for x in elimina_de_seq(iter(ln*2), 12):
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
111/222/333/444/555/666/777/111/222/333/444/555/777/
>>> for x in elimina_de_seq(enumerate(ln), 7):
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
(0, 111)/(1, 222)/(2, 333)/(3, 444)/(4, 555)/(5, 666)/(6, 777)/
>>> for x in elimina_de_seq(iter('ABCD'*10), 20):
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
A/B/C/D/A/B/C/D/A/B/C/D/A/B/C/D/A/B/C/D/B/C/D/A/B/C/D/A/B/C/D/A/B/C/D/A/B/C/D/
>>> it1 = islice(elimina_de_seq(iter(range(100000)), 50000), 49990, 50010)
>>> for x in it1:
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
49990/49991/49992/49993/49994/49995/49996/49997/49998/49999/50001/50002/50003/50004/50005/50006/50007/50008/50009/50010/
>>> it1 = iter('QWERTYUIOP')
>>> for x in range(10):
...    it1 = elimina_de_seq(it1, 2)
>>> for x in it1:
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
Q/W/
>>> it1 = islice(elimina_de_seq(count(0), 10), 20)
>>> for x in it1:
...    print(x, end='/')    # doctesttag: +TAG=2_elimina_de_seq
0/1/2/3/4/5/6/7/8/9/11/12/13/14/15/16/17/18/19/20/