g | x | w | all
Bytes Lang Time Link
084PowerShell240322T145419ZJames Fl
004Vyxal 3240321T141711Zpacman25
105Swift 5.9230712T022801ZmacOSist
087Desmos230722T050953ZAiden Ch
067C gcc230702T090917ZNoodle9
035Wolfram Language Mathematica230706T231929ZDomenico
009Pyth230705T181306ZCursorCo
023Raku230705T185215ZSean
008Japt E!230705T145101ZShaggy
011Japt230705T140146ZLuis fel
054R230704T075307ZDominic
nanScala230702T011434Z138 Aspe
155Racket230704T111055ZEd The &
042Ruby230704T065920ZG B
040JavaScript V8230703T064235Zl4m2
4342Javascript230701T232118ZDadsdy
026Lua230703T215519Zbluswimm
007Brachylog230703T123607ZFatalize
006Jelly230703T083712ZUnrelate
005MathGolf230703T074449ZKevin Cr
080Excel230703T062406ZJos Wool
004Thunno 2 M230702T032926Znoodle m
011Extended Dyalog APL230702T123737ZRubenVer
058R230702T134357Zpajonk
083Java 8230702T144631ZJack Amm
046Factor + math.unicode projecteuler.037.private230702T035851Znoodle m
011Charcoal230702T110819ZNeil
042Arturo230702T090628Zchunes
nanFig230702T050716Ztybocopp
006Nekomata + e230702T005904Zalephalp
039Retina 0.8.2230701T235625ZNeil
039Python 2230701T231104ZAlbert.L
00505AB1E230701T230312ZLuis Men
3375Vyxal g230701T221203Zlyxal

PowerShell, 84 bytes

$m=[math];if($m::sqrt($_)%1-eq0){return $m::sqrt($_[-1..-$_.length]-join'')%1-eq0}!1

Try it online!

Vyxal 3, 4 bytes

Ṛ√ᵞ⌊

Try it Online!

is the square root of the reverse equal to its integer part?

Swift 5.9, 113 101 105 bytes

import Foundation
let x={Int(exactly:sqrt($0))!},e={x(.init($0+0))
x(.init(String("\($0)".reversed()))!)}

e(_:) is the closure you're looking for. Throws a fatal error when the check fails; does nothing when it succeeds.

Desmos, 87 bytes

h=.5
d=floor(logn)+1
f(n)=0^{mod(n^h+(∑_{k=0}^d.1mod(floor(n/10^k),10)10^{d-k})^h,1)}

Try It On Desmos!

Try It On Desmos! - Prettified

As you can tell, reversing the digits of a number in Desmos is a pain to do.

C (gcc), 75 73 67 bytes

b;f(n){b=sqrt(n);for(b=b*b-n;n;n/=10)b+=9*b+n%10;n=sqrt(b);b-=n*n;}

Try it online!

Saved 2 8 bytes thanks to c--!!!

Wolfram Language (Mathematica), 35 bytes

AtomQ@Tr@Sqrt@{#,IntegerReverse@#}&

Try it online!

Pyth, 10 9 bytes

-1 byte by realizing that v automatically vectorizes

sMI@R2v_B

Try it online!

Explanation

sMI@R2v_BQ    # implicitly add Q
              # implicitly assign Q = eval(input())
       _BQ    # bifurcate Q over reversal
      v       # eval (automatically vectorizes)
   @R2        # map each to their square roots
  I           # check for invariance over
sM            # converting the entire list into integers

Raku, 23 bytes

{sqrt($_|.flip)!~~/\./}

Try it online!

$_ | .flip is an or-junction of the input number and its flipped string representation, which Raku treats as a number in nearly all contexts. sqrt applied to that or-junction produces another or-junction that contains the square roots of the two numbers above. Then the function returns whether it is not (!) the case that either of those square roots match (~~) the regular expression containing a period (/\./).

Japt -E!, 8 bytes

Based on l4m2's solution but with correct output.

¬%1ªßUìÔ

Try it

Japt, 11 bytes

[UUsÔ]m¬ev1

PD: Definitely can be golfed down

Try it


Japt , 11 bytes

¬v1 ©UsÔ¬v1

Try it

R, 56 55 54 bytes

Edit: -1 byte after looking at pajonk's answer, and -1 byte by rearranging

\(x)(x^.5+(x%/%rev(z<-10^(0:log10(x)))%%10%*%z)^.5)%%1

Attempt This Online!

Outputs zero (falsy) for reversed-squares, non-zero (truthy) for other numbers.
Based on the fact that there does not exist any pair of integers x and y that are not both squares, but for which sqrt(x)+sqrt(y) is an integer: see here.

Scala, 63 60 58 bytes

Saved 5 bytes thanks to the comments of @Shaggy and @Dominic van Essen


Golfed version. Try it online!

n=>(math.sqrt(n)+math.sqrt(n.toString.reverse.toLong))%1>0

Ungolfed version. Try it online!

object Main {
  def main(args: Array[String]): Unit = {
    def f(n: Long): Boolean = {
      val sqrtOriginal = math.sqrt(n)
      val sqrtReversed = math.sqrt(n.toString.reverse.toLong)

      sqrtOriginal % 1 != 0 || sqrtReversed % 1 != 0
    }

    (0 until 10000).foreach(i => {
      if (!f(i)) println(i)
    })

    val bigNumber = 1234567654321L
    if (!f(bigNumber)) println(bigNumber)
  }
}

Racket - 155 bytes

#lang racket
(define(m v)(let([r(string->number(list->string(reverse(string->list(number->string v)))))][? integer?])(and(?(sqrt v))(?(sqrt r)))))(m(read))

Try it online!


Explanation

On line one, we have Racket's required language statement, #lang racket, This just imports all of the statements/functions used in the language (like define and read, as well as wrapping our program into a module.

The second line is where the main program lies. We define a function named m. This function received an integer v as an argument. We then reverse the integer to obtain an integer named r. We take the square roots of both v and r and see whether they are integers or not. If both checks return true, then the number is a Reversed Perfect Square.

Here's the program in all its glory. In the shortened form, I embedded reverse-number as part of main's local scope. But to make it easier to read and understand, I made it its own function:

#lang racket

(define (reverse-number value)
  (string->number (list->string (reverse (string->list (number->string value))))))

(define (main value)
  (let ([reversed-value (reverse-number value)])
    (and (integer? (sqrt value))
         (integer? (sqrt reversed-value)))))

(main (read))

As of right now, Racket doesn't have a reverse-string or string-reverse function. So, the only way I could reverse the number was to first convert the number to a string, then convert the string to a list, reverse the list, convert the list to a string, then convert the string to a number. But if we did have a string-reverse function, I would've written:

(string->number (string-reverse (number->string value)))

Also, while I could've used quotient and remainder, it ended up bumping the number of bytes up by a tad bit (I got 180).


Example usages of main:

;; An infinite loop that loops over all natural numbers [1..] and finds all RPSs
(for ([i (in-naturals)] #:when (main i))
  (displayln i))

Ruby, 42 bytes

->n{n**0.5%1+n.digits.join.to_i**0.5%1==0}

Try it online!

JavaScript (V8), 40 bytes

g=x=>x**.5%1||g([...x].reverse().join``)

Try it online!

Throws as true and not throw as false.

Here assumes a reasonable stack(actually <1KB is enough, number is stored in heap) so it's allowed

C (gcc), 66 bytes

a;g(n){a=sqrt(n);a=a*a-n;}f(n){for(g(n);n;n/=10)a+=9*a+n%10;g(a);}

Try it online!

Strongly pushed Noodle9's

Javascript, 43 40 42 Bytes

Thanks to @Arnauld for -3 Bytes (-2 from backticks (which I forgot), -1 from inverse output)

n=>[...n].reverse().join``**.5%1*n**.5%1>0

TIO

Lua, 26 bytes

n=...a=n^.5&n:reverse()^.5

Try it online!

Outputs using the exit code (0 is true, 1 is false).

This works because Lua can't do bitwise operators on non-integer numbers. If either n^.5 or n:reverse()^.5 is not an integer, the program will error.

Brachylog, 7 bytes

↔;?~^₂ᵐ

Try it online!

Explanation

↔;?          The list [reversed(Input), Input]
   ~^₂ᵐ      Each element must be the square of some number

Jelly, 6 bytes

ṚƬḌ½ḞƑ

Try it online!

ṚƬ        Reverse while unique.
  Ḍ       Vectorizing convert from decimal.
   ½      Vectorizing square root.
     Ƒ    Is the entire list of results unchanged by
    Ḟ     vectorizing floor?

MathGolf, 5 bytes

‼°x°╓

Try it online.

Or alternatively:

xαm°╓

Try it online.

Explanation:

‼     # Apply the next two operators separately on the current stack:
      # (which will use the implicit input-integer)
 °    #  Check if it's a perfect square
  x   #  Reverse it
   °  # Check if this top reversed integer is a perfect square as well
    ╓ # Pop both, and get the minimum of the two
      # (which will be truthy if both were truthy; or falsey if either/both were falsey)
      # (after which the entire stack is output implicitly as result)

x     # Reverse the (implicit) input-integer
 α    # Pair the top two values, which is the (implicit) input and the reversed input
  m   # Map over this pair:
   °  #  Check for both whether it's a perfect square
    ╓ # Pop the square, and push its minimum
      # (which will be truthy if both were truthy; or falsey if either/both were falsey)
      # (after which the entire stack is output implicitly as result)

Excel, 80 bytes

=LET(
    a,LEN(A1),
    b,HSTACK(A1,CONCAT(MID(A1,1+a-SEQUENCE(a),1)))^0.5,
    AND(INT(b)=b)
)

Thunno 2 M, 4 bytes

Requires v2.2.2: Try it

Ḳ,Ʋ

Thunno 2 G!, 6 bytes

Works on old version of Thunno 2.

ḲNKƭ1%

Attempt This Online!

This could be 4 bytes with m flag if we had an is_square built-in, or 5 bytes with same flag if we had an is_int built-in.

Extended Dyalog APL, 18 13 11 bytes

Thanks Adám for -5 bytes!

Takes input as a string.

≡∘⌊⍨∘√⍎,⍎⍤⌽

Explanation:

≡∘⌊⍨⍤√⍎,⍎⍤⌽
       ,    ⍝ make a list of
      ⍎     ⍝ the input parsed as a number
        ⍎⍤⌽ ⍝ and the reversed input parsed as a number,
     √      ⍝ take the square root of both,
≡∘⌊⍨        ⍝ is that list equal to itself after you floor it?

R, 59 58 bytes

\(n,t=10^(1:nchar(n)-1))n^.5%%1|(n%/%t%%10%*%rev(t))^.5%%1

Attempt This Online!

\(n,t=10^(1:nchar(n)-1))any(c(n,n%/%t%%10%*%rev(t))^.5%%1)

Attempt This Online!

Outputs flipped TRUE/FALSE.

Java 8, 83 bytes

n->Math.sqrt(n)%1==0&Math.sqrt(new Long(new StringBuilder(""+n).reverse()+""))%1==0

this lambda can be used for a functional interface such as IntPredicate

Try It Online

Factor + math.unicode project-euler.037.private, 46 bytes

-5 bytes thanks to @chunes

[ dup reverse-digits [ √ dup ⌊ = ] both? ]

Attempt This Online!

√ dup ⌊ = seems to be the shortest way to check if a number is a perfect square, since √ integer? doesn't work.

Charcoal, 11 bytes

¬Σ﹪₂I⟦θ⮌θ⟧¹

Attempt This Online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - if a member of A061457, nothing if not. Explanation: Uses floating-point arithmetic, so will go wrong on large enough inputs.

      θ     Input as a string
        θ   Input as a string
       ⮌    Reversed
     ⟦   ⟧  Make into a list
    I       Cast to integer
   ₂        Take the square root
  ﹪         Modulo
          ¹ Literal integer `1`
 Σ          Take the sum
¬           Logical Not
            Implicitly print

15 bytes for a theoretically correct version which actually has worse performance because it creates a list of length of the input:

Nθ¬⁻⟦θ⮌θ⟧X…·⁰θ²

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

Nθ              First input as a number
     θ          First input
       θ        First input
      ⮌         Reversed
    ⟦   ⟧       Make into a list
   ⁻            Set difference with
          …·    Inclusive range from
            ⁰   Literal integer `0` to
             θ  First input
         X      Vectorised raise to power
              ² Literal integer `2`
  ¬             Logical Not
                Implicitly print

23 bytes for a version that imports Python's math.isqrt:

⬤I⟦θ⮌θ⟧⁼ιX▷math.isqrtι²

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

   θ                    Input as a string
     θ                  Input as a string
    ⮌                   Reversed
  ⟦   ⟧                 Make into a list
 I                      Cast to integer
⬤                       All values satisfy
                     ι  Current value
          ▷math.isqrt   Integer square root
         X              Raised to power
                      ² Literal integer `2`
       ⁼                Equals
        ι               Current value
                        Implicitly print

37 bytes for a version that uses the Babylonian method to find the integer square root and so will work with arbitrarily large integers in linear time on the number of digits:

⊞υI⟦θ⮌θ⟧W⁼¹№υ⌊υ⊞υE⌊υ÷⁺κ÷§⌈υλκ²⁼⌈υX⌊υ²

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

⊞υI⟦θ⮌θ⟧

Start with the input and its reversal both as the target and the initial estimate.

W⁼¹№υ⌊υ

Repeat until the estimate converges.

⊞υE⌊υ÷⁺κ÷§⌈υλκ²

Get the next estimate.

⁼⌈υX⌊υ²

Check that the square of the final estimate gives the target.

Arturo, 42 bytes

$->n[0=+%sqrt do reverse~"|n|"1(sqrt n)%1]

Try it!

$->n[                        ; a function taking an argument n
    0=                       ; is zero equal to
    +                        ; the sum between
    %sqrt do reverse~"|n|"1  ; the square root of n reversed modulo one
    (sqrt n)%1               ; and the square root of n modulo one
]                            ; end function

Fig, \$8\log_{256}(96)\approx\$ 6.585 bytes

!a%1mqw$

Try it online!

       $  # Inupt reversed
      w   # Pair with the input (we now have [reversed(n), n])
    mq    # Square root of each one
  %1      # Modulo 1
 a        # Any truthy (i.e. more than 0)
!         # Logical NOT

Nekomata + -e, 6 bytes

¢B¢bÐ√

Attempt This Online!

¢B¢bÐ√
¢B      Integer to decimal digits in the reverse order
  ¢b    Decimal digits to integer
    Ð   Pair
     √  Square root; fails if not a perfect square

-e checks if there is a solution.

Retina 0.8.2, 39 bytes

$
¶$`
O$^`\G.

.+
$*
%A`(^1|11\1)+$
^¶$

Try it online! Link includes faster test cases. Explanation:

$
¶$`

Duplicate the input.

O$^`\G.

Reverse the first copy.

.+
$*

Convert to unary.

%A`(^1|11\1)+$

Delete square numbers.

^¶$

Check that both numbers were deleted.

Python 2, 39 bytes

lambda n:n**.5%1+int(`n`[::-1])**.5%1>0

Attempt This Online!

Reversed squares, reversed output. Returns False if input is a square and reversed square, True if not.

05AB1E, 5 bytes

Â)ŲP

Prints 1 if the condition is met, 0 otherwise.

Try it online! Or verify all test cases.

How it works

    # Implicit input: n. Push n and (digit-)reversed n
)    # Concatenate stack into an array
Ų   # Is square? Element-wise
P    # Product of array. Implicit print

Vyxal g, 30 27 bitsv2, 3.75 3.375 bytes

Ṙ"∆²

Try it Online!

Explained

Ṙ"∆²
Ṙ"    # the list [input, input reversed]
  ∆²  # vectorise is square
# g flag takes the minimum which in this case is equivalent to checking if both items are truthy