The Computer Language
Benchmarks Game

pidigits Haskell GHC #4 program

source code

-- The Computer Language Benchmarks Game
-- http://benchmarksgame.alioth.debian.org/
-- contributed by Bryan O'Sullivan
-- modified by Eugene Kirpichov: pidgits only generates
-- the result string instead of printing it. For some
-- reason, this gives a speedup.

import System.Environment

pidgits n = 0 % (0 # (1,0,1)) where
 i%ds
  | i >= n = []
  | True = (concat h ++ "\t:" ++ show j ++ "\n") ++ j%t
  where k = i+10; j = min n k
        (h,t) | k > n = (take (n`mod`10) ds ++ replicate (k-n) " ",[])
              | True = splitAt 10 ds
 j # s | n>a || r+n>=d = k # t
     | True = show q : k # (n*10,(a-(q*d))*10,d)
  where k = j+1; t@(n,a,d)=k&s; (q,r)=(n*3+a)`divMod`d
 j&(n,a,d) = (n*j,(a+n*2)*y,d*y) where y=(j*2+1)


-- Uses only one bigint division instead of two when checking a produced digit's validity.
-- main = putStr.pidgits.read.head =<< getArgs
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
The Glorious Glasgow Haskell Compilation System, version 8.4.1


Fri, 23 Mar 2018 19:33:44 GMT

MAKE:
mv pidigits.ghc-4.ghc pidigits.ghc-4.hs
/opt/src/ghc-8.4.1/bin/ghc --make -fllvm -O2 -XBangPatterns -threaded -rtsopts  pidigits.ghc-4.hs -o pidigits.ghc-4.ghc_run
[1 of 1] Compiling Main             ( pidigits.ghc-4.hs, pidigits.ghc-4.o )

pidigits.ghc-4.hs:1:1: error:
    The IO action ‘main’ is not defined in module ‘Main’
  |
1 | -- The Computer Language Benchmarks Game
  | ^
/home/dunham/benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:340: recipe for target 'pidigits.ghc-4.ghc_run' failed
make: [pidigits.ghc-4.ghc_run] Error 1 (ignored)
rm pidigits.ghc-4.hs

0.32s to complete and log all make actions

COMMAND LINE:
./pidigits.ghc-4.ghc_run +RTS -N4 -RTS 2000

MAKE ERROR