Timeline for Find numbers that are palindromic in consecutive number bases
Current License: CC BY-SA 3.0
22 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 7, 2017 at 19:08 | history | edited | 200_success |
Reinstated Revision 4, since unfortunately Martin R's answer was already based on it.
|
|
Nov 7, 2017 at 19:07 | vote | accept | Vepir | ||
Nov 7, 2017 at 19:07 | history | rollback | Vepir |
Rollback to Revision 5
|
|
Nov 7, 2017 at 19:04 | comment | added | Vepir | @200_success Why roll back? The part of the code that the answer is talking about was not edited. And that edit was done even before the answer, If I recall it correctly. I don't understand your roll back? | |
Nov 7, 2017 at 18:58 | comment | added | 200_success | Please see What to do when someone answers . I have rolled back Rev 5 → 3. | |
Nov 7, 2017 at 18:57 | history | rollback | 200_success |
Rollback to Revision 3
|
|
Nov 6, 2017 at 19:33 | comment | added | Vepir | Only significant discarding of palindromes I believe would be, if we could generate only palindromes which are palindromic in two consecutive bases, and then just checking for a third. | |
Nov 6, 2017 at 19:16 | comment | added | Vepir |
@BarryCarter Did you meant to optimize the step where the palindrome is converted to bases b+1,b+2 and checked for being palindrome again?( >> If the number x is a multiple of b+1 or b+2 then do not check it since it ends with "0" - and a palindrome/number can't start with zero?); Just ran a quick test: this actually just discards a very small number of palindromes per number base - and the value [discards / total_palindromes] tends to 0 as the number base grows. And actually using (if not (x % (b+1) == 0 or x % (b+2) == 0)) in the while loop, slows it down rather than making it faster.
|
|
Nov 6, 2017 at 18:27 | comment | added | user1149 | Discard multiples, not duplicates. For example, a multiple of 5 will end in "0" in base 5. Depending on how you define palindrome, it might be impossible for that number to be a palindrome. | |
Nov 5, 2017 at 17:21 | answer | added | Martin R | timeline score: 1 | |
Nov 5, 2017 at 16:40 | comment | added | Laurent LAPORTE |
@Vepir It is recommended to respect PEP8 naming convention, so I prefer: list_to_int .
|
|
Nov 5, 2017 at 15:30 | history | edited | Vepir | CC BY-SA 3.0 |
optimization of my own
|
Nov 5, 2017 at 14:59 | comment | added | Vepir |
@LaurentLAPORTE Renamed it to listToInt
|
|
Nov 5, 2017 at 14:58 | history | edited | Vepir | CC BY-SA 3.0 |
renamed "eval" to "listToInt"
|
Nov 5, 2017 at 14:55 | comment | added | Vepir |
@BarryCarter My palindromes are stored and handled as lists of integers, not exactly strings, but I can still apply the same thing on it: and turns out my recursive function seems to be roughly the same speed compared to something like s == s[::-1] , If I'm not mistaken? Also, I'm not sure how you meant to discard duplicates exactly?
|
|
Nov 5, 2017 at 12:39 | answer | added | Nf4r | timeline score: 0 | |
Nov 5, 2017 at 7:02 | history | tweeted | twitter.com/StackCodeReview/status/927068571422920704 | ||
Nov 4, 2017 at 21:14 | comment | added | Laurent LAPORTE |
Avoid to redefine a built-in function like eval .
|
|
Nov 4, 2017 at 17:48 | history | edited | Vepir | CC BY-SA 3.0 |
added 23 characters in body
|
Nov 4, 2017 at 17:34 | comment | added | user1149 |
stackoverflow.com/questions/931092/reverse-a-string-in-python may be a faster way to reverse strings (and thus check palindromity). You might also consider generating palindromes in the highest base first and then looking at b-1 , b-2 etc. You might also be able to use "mod" to discard multiples of a given base (depending on how you treat strings that end in "0").
|
|
Nov 4, 2017 at 16:48 | history | edited | Phrancis | CC BY-SA 3.0 |
added 9 characters in body
|
Nov 4, 2017 at 15:45 | history | asked | Vepir | CC BY-SA 3.0 |