Skip to content

Instantly share code, notes, and snippets.

View duncanmortimer's full-sized avatar

Duncan Mortimer duncanmortimer

View GitHub Profile

Keybase proof

I hereby claim:

  • I am duncanmortimer on github.
  • I am duncanmortimer (https://keybase.io/duncanmortimer) on keybase.
  • I have a public key whose fingerprint is 5235 E44A 6B19 B27F 1D64 0DA6 4D22 9B9C E0DC E1F1

To claim this, I am signing this object:

@duncanmortimer
duncanmortimer / themepark.hs
Created January 22, 2011 22:55
This version memoizes the calculation by determining the sequences of "ride sizes" (i.e. number of people on the rollercoaster in subsequent rides) obtained starting at different positions in the queue. This speeds things up in two ways: (a) we only need
module Main where
import Text.Printf
-- Processing
profit :: Integer -> Integer -> [Integer] -> Integer
profit r cap gs
| sum gs <= cap = r * (sum gs)
| otherwise = sum $ take (fromIntegral r) $ rideSizes 0