Smallest number such that concatenation is a square

05AB1E, 7 bytes

∞<.Δ«Å²

Try it online or verify all test cases.

05AB1E (legacy), 8 bytes

[N«Å²#}N

Try it online or verify all test cases.

Alternative 8-byter which works in both 05AB1E versions (credit to @Grimmy):

[N«Å²iNq

Try it online (no test suite due to the program terminate q).

Explanation:

∞         # Push an infinite list in the range [1, ...]
 <        # Decrease each by 1 to make the range [0, ...]
  .Δ      # Find the first value which is truthy for:
    «     #  Concat the value to the (implicit) input-integer
     Ų   #  And check whether it is a square number
          # (after which this found first value is output implicitly as result)

[         # Start an infinite loop:
 N«       #  Concat the 0-based loop index to the (implicit) input-integer
   Ų     #  If it's a square number:
     #    #   Stop the infinite loop
}N        # After the infinite loop has stopped: push the last index
          # (after which this found index is output implicitly as result)

[         # Start an infinite loop:
 N«       #  Concat the 0-based loop index to the (implicit) input-integer
   Ųi    #  If it's a square number:
      N   #   Push the index again
       q  #   And terminate the program
          #   (after which this index is output implicitly as result)

The legacy version didn't had the builtin, and in the new version it isn't possible to push the last index N after a loop is terminated, which is why I decided to post both solutions.


J, 27 21 bytes

(]+0<1|2%:,&.":)^:_&0

Try it online!

-6 bytes thanks to FrownyFrog

  • ( )^:_ invoke the verb in parens continuously until it's output stops changing
  • &0 set the right argument -- the one that will change each iteration -- to 0 (the left argument, the input, will remain fixed)

Now let's break down what's in the parens

  • ]+ the right arg plus...
  • 0< 0 or 1, depending on if 0 is less than...
  • 1| the reminder when 1 divides...
  • 2%: the square root of...
  • ,&.": the left arg (original input) catted with , the right arg "under" &. stringification ":: ie, turn them both into strings, cat them, then convert back to an int

Perl 6, 23 bytes

{(0...($_~*)**.5%%1)-1}

Try it online!

Explanation

{                     }  # Anonymous codeblock
 (0...             )-1   # Find the first number
      ($_~*)             # That when appended to the input
            **.5         # Has a sqrt
                %%1      # That is whole