News

Hints for Day 03

Written on 03.12.2022 16:03 by Sven Rahmann

Dear all,

for today's problem(s), we want to give a few hints because some things can be difficult to figure out.

  • Remember sets? If A and B are Python sets, their intersection is (A & B).
  • Assume you have a set S with a single element. How do you get the element? You cannot write S[0] because indexing does not work on sets. However, you can manually create an iterator over S and get its first element by e = next(iter(S)).
  • Since part 2 is structurally different from day 1, you may want to write different functions for part 1 and 2. It is ok to read the input file again for part 2. Or you initially store it in a list of strings from which you then do both part 1 and 2 (making sure that you never change the list in between).
  • If you have trouble getting a group of 3 lines (in part 2), take a look at the itertools module; they show example code how to implement a "batched" function (https://docs.python.org/3/library/itertools.html); alternatively read the whole input into a long list and then slice it.
  • Remember to move short (but slightly complex) calculations (like letter -> priority) to their own functions; you get much more readable code like that.

Addendum for day 02:

  • Or course, there are shorter and more elegant ways than enumerating all 9 combinations explicitly. But we would be happy to see a simple clean solution that treats all 9 cases correctly rather than a "clever" wrong solution.

Have fun with the problems!

Privacy Policy | Legal Notice
If you encounter technical problems, please contact the administrators.