Skip to content
Create a gist now

Instantly share code, notes, and snippets.

acsl intermediate contest 2 in one line
# Taeer Bar-Yam
# Commonweath School
# Division Intermediate - 3
# Tested with Rakudo 2012.01
(open('acsl2.txt'){[.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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.