What I tell you three times is true!

The Bellman’s Rule is stated in Lewis Carroll’s The Hunting of the Snark, line #7 and line #335.

#! /usr/bin/haskell
import Data.List
statementList =
  ["Grand Fenwick steals our jobs!"
  ,"There are 10 Snark hunters."
  ,"There are 10 Snark hunters."
  ,"There are 9 Snark hunters."
  ,"Grand Fenwick steals our jobs!"
  ,"There are 9 Snark hunters."
  ,"6 * 7 = 39"
  ,"6 * 7 = 39"
  ,"There are 10 Snark hunters."
  ,"6 * 7 = 42"
  ,"Grand Fenwick steals our jobs!"
  ,"There are 10 Snark hunters."
  ,"6 * 7 = 39"
  ,"There are 10 Snark hunters."
  ]
atLeastThrice :: [String] -> [String]
atLeastThrice sL = [head grp | grp <- group $ sort sL, length grp >= 3]

Result (if loaded and executed in GHCI):
Prelude> atLeastThrice statementList
["6 * 7 = 39","Grand Fenwick steals our jobs!","There are 10 Snark hunters."]

Leave a Reply