Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested chains ? #6

Closed
atthom opened this issue Dec 4, 2020 · 0 comments
Closed

Nested chains ? #6

atthom opened this issue Dec 4, 2020 · 0 comments

Comments

@atthom
Copy link

atthom commented Dec 4, 2020

I am currently doing day 4 of adventofcode.com

Much of the job is just text parsing and I managed to do it with a nice "one-liner" thanks to this very neat package!

is_valid(pass) = (length(pass) == 8) | ((length(pass) == 7) & ("cid"  pass))

sol = @chain "./data/passport.txt" begin
    read(_, String)
    split(_, "\n\n")
    map(x -> replace(x, "\n" => " "), _)
    map(x -> split(x, " "), _)
    map(x -> map(y -> split(y, ":")[1], x), _)
    filter(is_valid, _)
    length
end

However, I found the maps and the map of a map difficult to read and I was unable to use nested chains (and the documentation).

Is it possible to do it with nested chains?

Some example string:

ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm

iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929

hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm

hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in

It's not really a bug so I would understand if you just close the issue.

@atthom atthom changed the title Nested chains issue Nested chains ? Dec 4, 2020
@atthom atthom closed this as completed Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant