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. Here is an example how to implement that rule:

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

Result (if loaded and executed in GHCi):
*Main> atLeastThrice statementList
["6 * 7 = 39","Grand Fenwick steals our jobs!","Just the place for a Brexit!","There are 10 Snark hunters."]

Leave a Reply