## 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.

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]

October 9th, 2017.cpp:Output:There are 108 days sharing the characteristic that on the Nth day, the sum of the first N primes, modulo N, is prime: 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, and 365.[/sourecode]

On an Apple Power Mac G4 (AGP Graphics) (450MHz processor, 1GB memory) to run the solution took approximately one second on both Mac OS 9.2.2 (International English) (the solution compiled using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition)) and Mac OS X 10.4.11 (the solution compiled using Xcode 2.2.1).

(I’ve just completed a gig at London South Bank University and so I’m again just trying to solve the problems posed by this ‘site whilst I try to get a job (and I’ve solved this problem in particular to test my

`seal_Queue`

template class I might use in the fourth version of my SDL2 joystick interrogator utility); I’m well-aware that my solutions are far from the best – but, in my defence, I don’t have any traditional qualifications in computer science :/ )Ps. Merry Christmas, and thank you for running this ‘site!