15
\$\begingroup\$

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.

\$\endgroup\$
10
  • 12
    \$\begingroup\$ Can we use other standard sequence output formats? \$\endgroup\$
    – pajonk
    Mar 10 at 20:18
  • 1
    \$\begingroup\$ what happens to multiples of 10? 02 divides 20 and is not a palindrome? \$\endgroup\$
    – pacman256
    Mar 10 at 21:45
  • 3
    \$\begingroup\$ @pajonk You can \$\endgroup\$
    – Trivaxy
    Mar 10 at 21:55
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ Mar 10 at 22:01
  • 6
    \$\begingroup\$ This is OEIS A031877. \$\endgroup\$
    – alephalpha
    Mar 11 at 2:06

16 Answers 16

5
\$\begingroup\$

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.)

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

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}
\$\endgroup\$
2
\$\begingroup\$

Haskell, 136 bytes

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

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$
    – Wheat Wizard
    Mar 11 at 3:45
  • \$\begingroup\$ Here's your same approach more aggressively golfed down to 63 bytes \$\endgroup\$
    – Wheat Wizard
    Mar 11 at 3:58
  • \$\begingroup\$ @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 \$\endgroup\$
    – hyper-neutrino
    Mar 11 at 14:18
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

Vyxal 3, 10 bytes

ЧṚ∦Ḋ≠gnt×Ẇ

Try it Online!

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

\$\endgroup\$
2
\$\begingroup\$

Vyxal, 65 bitsv2, 8.125 bytes

λKṫṘcnt*;ṅ

Try it Online!

Bitstring:

00000010010010001000001010000111001101101101011011101111111011011

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Charcoal, 28 bytes

NθW‹ⅉθ«≦⊕φ¿∧﹪φχ∧⁻φ⮌φ¬﹪φ⮌φ⟦Iφ

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

Nθ

Input x.

W‹ⅉθ«

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.

⟦Iφ

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

52 bytes for a fast version:

NθFEθ⍘⊕ι²F²⊞υ⁺ι✂⮌ικF01UMυ⪫E⪪κι⁺μ⌊μιI…▷SΣE89××⁹⁹IιIυθ

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

Nθ

Input x.

FEθ⍘⊕ι²

Generate the binary numbers from 1 to x.

F²⊞υ⁺ι✂⮌ικ

Produce 2x binary palindromes.

F01UMυ⪫E⪪κι⁺μ⌊μι

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

I…▷SΣE89××⁹⁹IιIυθ

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

\$\endgroup\$
1
\$\begingroup\$

Perl 5, 40 bytes

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

Try it online!

Outputs the sequence indefinitely.

\$\endgroup\$
1
\$\begingroup\$

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)
\$\endgroup\$
1
\$\begingroup\$

Raku (Perl 6) (rakudo), 48 bytes

(1..*).grep({$_%10&&$_!=.flip&&$_%%.flip})».say

(Continues indefinitely, printing out all the palintiples it finds.)

Attempt This Online!

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.