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]
n
elements. \$\endgroup\$[1, 10, 11]
is palindromic, but[1, 10, 1]
is not" seems so mathematically wrong. \$\endgroup\$