23
1
Introduction
Let's take the number 180
. This is an interesting number because the sum of digits of this number is equal to:
1 + 8 + 0 = 9
And the squared version of this number, or:
180² = 32400 > 3 + 2 + 4 + 0 + 0 = 9
These are both 9. The sum of digits of the original number and the squared number are the same. Of course, this is also found at OEIS: A058369.
Task
Given a non-negative integer n
, output the n
th positive number with this condition.
Test cases (zero-indexed)
Input > Output
0 > 1
1 > 9
2 > 10
3 > 18
4 > 19
5 > 45
6 > 46
7 > 55
8 > 90
9 > 99
10 > 100
11 > 145
12 > 180
13 > 189
14 > 190
15 > 198
16 > 199
17 > 289
18 > 351
19 > 361
The input can also be 1-indexed if that fits you better.
This is code-golf, so the submission with the least amount of bytes wins!
In case nobody has spotted it yet, only numbers which are equivalent to 0 or 1 (mod 9) can appear in the list. – Neil – 2016-03-12T19:05:31.660
@MamaFunRoll Um... no. Sorry. Numbers with digital roots of 5 have squares whose digital root is 7. – Neil – 2016-03-12T20:17:58.420
@Neil owait nvm – Mama Fun Roll – 2016-03-12T20:42:15.437
I wrote a Brachylog predicate to determine whether or not the input is a term of this sequence, but couldn't get the find-nth boilerplate working, so I'll just leave it in a comment:
^₂;?{ẹ+}ᵛ
– Unrelated String – 2019-05-09T03:35:05.193