Pretty Palintiples

Imagine you have a positive integer number $$\n\$$. Let $$\m\$$ be the number obtained by reversing $$\n\$$'s digits. If $$\m\$$ is a whole multiple of $$\n\$$, then $$\n\$$ is said to be a reverse divisible number. If neither are a palindrome, $$\m\$$ is called a palintiple.

For example, $$\1089 \cdot 9 = 9801\$$, so $$\9801\$$ is a palintiple because it is a whole multiple of its reversal, $$\1089\$$. Another example of a palintiple is $$\8712\$$, because $$\2178 \cdot 4 = 8712\$$.

It's easy to see that all palindrome numbers are reverse divisible, e.g. $$\171 \cdot 1 = 171\$$, so we're not interested in those, and we do not call them palintiples.

Input

Your input is an integer $$\x\$$. You may assume $$\x > 0\$$.

Output

Your task is to print out the first $$\x\$$ palintiple numbers. You can format your output however you like as long as every element is clearly separated.

Test Cases

Input      Output
x = 1      8712
x = 3      8712, 9801, 87912
x = 7      8712, 9801, 87912, 98901, 879912, 989901, 8799912


Rules

This is , so shortest number of bytes wins.

• Can we use other standard sequence output formats? Commented Mar 10 at 20:18
• what happens to multiples of 10? 02 divides 20 and is not a palindrome? Commented Mar 10 at 21:45
• @pajonk You can Commented Mar 10 at 21:55
• A better example would be 87120 which has 2718 as a divisor and neither are palindromes. It is probably best to state no m ending in a zero upfront (or you could word it as there must be a proper divisor of m that when reversed is m, since that cant add zeros). Commented Mar 10 at 22:01
• This is OEIS A031877. Commented Mar 11 at 2:06

Python 2, 61 bytes

m=9
while 1:
m+=1;r=int(m[::-1])
if m in(4*r,9*r):print m


A full program that prints indefinitely.

Try it online!

Why only multiples of four and nine? See the OEIS page and this linked reference by Dan Hoey.

If floating point errors are acceptable then (thanks to l4m2)...

Python 3 57 bytes

m=9
while 1:m+=1;int(str(m)[::-1])in(m/4,m/9)and print(m)


Try it online! (The header just forces TIO to flush to stdout after each print, since it seems not to flush after the 60-second timeout.)

• Why only 4 and 9 possible?
– l4m2
Commented Mar 11 at 5:00
• see, from OEIS.
– l4m2
Commented Mar 11 at 5:11
• Why this work but removing end condition it doesn't?
– l4m2
Commented Mar 11 at 6:41
• Seems TIO isn't flushing - TIO. I'm not sure that the (eventual) floating point errors from the divisions would be acceptable however. Commented Mar 11 at 10:44

JavaScript (V8), 61 bytes

A full program that prints the sequence indefinitely.

for(n=0;;n%r|r/n||print(n))r=[...++n+""].sort(_=>n%10).join


Try it online!

Commented

for(              // main loop:
n = 0;          //   start with n = 0
;               //   loop forever
n % r           //   do nothing if r is not a divisor of n
| r / n         //   or r = n
|| print(n)     //   otherwise, print n
)                 //
r =             //   compute r:
[...++n + ""] //     increment n and turn it into a list of digits
.sort(_ =>    //     reverse this list if and only if ...
n % 10      //     ... n is not a multiple of 10
).join      //     join back to a string


Jelly, 9 bytes

ÆḌDUḌ€ċµ#


A full program that accepts a positive integer, $$\x\$$, from stdin and prints a Jelly representation of the first $$\x\$$ palintiples.

Try it online! - N.B. it's very slow due to checking all proper divisors.

How?

ÆḌDUḌ€ċµ# - Main Link: no arguments
µ# - start with m=0 and count up, collecting the first {stdin} m for which:
ÆḌ        -   {m}'s proper divisors (excludes m itself, catering for
the no-palindrome requirement)
D       -   to decimal (vectorises)
U      -   reverse each
Ḍ€    -   convert each from decimal (each as vectorised form would take
[] to 0 giving a false positive of m=0)
ċ   -   count occurrences of {m}


r 0 a=a
r n a=r(quot n 10)(a*10+mod n 10)
g n a|n<1=[]|mod a 10<1||r a 0==r(r a 0)0||mod a(r a 0)>0=g n(a+1)|1>0=a:g(n-1)(a+1)
f n=g n 1


Try it online!

My first Haskell golf, so it's probably not good lol

• You can make r an infix function. And you can define g with the arguements reversed (g a n) and then just do g 1 as your anonymous function. Commented Mar 11 at 3:45
• Here's your same approach more aggressively golfed down to 63 bytes Commented Mar 11 at 3:58
• @WheatWizard damn, that's nice, feels like that should be its own solution TBH but if you're okay with it I'll add it and my original into this answer Commented Mar 11 at 14:18

Vyxal 3, 10 bytes

ЧṚ∦Ḋ≠gnt×Ẇ


Try it Online!

Does not check the factors of anything, probably will be golfable

Vyxal, 65 bitsv2, 8.125 bytes

λKṫṘcnt*;ṅ


Try it Online!

Bitstring:

00000010010010001000001010000111001101101101011011101111111011011


Slow method checking factors, but I had to beat Jelly.

Retina, 111 bytes

.+
*¶

$>:&*1 +(1+)\1${1}0
01
1
mL$w^(.*)(?=.?$)
$%=$^$& (.)\1*$&$1 L$.+
$.(792**)¶$.(891**
"$&,A.+"^~)N  Try it online! Explanation: In theory I could do this using unary division, but it would probably time out before producing any results at all, so I used the fact that all palintiples are either 792 or 891 times a palindromic string of 1s and 0s where no digit has a run length of 1. .+ *¶$>:&*1


Generate the integers from 1 to x+1 in unary.

+(1+)\1
${1}0 01 1  Convert them to binary. mL$w^(.*)(?=.?$)$%=$^$&


Produce 2x+2 binary palindromes.

(.)\1*
$&$1


Increase the run length of all the runs by 1.

L$.+$.(792**)¶$.(891**  Multiply each palindrome by both 792 and 891. N  Sort them in numeric order. "$&,A.+"^~)


Keep only the first x.

Charcoal, 28 bytes

ＮθＷ‹ⅉθ«≦⊕φ¿∧﹪φχ∧⁻φ⮌φ¬﹪φ⮌φ⟦Ｉφ


Try it online! Link is to verbose version of code. Explanation:

Ｎθ


Input x.

Ｗ‹ⅉθ«


Repeat until x terms have been output.

≦⊕φ


Increment the variable f which is predefined to 1000.

¿∧﹪φχ∧⁻φ⮌φ¬﹪φ⮌φ


Check whether f is not a multiple of 10 or a palindrome but is divisible by its reverse.

⟦Ｉφ


Output it on its own line if this is the case.

52 bytes for a fast version:

ＮθＦＥθ⍘⊕ι²Ｆ²⊞υ⁺ι✂⮌ικＦ01ＵＭυ⪫Ｅ⪪κι⁺μ⌊μιＩ…▷SΣＥ89××⁹⁹ＩιＩυθ


Attempt This Online! Link is to verbose version of code. Explanation:

Ｎθ


Input x.

ＦＥθ⍘⊕ι²


Generate the binary numbers from 1 to x.

Ｆ²⊞υ⁺ι✂⮌ικ


Produce 2x binary palindromes.

Ｆ01ＵＭυ⪫Ｅ⪪κι⁺μ⌊μι


Increase the run lengths of all of the runs by 1.

Ｉ…▷SΣＥ89××⁹⁹ＩιＩυθ


Multiply each palindrome by both 792 and 891, sort them into order, and output only the first x.

Perl 5, 40 bytes

$_%($;=reverse)|/^$;$|0$/||say while++$_


Try it online!

Outputs the sequence indefinitely.

Uiua 0.10.0, 32 30 bytes SBCS

⍥(+1⟨◌|&p⟩↧±◿10,>⊃◿≠⍜°⋕⇌...)∞0


Try on Uiua Pad!

Prints indefinitely.

0        # starting at 0
⍥(       # repeat
...    # dup input 3 times on stack
⍜°⋕⇌   # stringify, reverse, then parse
>⊃◿≠   # m = 0 mod n AND m != n
±◿10,  # test 10 does not divide m
↧      # AND results
⟨◌|&p⟩ # print if true
+1     # add 1 to m
)∞       # until fixed point (never)


(1..*).grep({$_%10&&$_!=.flip&&$_%%.flip})».say  (Continues indefinitely, printing out all the palintiples it finds.) Attempt This Online! Scala 3, 84 bytes var m=9;while(1<2){m+=1;val r=m.toString.reverse.toInt;if(m==4*r||m==9*r)println(m)}  Attempt This Online! Uiua, 23 bytes SBCS Try on Uiua Pad! Prints indefinitely. ⍥(+1⍥⟜&p∊:×4_9⍜°⋕⇌..)∞1  Explain:  ⍜°⋕⇌. # generate palindrome from input ∊:×4_9 . # if the 4*palindrome or 9*palindrome ⍥⟜&p # print if true +1 # increment ⍥( )∞1 # repeat forever, starting at 1  05AB1E, 9 bytes µNÑ¨íNåD–  Try it online. Explanation: µ # Loop while the counter variable (default 0) is not equal to the (implicit) # input-integer: N # Push the current loop-index Ñ # Pop and push a list of its divisors ¨ # Remove the number itself (for palindrome cases) í # Reverse each divisor in the list Nå # Pop and check if the loop-index itself is in the list of reversed divisors D # Duplicate this check – # Pop, and if it's truthy: print the loop-index with trailing newline # Pop, and if it's truthy: implicitly increase the counter variable by 1  Racket, 223 bytes (define(r n a)(if(= n 0)a(r(quotient n 10)(+(* a 10)(modulo n 10))))) (define(f x #:a[a 1])(if(= x 0)'()(if(and(>(modulo a 10)0)(not(=(r a 0)(r(r a 0)0)))(=(modulo a(r a 0))0))(cons a(f(- x 1)#:a(+ a 1)))(f x #:a(+ a 1)))))  Try it online! Disclaimer: I'm not exactly good at golfing in Racket. PowerShell Core, 82 bytes for(){if((++$i%10)*($i-ne($u=-join("$i"|% t*y|%{"$i"[-++$t]})))*!($i%$u)){$i}\$t=0}
`

Try it online!

Prints all the palintiple, separated by newlines