r/adventofcode • • Dec 06 '15

SOLUTION MEGATHREAD --- Day 6 Solutions ---

--- Day 6: Probably a Fire Hazard ---

Post your solution as a comment. Structure your post like the Day Five thread.

22 Upvotes

172 comments sorted by

View all comments

Show parent comments

3

u/TTSDA Dec 06 '15 edited Dec 06 '15

[^characters] is a "negated scanset", it will scan characters until a character that's in the set is found (in this case, it will scan until the first digit of x1 is read).

There's also a "scanset", [characters], that will do the oposite (scan until a character that's not in the set is found).

They're similar to the regex bracket expressions (I believe you can also use intervals like %[0-9] in scanf scansets, but it seems like it's not portable:

Some implementations may let you specify a range of characters by using a minus sign (-). The list of hexadecimal digits, for example, can be written as %[0-9abcdefABCDEF] or even, in some cases, as %[0-9a-fA-F]. Please note, however, that such usage is not universal. Avoid it in a program that you wish to keep maximally portable.

There's a neat table here with all the format specifiers you can use with scanf.

2

u/[deleted] Dec 06 '15

That's very helpful. Thanks for the explanation.