Skip to content

Instantly share code, notes, and snippets.

/wordsearch.hs Secret

Created January 6, 2017 02:46
Show Gist options
  • Save anonymous/06fb05818ba77ec26295011196109dc2 to your computer and use it in GitHub Desktop.
Save anonymous/06fb05818ba77ec26295011196109dc2 to your computer and use it in GitHub Desktop.
-- my friend tweeted about wordsearches and this possessed
-- me to calculate the number of possible positions for a
-- word of a given length so here we are
-- given a length l and a wordsearch of n by m characters,
-- returns the number of possible vectors that a word of
-- length l can inhabit.
v l n m
| l <= min n m = (iw * ih * 8) + 2*(iw * s * 5) + 2*(ih * s * 5) + 4 * (s * s * 3)
| (l > sb)
&& (l <= lb) = sb * (lb - l + 1) * 2
| otherwise = 0
where
s = l - 1
iw = n - 2*s
ih = m - 2*s
sb = min n m
lb = max n m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment