# Am a I square repdigit? [closed]

You will write a program or function to return a truthy value if the integer inputted to it is a square repdigit, and a falsy value if it is not. A repdigit is an integer that contains only one digit (e.g. 2, 44, 9999). For the purpose of this challenge, a square repdigit is a repdigit that is the square of a different repdigit.

## Input

An integer, in base 10.

## Output

A truthy/falsy value that reflects whether the input is a square repdigit

## Examples

0 --> falsy
1 --> falsy
2 --> falsy
4 --> truthy
9 --> truthy
11 --> falsy


## Scoring

This is , lowest bytes wins.

• So, the integer provided and it's square root must be repdigits? – Shaggy Jun 12 '17 at 10:57
• Is this really much different from Is this number a repdigit? – TheLethalCoder Jun 12 '17 at 11:02
• So we are asking if input is 4 or 9? – J42161217 Jun 12 '17 at 11:04
• @Adám No they must be squares of different repdigits. – Erik the Outgolfer Jun 12 '17 at 11:26
• 4 and 9 are indeed the only repdigits that are squares of other repdigits. The last two digits of any repdigit>10 squared contains two different values: 1..1 -> ..21, 2..2 -> ..84, 3..3 -> ..89, 4..4 -> ..36, 5..5 -> ..25, 6..6 -> ..36, 7..7 -> ..29, 9..9 -> ..01. If you square 8..8, the last three digits are 544. – JungHwan Min Jun 12 '17 at 12:41

# Neim, 63 2 bytes

+𝕚


Abuses the way that Neim deals with lists.

+ pushes the numeric literal 49 to the stack.

Then, 𝕚 attempts to pop a list from the stack, and Neim implicitly converts 49 to [4 9]. It then pops another element, which is the input, provided implicitly. Finally, it checks that the input is in the list.

Try it!

• Umm, can't you use one of the constants for 49? – Erik the Outgolfer Jun 12 '17 at 11:20
• @EriktheOutgolfer Forgot all about them :P – Okx Jun 12 '17 at 11:23
• And wait Neim is competing? o_O it even beats Jelly – Erik the Outgolfer Jun 12 '17 at 11:23
• Why the heck does Neim have a built-in for 49? :P – ETHproductions Jun 12 '17 at 16:05
• @ETHproductions It has a built-in for all numbers 1-156. As it's an incomplete language, characters not assigned are automatically assigned as a variable. It used to have numbers up to 180 (also it was Erik's idea to add these :P) – Okx Jun 12 '17 at 16:07

# Befunge, 2017 10 bytes

&4-:5-*!.@


Try it online!

Thanks @ovs for -7 bytes!

## How?

&4-:5-*!.@    Initial pointer direction >  (Input: 9   )
&             Get input as integer         (Stack: 9   )
4-           Subtract 4                   (Stack: 5   )
:          Duplicate                    (Stack: 5, 5)
5-        Subtract 5                   (Stack: 5, 0)
*       Multiply                     (Stack: 0   )
!      NOT                          (Stack: 1   )
.     Print as integer             (Stack:     )
@    End of program


## Proof that 4 and 9 are the only valid square repdigits

The last two digits of any repdigit>10 squared are two different values, except 8..8:

 n    n^2 % 100
--------------
1..1     21
2..2     84
3..3     89
4..4     36
5..5     25
6..6     36
7..7     29
8..8     44
9..9     01


88^2 = 7744, and the last three digits of 8..8^2 is 544.

• +1 just for the proof. I really wish I had checked to make sure there were more repdigits before asking this. – Gryphon - Reinstate Monica Jun 12 '17 at 13:05
• @Gryphon You could use the Sandbox to prevent issues like this. – JungHwan Min Jun 12 '17 at 13:16
• Yes, I should have posted this in the sandbox first. – Gryphon - Reinstate Monica Jun 12 '17 at 13:17
• &4-:5-*!.@ for 10 bytes – ovs Jun 12 '17 at 14:29
• @ovs Wow, that's awesome. I couldn't think of using a NOT... – JungHwan Min Jun 12 '17 at 14:42

# Mathematica, 11 bytes

#==4||#==9&


# C#, JavaScript, Java, 12 bytes

n=>n==4|n==9


For Java replace => with ->.

Or a version more in the spirit of the challenge, C# only, for 61 bytes:

g=n=>n.Replace(n[0]+"","")==""
n=>g(n)&g(System.Math.Sqrt(n))

• The 12 byte solution works for JS too. – Shaggy Jun 12 '17 at 11:19
• @Shaggy I suppose it will work for Java too – TheLethalCoder Jun 12 '17 at 11:21
• Doesn't Java use - instead of = for arrow functions? – Shaggy Jun 12 '17 at 11:22
• @Shaggy Oh yeah... added a comment about it because it is really the same code. – TheLethalCoder Jun 12 '17 at 11:23
• Was about to post a Java answer when I saw this. +1 – Kevin Cruijssen Jun 12 '17 at 11:32

# Jelly, 4 bytes

e4,9


Try it online!

Note: if you disprove me, I'll edit. This returns a truthy result only if the input is 4 or 9.

Junghuan Min ninja'd a proof...

# 05AB1E, 5 bytes

49S¹å


Try it online!

# APL (Dyalog), 5 bytes

Just tests for membership of {4,9}

∊∘4 9


Try it online!

# Braingolf, 19 bytes

.pl3e1:0|>e1:0|<+1-


Try it online!

This is as far as I can tell actually the shortest way to check "is n 4 or 9?"

Will output 1 if input is 4 or 9, otherwise will output 0

## Explanation

.pl3e1:0|>e1:0|<+1-  Implicit input from commandline args
.p                   Duplicate, pop duplicate, push prime factors
l3e                If there are exactly 3 items in stack..
(2 prime factors plus original input)
1               ..Push 1
:              Else
0             ..Push 0
|            Endif
>           Move last item to start
e          If 2 prime factors are equal..
1         ..Push 1
:        Else
0       ..Push 0
|      Endif
<     Move first item to end
+    Sum last 2 items
1-  Subtract 1
Implicit output.

• That's not very golfy, considering the language name is Braingolf and it is beaten by Java. – Okx Jun 12 '17 at 12:39
• @Okx it's bad at complex conditionals – Skidsdev Jun 12 '17 at 13:07

# PHP, 22 bytes

<?=$argn==4||$argn==9;


Try it online!

# Python, 18 bytes

lambda n:n in[4,9]


Try it online!

# Python 3, 39 25 bytes

Solution can be shorter for sure.

old:

n=input();print(n in ['0','1','4','9'])


Try it online!

new:

print(input()in['4','9'])


Try it online!

From this: "a square repdigit is a repdigit that is the square of a different repdigit."

Let z='ζζζζ...' be the square repdigit.

Case 1 z<10:

0² = 0

1² = 1

2² = 4

3² = 9

4² to 9² are not square repdigits.

Case z>10:

Lets assume there is an y∈ℕ with y²=z and y='xxxxx..'

We have just tested all single digits, so if there is an y with y² = z, then it has to be y>10.

So we can write y = x[10°+10¹] + x[10²+10³+...]

Then it is: y² = x²[10°+10¹]² + r = x² [10° + 2*10¹] + r, with r only containing summands of power >1.

Comparing z='ζζζ..' with y² we get: x²=ζ and 2x²=ζ, hence x=0.

⇒ The only square repdigits are 0,1, 4 and 9.

• I don't understand the + r part. – JungHwan Min Jun 12 '17 at 12:42
• Emphasis: a square repdigit is a repdigit that is the square of a different repdigit. – Okx Jun 12 '17 at 12:42
• @JungHwanMin: You are right "r>100" is not clear. Now, as r=r₂*10²+r₃*10³+..., it should be clear, that r just contains all dezimals >=10². – P. Siehr Jun 12 '17 at 12:51
• I think you can write [10⁰+10¹] as simply 11. Also, I can't understand what the r is for. – Erik the Outgolfer Jun 12 '17 at 12:52
• Welcome on the site! Nice first answer! (as Okx mentioned, 0 and 1 are not square repdigits though) – Dada Jun 12 '17 at 12:52

# Javascript, 17 bytes

a=>!((a-4)*(a-9))


f=
a=>!((a-4)*(a-9))

for (i=0;i<12;i++) console.log(''+i+' -> '+f(i))

# Batch, 65 58 53 46 bytes

I have code-copying issues.

@if %1 neq 4 if %1 neq 9 echo 0&exit/b
echo 1


Return 1 for truthy value, 0 for falsely value.

• Unrolling the loop to @if %1 neq 4 if %1 neq 9 echo 0&exit/b is a few bytes shorter. (FYI my solution is 26 bytes.) – Neil Jun 12 '17 at 12:04