Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ struct Permutations(bool doCopy=true, T) {
|
|||
static if (!doCopy)
|
||||
T[] result;
|
||||
|
||||
this(T)(T[] items, int r=-1) pure /*nothrow*/ {
|
||||
this(T)(T[] items, int r=-1) pure nothrow @safe {
|
||||
this.items = items;
|
||||
immutable int n = items.length;
|
||||
if (r < 0)
|
||||
|
|
@ -20,19 +20,20 @@ struct Permutations(bool doCopy=true, T) {
|
|||
} else {
|
||||
this.stopped = false;
|
||||
this.indices = n.iota.array;
|
||||
this.cycles = iota(n, n_minus_r, -1).array;
|
||||
//this.cycles = iota(n, n_minus_r, -1).array; // Not nothrow.
|
||||
this.cycles = iota(n_minus_r + 1, n + 1).retro.array;
|
||||
}
|
||||
|
||||
static if (!doCopy)
|
||||
result = new T[r];
|
||||
}
|
||||
|
||||
@property bool empty() const pure nothrow {
|
||||
@property bool empty() const pure nothrow @safe @nogc {
|
||||
return this.stopped;
|
||||
}
|
||||
|
||||
static if (doCopy) {
|
||||
@property T[] front() const pure nothrow {
|
||||
@property T[] front() const pure nothrow @safe {
|
||||
assert(!this.stopped);
|
||||
auto result = new T[r];
|
||||
foreach (immutable i, ref re; result)
|
||||
|
|
@ -40,7 +41,7 @@ struct Permutations(bool doCopy=true, T) {
|
|||
return result;
|
||||
}
|
||||
} else {
|
||||
@property T[] front() pure nothrow {
|
||||
@property T[] front() pure nothrow @safe @nogc {
|
||||
assert(!this.stopped);
|
||||
foreach (immutable i, ref re; this.result)
|
||||
re = items[indices[i]];
|
||||
|
|
@ -48,14 +49,14 @@ struct Permutations(bool doCopy=true, T) {
|
|||
}
|
||||
}
|
||||
|
||||
void popFront() pure /*nothrow*/ {
|
||||
void popFront() pure nothrow /*@safe*/ @nogc {
|
||||
assert(!this.stopped);
|
||||
int i = r - 1;
|
||||
while (i >= 0) {
|
||||
immutable int j = cycles[i] - 1;
|
||||
if (j > 0) {
|
||||
cycles[i] = j;
|
||||
swap(indices[i], indices[$ - j]);
|
||||
indices[i].swap(indices[$ - j]);
|
||||
return;
|
||||
}
|
||||
cycles[i] = indices.length - i;
|
||||
|
|
@ -63,7 +64,7 @@ struct Permutations(bool doCopy=true, T) {
|
|||
assert(n1 >= 0);
|
||||
immutable int num = indices[i];
|
||||
|
||||
// copy isn't nothrow.
|
||||
// copy isn't @safe.
|
||||
indices[i + 1 .. n1 + 1].copy(indices[i .. n1]);
|
||||
indices[n1] = num;
|
||||
i--;
|
||||
|
|
@ -75,7 +76,7 @@ struct Permutations(bool doCopy=true, T) {
|
|||
|
||||
Permutations!(doCopy, T) permutations(bool doCopy=true, T)
|
||||
(T[] items, int r=-1)
|
||||
pure /*nothrow*/ {
|
||||
pure nothrow @safe {
|
||||
return Permutations!(doCopy, T)(items, r);
|
||||
}
|
||||
|
||||
|
|
@ -86,8 +87,8 @@ import std.stdio, std.typecons, std.conv, std.algorithm, std.array,
|
|||
|
||||
enum maxIters = 1_000_000;
|
||||
|
||||
string A036058(in string ns) pure {
|
||||
return ns.group.map!(t => t[1].text ~ cast(char)t[0]).join;
|
||||
string A036058(in string ns) pure nothrow @safe {
|
||||
return ns.representation.group.map!(t => t[1].text ~ char(t[0])).join;
|
||||
}
|
||||
|
||||
int A036058_length(bool doPrint=false)(string numberString="0") {
|
||||
|
|
@ -99,12 +100,12 @@ int A036058_length(bool doPrint=false)(string numberString="0") {
|
|||
static if (doPrint)
|
||||
writefln(" %2d %s", iterations, numberString);
|
||||
|
||||
numberString = cast(string)(numberString
|
||||
.dup
|
||||
.representation
|
||||
.sort()
|
||||
.release
|
||||
.assumeUnique);
|
||||
numberString = numberString
|
||||
.dup
|
||||
.representation
|
||||
.sort()
|
||||
.release
|
||||
.assumeUTF;
|
||||
|
||||
if (lastThree[].canFind(numberString))
|
||||
break;
|
||||
|
|
@ -124,12 +125,12 @@ Tuple!(int,int[]) max_A036058_length(R)(R startRange = 11.iota) {
|
|||
auto max_len = tuple(-1, (int[]).init);
|
||||
|
||||
foreach (n; startRange) {
|
||||
immutable string sns = cast(string)(n
|
||||
.to!(char[])
|
||||
.representation
|
||||
.sort()
|
||||
.release
|
||||
.assumeUnique);
|
||||
immutable sns = n
|
||||
.to!(char[])
|
||||
.representation
|
||||
.sort()
|
||||
.release
|
||||
.assumeUTF;
|
||||
|
||||
if (sns !in alreadyDone) {
|
||||
alreadyDone[sns] = true;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ Rec* findRec(char* s, Rec* root) nothrow {
|
|||
next = root.p[c];
|
||||
if (!next) {
|
||||
nNodes++;
|
||||
next = recPool.newItem();
|
||||
next = recPool.newItem;
|
||||
root.p[c] = next;
|
||||
}
|
||||
root = next;
|
||||
|
|
@ -66,7 +66,7 @@ Rec* findRec(char* s, Rec* root) nothrow {
|
|||
return root;
|
||||
}
|
||||
|
||||
void nextNum(char* s) nothrow {
|
||||
void nextNum(char* s) nothrow @nogc {
|
||||
int[10] cnt;
|
||||
for (int i = 0; s[i]; i++)
|
||||
cnt[s[i] - '0']++;
|
||||
|
|
@ -105,7 +105,7 @@ void main() nothrow {
|
|||
char[32] buf;
|
||||
rec_root = recPool.newItem();
|
||||
|
||||
foreach (i; 0 .. MAXN) {
|
||||
foreach (immutable i; 0 .. MAXN) {
|
||||
sprintf(buf.ptr, "%d", i);
|
||||
int l = getLen(buf.ptr, 0);
|
||||
if (l < ml)
|
||||
|
|
@ -119,10 +119,10 @@ void main() nothrow {
|
|||
}
|
||||
|
||||
printf("seq leng: %d\n\n", ml);
|
||||
foreach (i; 0 .. nLongest) {
|
||||
foreach (immutable i; 0 .. nLongest) {
|
||||
sprintf(buf.ptr, "%d", longest[i]);
|
||||
// print len+1 so we know repeating starts from when
|
||||
foreach (l; 0 .. ml + 1) {
|
||||
foreach (immutable l; 0 .. ml + 1) {
|
||||
printf("%2d: %s\n", getLen(buf.ptr, 0), buf.ptr);
|
||||
nextNum(buf.ptr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue