Skip to content

Instantly share code, notes, and snippets.

@mavant
Created April 1, 2014 03:47
Show Gist options
  • Save mavant/9907358 to your computer and use it in GitHub Desktop.
Save mavant/9907358 to your computer and use it in GitHub Desktop.
defn line->ints [line]
map
fn [l]
Integer/parseInt l
split line #"\s+"
defn solutions->outputs [solutions]
map
fn [n s]
str "Case #"
inc n
": " s " "
range
count solutions
solutions
let [ filename "A-large-practice" outfile
str filename ".out"
infile
str filename ".in"
write
fn [outs]
with-open [wrt
writer outfile
doseq [o outs]
.write wrt o
inputs
split-lines
slurp infile
[firstline & lines] inputs [L D N]
line->ints firstline
words
take D lines
cases
map casestring->pattern
drop D lines
wordmatches
fn [pattern]
map #
re-matches pattern %
words
nummatches
fn [pattern]
count
remove nil?
wordmatches pattern
solutions
map nummatches cases
outputs
solutions->outputs solutions
write outputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment