Equality in the sum of digits
Jelly, 13 bytes
,²DS€=/
1dz#Ṫ
Input is 1-indexed. Try it online!
How it works
1dz#Ṫ Main link. Argument: n (index)
1 Set the return value to 1.
# Execute ... until ... matches have been found.
Ç the helper link
³ n
Ṫ Extract the last match.
,²DS€=/ Helper link. Argument: k (integer)
,² Pair k with k².
D Convert each to decimal.
S€ Compute the sum of each list of base 10 digits.
=/ Reduce by equality.
Haskell, 54 bytes
s=sum.map(read.pure).show
([x|x<-[1..],s x==s(x^2)]!!)
Usage example: ([x|x<-[1..],s x==s(x^2)]!!) 17
-> 289
.
s calculates the digit sum:
show -- turn number into a string
map(read.pure) -- turn every character (the digits) in to a
-- one element string and convert back to integer
sum -- sum those integers
main function:
[x|x<-[1..] ] -- make a list of all x starting from 1
,s x==s(x^2) -- where s x == s (x^2)
!! -- pick nth element from that list
JavaScript (ES6), 76 73 72 bytes
n=>eval("for(q=s=>eval([...s+''].join`+`),i=1;q(i)!=q(i*i)||n--;i++);i")
I spent 30 minutes trying to get this to work until I realized I was outputting the wrong variable :|
This is zero-indexed.