25
2
Today, as I'm writing this, is March 31st. In the US, this is 3/31
. I was playing around with 331
as a number to come up with a challenge, and found that its residues (modulo small numbers) is palindromic. 331%2=1, 331%3=1, 331%4=3, 331%5=1, 331%6=1
(11311
).
Your challenge here is, when given an integer n > 2
, output the first n
positive numbers that have palindromic residue when taken modulo [2,n]
.
For example, for input 7
, the output should be 1, 42, 43, 140, 182, 420, 421
. Here's the chart explaining why that's the case:
mod
num | 2 3 4 5 6 7
-----------------
1 | 1 1 1 1 1 1
42 | 0 0 2 2 0 0
43 | 1 1 3 3 1 1
140 | 0 2 0 0 2 0
182 | 0 2 2 2 2 0
420 | 0 0 0 0 0 0
421 | 1 1 1 1 1 1
Input
A single positive integer n
with n > 2
in any convenient format.
Output
The resulting array/list of the first n
palindromic residues, as outlined above. Again, in any suitable format.
Rules
- For
n > 10
, assume the residue list to be flattened before checking whether it's a palindrome. That is,[1, 10, 11]
is palindromic, but[1, 10, 1]
is not. - Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Examples
[input]
[output]
3
[1, 6, 7]
4
[1, 4, 5, 8]
5
[1, 50, 60, 61, 110]
6
[1, 30, 31, 60, 61, 90]
7
[1, 42, 43, 140, 182, 420, 421]
8
[1, 168, 169, 336, 337, 504, 505, 672]
9
[1, 2520, 2521, 5040, 5041, 7560, 7561, 10080, 10081]
10
[1, 280, 281, 560, 1611, 1890, 1891, 2170, 2171, 2241]
11
[1, 22682, 27720, 27721, 50402, 55440, 55441, 78122, 83160, 83161, 105842]
Is the output supposed to be ordered? – Arnauld – 2017-03-31T15:24:45.743
@Arnauld It doesn't need to be, no, provided that it includes only the first
n
elements. – AdmBorkBork – 2017-03-31T15:27:07.5202arrgh ... your challenge = your rules, but "
[1, 10, 11]
is palindromic, but[1, 10, 1]
is not" seems so mathematically wrong. – Greg Martin – 2017-03-31T16:25:31.8671@GregMartin Stringy palindromes, not mathy palindromes. ;-) – AdmBorkBork – 2017-03-31T16:34:55.243
Can you add a test case that makes use of the
n>10
flattening behaviour? – math junkie – 2017-03-31T16:38:18.533@math_junkie I don't have a full test case, but for an example,
15
has this happen when it gets to1041040
-- the residues are0 1 0 0 4 0 0 1 0 0 4 0 0 10
. – AdmBorkBork – 2017-03-31T16:55:32.7831grr. The whole stringy instead of mathy palindrome makes this a thousand times harder in certain languages. Oh well. – MildlyMilquetoast – 2017-03-31T17:06:47.753