lyng/docs/samples/happy_numbers.lyng
sergeych 512dda5984 fix #5 loop optimization
fixed arguments modifying bug
added samples and samplebooks w/tests
2025-06-03 10:44:42 +04:00

20 lines
568 B
Plaintext

/*
Count "happy tickets": 6-digit numbers where sum of first three
digits is equal to those of last three. Just to demonstrate and
test the Lyng way. It is not meant to be effective.
*/
fun naiveCountHappyNumbers() {
var count = 0
for( n1 in 0..9 )
for( n2 in 0..9 )
for( n3 in 0..9 )
for( n4 in 0..9 )
for( n5 in 0..9 )
for( n6 in 0..9 )
if( n1 + n2 + n3 == n4 + n5 + n6 ) count++
count
}
assert( naiveCountHappyNumbers() == 55252 )