## Day 280

### October 9, 2017

Since we already have code to deal with prime numbers, this is easy:

(define (sum-mod-prime-day limit) (let ((pgen (primegen))) (let loop ((sum (pgen)) (mod 1) (zs (list))) (if (< limit mod) (reverse zs) (if (prime? (modulo sum mod)) (loop (+ sum (pgen)) (+ mod 1) (cons mod zs)) (loop (+ sum (pgen)) (+ mod 1) zs))))))

> (sum-mod-prime-day 365) (5 6 7 8 12 15 16 19 20 21 24 26 30 34 37 38 40 42 44 45 46 48 49 50 55 58 59 60 62 64 65 66 67 68 70 72 73 75 76 78 86 87 88 92 102 116 120 122 124 128 130 132 135 140 143 145 150 156 158 164 165 166 168 172 173 175 176 182 183 191 196 210 214 216 218 223 234 236 241 248 250 256 259 262 265 266 272 280 285 301 306 310 311 314 315 324 328 330 336 337 344 347 348 349 352 355 358 365) > 108

You can run the program, and see the prime generator and primality tester, at https://ideone.com/TyDKiX.

First I thought there would not be many such days, because if there were, they would not be interesting. But then I realized that the sums mod *n* are small, and lots of small numbers are prime, so there should be lots of results, which is correct.

I’ve added Ballew’s blog to my blog rotation. You might want to do the same.

Advertisements

Pages: 1 2

Using the primes package for Haskell, the simple solution works just fine:

I went up to 367 to include leap years.

Perl ‘golf’ish solution – using a bit of bash and a bit of perl!

The bash in back ticks generates a list of 365 primes…

Get a list of 108 numbers – can add “|wc -w” to the end to get the number of values which satisfy this….

SML:

Here’s another Haskell solution, this one builds a list of the partial sums with scanl rather than recomputing each time around:

Using standard (R7RS) Scheme and popular a couple of popular libraries

(SRFI-1 and SLIB’s factor):

Klong 20170905

findPrimes@365

[5 6 7 8 12 15 16 19 20 21 24 26 30 34 37 38 40 42 44 45 46 48 49 50 55 58 59 60 62 64 65 66 67 68 70 72 73 75 76 78 86 87 88 92 102 116 120 122 124 128 130 132 135 140 143 145 150 156 158 164 165 166 168 172 173 175 176 182 183 191 196 210 214 216 218 223 234 236 241 248 250 256 259 262 265 266 272 280 285 301 306 310 311 314 315 324 328 330 336 337 344 347 348 349 352 355 358 365]