"""
Created on: Thu Nov 24 02:48:49 2022
Author: vila@cs.upc.edu
"""
def salta(l, i):
    lsol = []
    while 0 <= i < len(l) and i not in lsol:
        lsol.append(i)
        i = l[i]
    lsol.append(i)
    return lsol
    
'''
    VERSIO MES EFICIENT: les posicions visitades es guarden en un diccionari amb clau la posicio i valor el booleà True (enlloc de fer-ho amb l operador in sobre llistes ).
    
    d = {}
    i = i0
    while i not in d:
        d[i] = True
        i = l[i]
    l = list(d.keys())
    l.append(i)
    return l
'''
