Rules: no spoilers.

The other rules are made up as we go along.

Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.

  • @froztbyte
    link
    English
    310 months ago

    rule 5: one code enters, 7 codes leave

    • @froztbyte
      link
      English
      3
      edit-2
      10 months ago

      okay yeah so

      p1 part 1 submitted, runs fine. part 2 says “wrong answer for you but right for someone else”. doing a debug-print-everything run on the intermediate stages of the data after my regex all seems correct, but it’s also 23h50 and it’s been a looooong week. so I guess I’ll take a look a fresh look at that one in the morning over coffee

      part1, badly:

      spoiler
      import re
      
      pattern = '\d'
      cmp = re.compile(pattern)
      
      # extremely lazy, of the ungood kind
      datapath = 'data'
      lines = open(datapath, 'r').read().split('\n')
      candidates = []
      values = []
      for l in lines:
          if l != '':
              r = cmp.findall(l)
              candidates.append(r)
              values.append(int(''.join([r[0], r[-1]])))
      
      print(candidates)
      print(values)
      print(sum(values))
      

      (I really wasn’t kidding about the badly)

      part2:

      spoiler

      missed the eightwo case

      changes:

      mapping = {...} # name/int pairs
      pattern = f'(?=(\d|{"|".join(mapping.keys())}))'
      lines = open(datapath, 'r').read().split('\n').remove('')
      values = []
      for l in lines:
          r = cmp.findall(l)
          equivs = [str(mapping.get(x, x)) for x in r]
          head, tail = [equivs[0], equivs[-1]]
          values.append(int(f"{head}{tail}"))
      print(sum(values))