last day (21 days later) » 

06:58
hi
so basically my solution uses a cache
of length 1 000 000
yeah i'm writing one up quickly don't exactly remember what i used
oh okay
what lang are you using?
I used APL
doesn't seem like that should take so long though
JS :P
:P
well the funny thing was that I went exploring the conjecture in detail, trying to discover possible shortcuts, for several days. In the end, I couldn't apply anything I learnt to my solution
07:35
@ASCII-only are you still there?
I have a question on C (a port of the solution to C from APL) if you don't mind
so I have a global array int cache[1000]={0}; The next line I have cache[1]=1; but gcc thinks that I am assigning another array instead of setting the value of the initial array
is there any way to overcome this?
:| what
int cache[1000] = {0};
cache[1]=1;
is cache[1] = 1; global code
07:40
yes
they are all outside of main
well there's your problem
C has no global code
;_;
I can't even do stuff like cache[n]=blah inside a global function
you can
well you should be able to, what error is it giving
07:48
I get a segfault when doing cache[n]=blah in a function
segfault 11, to be more precise
btw {0} is not needed here
wait
segfault probably means just out of range
07:51
I think it's something to do with my code
simply cache[0]=1;return cache[0]; works
make sure n < 1000
wait what it works now
changing the code from being 1-indexed to 0-indexed makes everything work
well for 1-indexed you'd need cache[1001]
07:59
wait, 1-indexed works now
waht
yay managed to make it work
finally
runs in ~300 ms
@KritixiLithos IDK why yours takes so long
if you want spoiler i can give it to you
do you also use a cache?
yes
because memoization is fast
I would post my code, but it is in APL, unless you understand it
don't understand it
can you post pseudocode
@KritixiLithos can you post it
08:15
gimme some time
I was trying a C port, but it gives a segfault when testing the largest number under 1 000 000
but it works fine under 100 000
probably no more stack space then?
use an int* array instead + array = malloc(sizeof(int) * 1000000)
08:18
it does 100 000 under 0.1 seconds though
@ASCII-only what do you mean
nvm
btw I can initialise the array fine, but I get a segfault when finding the maximum value under 1 000 000
I still get the segfault
hmm what
weird
wait
pls post the code
i think you're still not doing bounds checking
#include<stdio.h>

// the cache stores the stopping time for all integers for efficiency
int *cache;

/*
 * returns the stopping time, the amount of times for an integer to reach 1 via the Collatz Conjecture
 * */

int stoppingTime(int n) {
	int tmp = n&1?n*3+1:n>>1;
	if(n > 1000000) return 1 + stoppingTime(tmp);
	if(cache[n-1]) return cache[n-1];
	return (cache[n-1] = 1 + stoppingTime(tmp));
}

int main() {
	cache = malloc(sizeof(int) * 1000000);

	// initialise the result for n=1
	cache[0]=1;
yeah your bounds checking is broken
08:23
where
wait no
array siuze
should be 1000001 not 1000000
my js code:
var d = new Date();
var a = Array(1000001).fill();
a[0] = a[1] = 1;
for (var i = 2; i <= 1000000; i++) {
    var c = -1, j = i;
    while (c++, (j = j % 2 ? j * 3 + 1 : j / 2) > i);
    a[i] = a[j] + c;
}
console.log(a.indexOf(a.reduce((p, c) => Math.max(p, c))));
new Date() - d;
@ASCII-only still bork
:|
@KritixiLithos realized it's - 1 anyway so it's actually 1000000
for(int i=1; i<1000000; i++) { changing the 1 million to 100 thousand here works though
but 200 thousand borks
seems like a stack size problem
08:26
;_;
btw using your method of doing the comparison while doing collatz i get <200ms
var d = new Date(),
    a = Array(1000001).fill(),
    max = 0,
    winner = 0;
a[0] = a[1] = 1;
for (var i = 2; i <= 1000000; i++) {
    var c = -1, j = i;
    while (c++, (j = j % 2 ? j * 3 + 1 : j / 2) > i);
    a[i] = a[j] + c;
    if (a[i] > max) max = a[i], winner = i;
}
console.log(winner);
new Date() - d;
:D
yeah maybe it's just the stack size, APL used to be borky for me because it exceeded the memory limits, then I reduced the cache size
hmm seems like max is 113383
oh yeah
this is why it breaks
for 113383 the max value can't be represented as an int
#include<stdio.h>
int cache[1000000];
int stoppingTime(long n) {
	long tmp = n&1?n*3+1:n>>1;
	if(n > 1000000) return 1 + stoppingTime(tmp);
	if (cache[n-1]) return cache[n-1];
	return (cache[n-1] = 1 + stoppingTime(tmp));
}
int main() {
	cache[0]=1;
	int max=0;
	int j=1;
	for(int i=1; i<1000000; i++) {
		if(stoppingTime(i) > max) {
			max = cache[i-1];
			j = i;
		}
	}
	printf("%d\n", j);
	return 0;
}
 
4 hours later…
13:06
ah thanks @ASCII-only
 
2 hours later…
15:28
wut
16:11
@LegionMammal978 nuffin'
 
3 hours later…
19:05
What What is the purpose of this room? Collatz?

  last day (21 days later) »