Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Happy-numbers/Groovy/happy-numbers.groovy
Normal file
15
Task/Happy-numbers/Groovy/happy-numbers.groovy
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Number.metaClass.isHappy = {
|
||||
def number = delegate as Long
|
||||
def cycle = new HashSet<Long>()
|
||||
while (number != 1 && !cycle.contains(number)) {
|
||||
cycle << number
|
||||
number = (number as String).collect { d = (it as Long); d * d }.sum()
|
||||
}
|
||||
number == 1
|
||||
}
|
||||
|
||||
def matches = []
|
||||
for (int i = 0; matches.size() < 8; i++) {
|
||||
if (i.happy) { matches << i }
|
||||
}
|
||||
println matches
|
||||
Loading…
Add table
Add a link
Reference in a new issue