**Paste:**#107700**Author(s):**1HaskellADay**Language:**Haskell**Channel:**-**Created:**2014-07-18 11:46:27 UTC

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | module Analytics.Theory.Number.Continued.Continuations where import Analytics.Theory.Number -- http://lpaste.net/107480 {-- So, okay, my prime number tester-guesser function, and yours, have a problem. A BIG problem. Ah, Frère Mersenne, glad you could join us! We were just talking about you. Behind your back. Rude of us, I know. So, the problem is this. For some big prime, let's call it Mp, your prime number test, and mine, goes into a deep funk of thinking, and we don't know if it's stuck, or if it's Frozen (no Disney songs, please), or if it's ever going to return in our lifetimes. So, that's a problem, that. A solution: the Singularity. Another solution: eat Chaos' Golden Apples, granting you immortality. Problem solved! For the rest of us, or in the interim, what, then, can we do? Well, I'll tell you. (cue Monthy Pithon knightly minstrel choruses ('chorusae'?)) So, let's say for the Mersenne prime, pthMersenne 61: 2305843009213693951 if we try to find primality to this, it may take a while. A little while. More ... than just 'a little while.' How do you know your trusty dusty isPrime function is doing anything? How do you know how far it has come along? How do you know what they are serving at the cafeteria for lunch and if you'll like it at all? (Never compose these problems just before lunch. That's just an FYI for ya.) So. Compose a new isPrimeC function --} isPrimeC' :: Monad r => Integer -> (Integer -> Integer -> r Bool) -> r Bool isPrimeC' p c = undefined {-- such that at every X checks for some incremented factor f the function outputs a mark to indicate progress. For example, in my case, I have a tick ('.') output to my shell's standard output every 100,000 factors checked against the possibly prime value input to my isPrimeC' function. 'C' as in 'C is for continuation.' http://logicaltypes.blogspot.com/2014/04/c-is-for-continuation-function.html *Ahem* Write a stepper function --} stepper :: Monad r => Int -> Integer -> Integer -> r Bool stepper stepsToTick = undefined {-- that creates for the isPrimeC' function the c, continuation, function that emits a mark every stepsToTick factors checked. Apply isPrimeC' against pthMersenne 31. How many ticks were emitted? Apply isPrimeC' against pthMersenne 61. How many ticks were emitted ... before you ctrl-c'd out? Hm. --} |