Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -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)}");
|
||||
}
|
||||
42
Task/Hofstadter-Q-sequence/Dart/hofstadter-q-sequence-2.dart
Normal file
42
Task/Hofstadter-Q-sequence/Dart/hofstadter-q-sequence-2.dart
Normal 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");
|
||||
}
|
||||
17
Task/Hofstadter-Q-sequence/Dart/hofstadter-q-sequence-3.dart
Normal file
17
Task/Hofstadter-Q-sequence/Dart/hofstadter-q-sequence-3.dart
Normal 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");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue