37
1
Input
no input for this challenge
The Challenge
Write a code that outputs:
The first 10 prime numbers whose sum of their digits equal the number of bytes of your code
Examples
Let's say your code is Co&%423@k"oo"
which is 13 bytes
your code must output [67, 139, 157, 193, 229, 283, 337, 373, 409, 463]
those are the first 10 prime numbers whose sum.... ok you got it!
If your code is 8 bytes
, you must output [17, 53, 71, 107, 233, 251, 431, 503, 521, 701]
Rules
You must only use the first 10^8 prime numbers
which means all your numbers must be <2038074743=10^8th prime
If you can't find 10 prime numbers in this range that fit your bytes, then you will have to adjust your code (you may even have to add some bytes!) in order to find a "working number of bytes"
Just output the 10 primes in any way you like
This is code-golf, so the shortest code in bytes win!
1
Can't edit comment so I'm just deleting and reposting: Here's a gist containing the primes you'd need to output for a given bytecount as well as their indices: link Since I did it naïvely, I only checked for the sums up to the first 10^7 primes.
Like some answers have mentioned, there are missing values which likely correlate to unachievable digital sums, though for larger sums this may not be the case (remember, I only checked the first 10^7 primes).
"in any way you like": do the primes need to be ordered? – Arnauld – 2017-08-23T23:45:50.950
@Arnauld No, but they must be the 10 smaller in any order – None – 2017-08-23T23:47:39.023
@cole It's definitely impossible for all the missing numbers up through 69. There aren't 10 primes in the first 10^8 that sum up to 2, and there are no primes whose digits add up to any number divisible by 3 (except for 3 itself) since then that number would be divisible by 3. – Chris – 2017-08-24T04:34:38.927
"You must only use the first 10^8 prime number, which means all your numbers must be <2038074743=10^8th prime" I guess this invalidates my 364 bytes Java answer. xD Not that it returns 10 primes which digits are equal to 364 even if it has a year to run anyway.. – Kevin Cruijssen – 2017-08-24T08:32:45.083
1@KevinCruijssen Although your answer is invalid you are welcome to post it in order to have a discussion with other members to help you find a better one. – None – 2017-08-24T08:38:47.690
Why the arbitrary cutoff? "You must only use the first 10^8 prime numbers" effectively means "your program must be <=79 bytes" and that's not a normal codegolf restriction. What other purpose or reason is there for it? – TessellatingHeckler – 2017-08-24T23:45:55.200
@TessellatingHeckler do you think you can verify a 350 bytes answer? The task is very easy and can be done in a few bytes. I think the real challenge is to get to 5 or 4. If your language can't do this task in 80 bytes then you should try another language. or try hardcoding! – None – 2017-08-25T00:02:53.227
@TessellatingHeckler how about 1350 bytes then?Just a question: how many bytes is your answer? – None – 2017-08-25T00:40:58.393
1@TessellatingHeckler I also think the 10^8 cutoff is rather arbitrary. To verify that ten given numbers all have digit sum 350, and all are primes, should be fast. However, to verify that those ten are in fact the smallest possible, could be harder, I guess. – Jeppe Stig Nielsen – 2017-08-25T19:09:00.890
@BillSteihn I stopped trying because of the cutoff, so I don't know how long. I answered 71 bytes of V instead. – TessellatingHeckler – 2017-08-26T00:01:27.743
@JeppeStigNielsen Good point. With PrimeSieve generating primes, I wrote this Python script to sum the digits and find the first ten primes for each sum. The question's cutoff is 2 billion for 79 code characters. By 3 billion it's 80 chars. 4 billion, still 80. By 10 billion it's up to 86. By 20 billion, 88 chars. Here is the prime lists for up to 88 chars. clearer now that high sums will end up being 'remove repeating 9s'
– TessellatingHeckler – 2017-08-26T00:08:09.203For the record, up to 100 billion gets to 95 chars - https://gist.github.com/anonymous/cb500b6a7dfc114df89e54941797ab0b
– TessellatingHeckler – 2017-08-29T17:27:17.053