Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,23 @@
bool isHappy(int n) pure nothrow {
int[int] past;
while (true) {
int total = 0;
while (n > 0) {
total += (n % 10) ^^ 2;
n /= 10;
}
if (total == 1)
return true;
if (total in past)
return false;
n = total;
past[total] = 0;
}
}
void main() {
import std.stdio, std.algorithm, std.range;
int.max.iota.filter!isHappy.take(8).writeln;
}

View file

@ -0,0 +1,19 @@
import std.stdio, std.algorithm, std.range, std.conv, std.string;
bool isHappy(int n) pure nothrow {
int[int] seen;
while (true) {
immutable t = n.text.representation.map!q{(a - '0') ^^ 2}.sum;
if (t == 1)
return true;
if (t in seen)
return false;
n = t;
seen[t] = 0;
}
}
void main() {
int.max.iota.filter!isHappy.take(8).writeln;
}