## Day 280

### October 9, 2017

Pat Ballew is a retired math teacher who writes a blog *On This Day In Math* that gives a day-by-day history of mathematics. The blog is odd, quirky, and unquestionably fun. On October 7th, Ballew wrote:

The 280th day of the year…. The sum of the first 280 consecutive primes, mod 280, is prime.

Since I like to play with prime numbers, that got my attention, and I quickly went to determine how many such days there are in a year.

Your task is to determine how many days in a year share the characteristic that on the *n*th day the sum of the first *n* primes, mod *n*, is prime. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

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]

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!