I may have been able to still do 94 in EEL though, for the same reason I was able to do the problem I ended up using it for - I seem to have used C++ to solve problem 53 a while ago. However, I am not entirely sure why I hadn't redone the problem more recently, as problem 53 was rather simple to solve. The below code is pretty much a translation of my previous C++ code, which was not too hard to do after having just played around in EEL trying to get problem 94 working. The most notable things about the code below are that it follows EEL coding style, giving the curly-braces-get-their-own-line syntax I don't use very often, and one very important part of the below program: The * 1.0. This coerces to a real number, because EEL only supports 32-bit integers, and only supports 64-bit floating point numbers, because why not?
Below code runs in about 8ms (EEL seems to be a fairly fast language, even though it runs on its own VM).
export function main<args> { function fac(n) { if (n < 2) { return 1; } else { return n * fac(n - 1); } } function isncrbig(n, r) { local denom = fac(r); //very important 1.0 converts to a real; //EEL only has 32 bit ints and only has //64 bit reals. local rest = n * 1.0; local i = n - 1; while (i > (n - r)) { rest = rest * i; if (rest / denom > 1000000) { return true; } i = i - 1; } return false; } local min_r = 10; local ans = 0; local n = 23; while (n <= 100) { while (isncrbig(n, min_r - 1)) { min_r = min_r - 1; } ans = ans + n - (2 * min_r) + 1; n = n + 1; } print(ans); print("\n"); return 0; }
No comments:
Post a Comment