6 kyu
Arithmetic Progression of Primes
84 of 93amekh2
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Nice coding challenge of the series as well, it takes a while to figure this one out.
Python new test framework should be used
Fixed in this fork
Range of inputs should be specified
Ruby 3.0 should be enabled, see this to learn how to do it
updated
Ruby random tests are raising errors by itself:
Fixed
What if 2 arithmetic progression have the same start? Should we return only the first or both? And in which order? I have seen nothing in description about this.
The description says 'all possible', so return all in ascending order.
Well..
What if two sequences have the same first element?
Just a quick question - how many 'random' tests are there? I've up to 33 tests passed only for the overall to fail due it breaching the 12s boundary. Now this is my first python code snippet, but I figure if the algorithm works well enough to pass all the tests it reaches, maybe something needs to be added to the description covering the time requirements? Or is it possible that I'm getting too many random tests?
Cheers Kevin
There are 95 random tests, and that should fit well in the time limit. Check your algorithm
Thank you for the heads up :-)
This comment has been hidden.
Ruby tanslation kumited -- please check and approve
Thanks for the approval
The expected solution returns primes outside the given range (and yes, I checked, actual and expected are not swapped here):
prime(4912, 6817):
[[5021, 5261, 5501, 5741, 5981, 6221], [5081, 5171, 5261, 5351, 5441, 5531], [5153, 5483, 5813, 6143, 6473, 6803], [5171, 5381, 5591, 5801, 6011, 6221], [5179, 5479, 5779, 6079, 6379, 6679], [5227, 5437, 5647, 5857, 6067, 6277], [5273, 5483, 5693, 5903, 6113, 6323], [5443, 5503, 5563, 5623, 5683, 5743]]
should equal
[[5021, 5261, 5501, 5741, 5981, 6221], [5081, 5171, 5261, 5351, 5441, 5531], [5153, 5483, 5813, 6143, 6473, 6803], [5171, 5381, 5591, 5801, 6011, 6221], [5179, 5479, 5779, 6079, 6379, 6679], [5227, 5437, 5647, 5857, 6067, 6277], [5273, 5483, 5693, 5903, 6113, 6323], [5443, 5503, 5563, 5623, 5683, 5743], [6673, 6703, 6733, 6763, 6793, 6823]]
prime(5082, 6657):
[[5171, 5381, 5591, 5801, 6011, 6221], [5227, 5437, 5647, 5857, 6067, 6277], [5273, 5483, 5693, 5903, 6113, 6323], [5443, 5503, 5563, 5623, 5683, 5743]]
should equal
[[5081, 5171, 5261, 5351, 5441, 5531], [5171, 5381, 5591, 5801, 6011, 6221], [5227, 5437, 5647, 5857, 6067, 6277], [5273, 5483, 5693, 5903, 6113, 6323], [5443, 5503, 5563, 5623, 5683, 5743]]
Fixed.
(the checker algo is painfully ineffective, I'll try to fix that too)
New one so that I'm sure you'll see it:
Congrats! You just invalidated ALL the other solutions! ;p
Your internal solution is currently wrong:
seeing the requirement, with
r2=10000
, your list of primes has to go further so that your solution can match lists with big primes numbers. Look at mine: I use a list going up to 100 000 for the biggest primes to seek.PS: note that your r2 value goes upper than 10 000, for now.
Fixed.
...and I just invalidated all solutions (i.e. mine ;-) again, because I changed the function name from
primes
(such a terrible choice)are you sure about what you did? I still get some fails. Investigating...
I have sometimes an extra serie. Didn't find yet the reason why and what is correct/wrong
ok, got it. I've values out of the range.
Raise an issue if you find one :-)
Oh, and do some reading on the possible differences in the progression...
what do you mean?
This comment has been hidden.
well, primes are boring me for that kind of reason... ;p
Thanks for all your comments so far, I'm updating everything! (this is the first kata I have made so I'm quite unfamiliar with everything)
seeing "the amount of work", you should maybe unpublish it in the meantime. ;)
Is it better now?
yes, but still some things to address:
you didn't describe the order in which the sequences have to been put in the output list
do NEVER put your solution in the preloaded part (EDIT: well, it seems actually that you didn't put anything in the preloaded part... Then how do you compute the reference solution??? See below ;p )
"typo" in the random tests:
of course the two calls will return the exact same output, there, even if it's completely flawed!
test.assert_equals(actual, expected,"primes({}, {})".format(r1, r2))
=> That's good, to put the input in the message. Though, usingassert_equals
, the whole lists will be displayed in case of failures: depending on there length, that might make crash the consol output. Did you try to make it fail on long ouptuts, to be sure that's good?note that you didn't correct the solution setup either.
I think I've fixed it now
nope, not completely:
And you should push further your requirement for the tests. I'd suggest:
MAX_P = 10000
(talking about "usable" ones, meaning, that would be the upperbond for r2)MAX_P-2000
, then define r2 withr2 = r1 + randrange(2000)
Seriously? The description isn't even matching what the task really is!
Generate AN increasing arithmetic progression of six primes a,b,c,d,e,f (within a given range) for which the last term f IS AS SMALL AS possible
=> Meaning: we should generate only ONE SINGLE list. And that's absolutely NOT what is expected!
And so we actually have to generate ALL the sequences, but you have then to tell about the order they have to be generated.
EDIT: well, That's actually already in ZED's issue. Let say I leave it here to really emphasize it... ;)
EDIT²: Well, lets make that post more usefull with another problem:
What about a range where no such arithmetic progression is possible? => tell in the description that an empty list is the default ouput.
Seems to be fixed.
def prime(...
instead ofdef primes(...
Fixed.
Needs tests with larger range (eg.
0,1000
). And you need to specifyAccording to your code, you are expecting to return all possible progressions. You need to clearify it in the desc.
Seems to be done.
Needs Random Tests.
Seems to be done.