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,8 @@
int Q(int n) => n>2 ? Q(n-Q(n-1))+Q(n-Q(n-2)) : 1;
main() {
for(int i=1;i<=10;i++) {
print("Q($i)=${Q(i)}");
}
print("Q(1000)=${Q(1000)}");
}

View file

@ -0,0 +1,42 @@
class Q {
Map<int,int> _table;
Q() {
_table=new Map<int,int>();
_table[1]=1;
_table[2]=1;
}
int q(int n) {
// if the cache is not filled until n-1, fill it starting with the lowest entries first
// this avoids doing a recursion from n to 2 (e.g. if you call q(1000000) first)
// this doesn't happen in the tasks calls since the cache is filled ascending
if(_table[n-1]==null) {
for(int i=_table.length;i<n;i++) {
q(i);
}
}
if(_table[n]==null) {
_table[n]=q(n-q(n-1))+q(n-q(n-2));
}
return _table[n];
}
}
main() {
Q q=new Q();
for(int i=1;i<=10;i++) {
print("Q($i)=${q.q(i)}");
}
print("Q(1000)=${q.q(1000)}");
int count=0;
for(int i=2;i<=100000;i++) {
if(q.q(i)<q.q(i-1)) {
count++;
}
}
print("value is smaller than previous $count times");
}

View file

@ -0,0 +1,17 @@
main() {
List<int> q=new List<int>(100001);
q[1]=q[2]=1;
int count=0;
for(int i=3;i<q.length;i++) {
q[i]=q[i-q[i-1]]+q[i-q[i-2]];
if(q[i]<q[i-1]) {
count++;
}
}
for(int i=1;i<=10;i++) {
print("Q($i)=${q[i]}");
}
print("Q(1000)=${q[1000]}");
print("value is smaller than previous $count times");
}