public
Created

acsl intermediate contest 2 in one line

  • Download Gist
acsl2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.