Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,15 +1,17 @@
import std.stdio, std.algorithm, std.conv;
string[] selfReferentialSeq(string n, string[] seen=[]) {
static string[][string] cache;
if (n in cache) return cache[n];
if (canFind(seen, n)) return [];
string[] selfReferentialSeq(string n, string[] seen=[]) nothrow {
__gshared static string[][string] cache;
if (n in cache)
return cache[n];
if (seen.canFind(n))
return [];
int[10] digit_count;
foreach (d; n)
foreach (immutable d; n)
digit_count[d - '0']++;
string term;
foreach_reverse (d; 0 .. 10)
foreach_reverse (immutable d; 0 .. 10)
if (digit_count[d] > 0)
term ~= text(digit_count[d], d);
return cache[n] = [n] ~ selfReferentialSeq(term, [n] ~ seen);
@ -20,7 +22,7 @@ void main() {
int max_len;
int[] max_vals;
foreach (n; 1 .. limit) {
foreach (immutable n; 1 .. limit) {
const seq = n.text().selfReferentialSeq();
if (seq.length > max_len) {
max_len = seq.length;
@ -32,6 +34,6 @@ void main() {
writeln("values: ", max_vals);
writeln("iterations: ", max_len);
writeln("sequence:");
foreach (idx, val; max_vals[0].text().selfReferentialSeq())
foreach (const idx, const val; max_vals[0].text.selfReferentialSeq)
writefln("%2d %s", idx + 1, val);
}