Created
March 5, 2012 03:35
-
-
Save Radvendii/1976325 to your computer and use it in GitHub Desktop.
acsl intermediate contest 2 in one line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taeer Bar-Yam | |
# Commonweath School | |
# Division Intermediate - 3 | |
# Tested with Rakudo 2012.01 | |
say | |
( | |
(open('acsl2.txt').lines.map({[.split(' ')]} #Read input and split into lines, and split each line into array by spaces (as specified) | |
).map( #loop over first level array (each line) | |
{ | |
[( #array reference (so that the array doesn't flatten) | |
$^a[2..*].grep( # [2..*]: ignore first two members of list (shorthand bitstring and num of elems to follow) Filter the rest (bitstrings to match) by: | |
/^<{ #matches the following at the beginning of the elem | |
$a[0].subst(:g, '*', '[ (0|1) ]') # match the first elem (bitstring) with *s replaced with [ (0|1) ] which is parsed as 0 or 1 | |
}>$/ #until the end of the elem (has to be the whole thing, not a substring) | |
) #end of filter (grep) | |
)] | |
} | |
).map(*.join(' ')).join("\n") #join each elem (bitstring) with space and join each array of bitstrings with newline | |
).subst(:g, /\n[$|$$]/, "\nNone") #Replace an empty line (\n: newline [$|$$]: end of line or end of string) with "None" | |
) | |
; #DONE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment