On Mon, Mar 03, 2003 at 08:46:22PM -0800, Mark P Jones wrote:
pascal :: [[Integer]]
pascal = iterate (\row - zipWith (+) ([0] ++ row) (row ++ [0])) [1]
comb:: Int - Int - Integer
comb n m = pascal !! n !! m
In that case, you can take further advantage of using Pascal's triangle
So, I'm having to calculate 'n choose k' an awful lot. At the moment I've got
this:
comb :: Integer - Integer - Integer
comb m 0 = 1
comb m n = (numerator(toRational (fact m) / toRational (fact n * fact (m-n
where fact is a memoized factorial function. It's not perfectly memoized,
On Tue, Mar 04, 2003 at 12:25:01PM +1100, Andrew J Bromage wrote:
Or, even better, if you didn't multiply stuff that you're just going
to divide out in the first place.
I had thought of that before, and used a simple
comb m n = product [m, m-1 .. m-n+1] / fact (m-n)
but the unmemoized product
On Mon, Mar 03, 2003 at 04:59:21PM -0800, Hal Daume III wrote:
comb m n = fact m `div` (fact n * fact (m-n))
This was the biggest help, 33 seconds instead of my original 43. fact is the
big consumer now, and I think cries out for being arrayed, especially as it
gets used a lot elsewhere too.
main =
do
args - System.getArgs
let (m, b) = (read (args!!0), read (args!!1))
let lim :: Int
lim = read (args!!2)
printstate = args!!3
time1 - getClockTime
let n = 2^b
let afact = array (0,n) ((0,1):[(i,i*afact!(i-1)) |
On Tue, Mar 04, 2003 at 03:06:13PM +1100, Bernard James POPE wrote:
Damien writes:
main =
do
args - System.getArgs
let (m, b) = (read (args!!0), read (args!!1))
let lim :: Int
lim = read (args!!2)
printstate = args!!3
On Mon, Mar 03, 2003 at 10:45:38PM -0600, Jon Cast wrote:
Never programmed in C++ much, eh?
Only for a few years, professionally.
In general, getting the ordering of initialization right in the general
case is a harder problem than you might think.
It's not something I'd be having trouble
I have this code which compiles and runs normally, but gives bus errors or
segfaults at run time when compiled with -prof -auto-all. ghc-5.04
SunOS cownose.cs.indiana.edu 5.8 Generic_108528-18 sun4u sparc SUNW,Ultra-5_10
What's wrong?
import Numeric
import Ratio
import System
top 1 = 1
top n =
On Tue, Feb 25, 2003 at 06:08:42PM -0800, Hal Daume III wrote:
Have you removed the .o and .hi files before compiling with -prof? These
are not compatible.
Well, I got this code to run, although I thought I couldn't earlier from
clean. But the longer code I'm really concerned with still bus
On Tue, Feb 25, 2003 at 09:12:23PM -0800, Hal Daume III wrote:
My guess is that the error is here. There's a bug in ghc where (x `div`
0) and (x `mod` 0) will results in a seg fault. For now (according to one
of the Simons, this is fixed in the next version) you should do something
Doesn't
So, for my Algorithms class in grad school we have to calculate some number to
as many digits as possible in a minute. I figured this would be a good
project to try in multiple languages, to see how they compared in ease and
speed. In particular I've been intrigued by the functionality and
11 matches
Mail list logo