Skip to content

Instantly share code, notes, and snippets.

@jadlr
Created July 19, 2016 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadlr/baa83a68c1c503ee1f3f646acbcf9e6f to your computer and use it in GitHub Desktop.
Save jadlr/baa83a68c1c503ee1f3f646acbcf9e6f to your computer and use it in GitHub Desktop.
Repdigit sequence calculation in haskell
module Repdigit where
-- https://oeis.org/A010785
repdigit :: Integer -> Integer
repdigit n = (n - 9 * floor ((fromInteger n - 1) / 9)) * (10 ^ floor ((fromInteger n + 8) / 9) - 1) `quot` 9
repdigits :: [Integer]
repdigits = go 0
where go n = repdigit n : go (n + 1)
@jadlr
Copy link
Author

jadlr commented Jul 19, 2016

*Repdigit> repdigit 100
111111111111
*Repdigit> take 30 repdigits
[0,1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment