Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/gst -q
- parse_re := '(\d+)-(\d+) (.): (.*)$' asRegex.
- part1 := 0.
- part2 := 0.
- stdin linesDo:
- [
- :line |
- (line =~ parse_re) ifMatched: [ :results |
- " Aliases: "
- low := results at: 1.
- high := results at: 2.
- let := results at: 3.
- pass := results at: 4.
- " Part 1: "
- " Check for low-high occurrences of the letter in the password. "
- " Makes a regex that looks something like: ^([^a]*a[^a]*){1,3}$ "
- check_re := ('^([^', let, ']*', let, '[^', let, ']*){', low, ',', high, '}$') asRegex.
- (pass =~ check_re) ifMatched: [ part1 := part1 + 1 ].
- " Part 2: "
- " Check if low xor high position equals letter. "
- (((pass at: low asInteger) asString = let)
- xor: ((pass at: high asInteger) asString = let)) ifTrue:
- [
- part2 := part2 + 1.
- ]
- ]
- ].
- stdout nextPutAll: ('Part 1: ', part1 asString); nl.
- stdout nextPutAll: ('Part 2: ', part2 asString); nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement