Advent of code

 10 décembre 2015 

  Elves Look, Elves Say :
  1. code_partie1.py
  2. code_partie1_oneLiner.py
  3. code_partie1_realOneLiner.py
  4. code_partie2_coupure.py
  5. code_partie2_coupure_moinsEfficace.py
  6. code_partie2_coupures.diffy
  7. code_partie2_elements.py
from functools import cache                                     from functools import cache
from itertools import groupby                                   from itertools import groupby

inputString = '1113222113'                                      inputString = '1113222113'

def nbRepet(s):                                                 def nbRepet(s):
    c = s[0]                                                        c = s[0]
    n = 1                                                           n = 1
    for i in range(1,len(s)):                                       for i in range(1,len(s)):
        if s[i] != c:                                                   if s[i] != c:
            break                                                           break
        n += 1                                                          n += 1
    return n                                                        return n

@cache                                                          @cache
def lookandsay(s):                                              def lookandsay(s):
    if len(s) < 10:                                                 if len(s) < 10:
        return ''.join([(str(len(list(i[1])))+i[0]) for i in            return ''.join([(str(len(list(i[1])))+i[0]) for i in 
    coupure = len(s) // 2                                           coupure = len(s) // 2
    while coupure > 0 and s[coupure] == s[coupure - 1]:       |     a = lookandsay(s[:coupure])
        coupure -= 1                                          |     b = lookandsay(s[coupure:])
    return lookandsay(s[:coupure]) + lookandsay(s[coupure:])  |     if a[-1] == b[1]:
                                                              >         return a[:-2] + str(int(a[-2])+int(b[0])) + b[1:]
                                                              >     else:
                                                              >         return a + b


s = inputString                                                 s = inputString

for i in range(50):                                             for i in range(50):
    s = lookandsay(s)                                               s = lookandsay(s)

print(len(s))                                                   print(len(s))