zlacker

[parent] [thread] 13 comments
1. gglon+(OP)[view] [source] 2015-02-17 01:44:03
Now the contest for programmers: Write the biggest number in one line of code (80 characters, keywords count as 1 character, whitespace - 0) using computer language of choice(standard library with infinite integer type) that any reasonable programmer can prove that it is actually a finite number.
replies(5): >>swatow+m3 >>yepguy+v6 >>evanb+q9 >>leohut+J9 >>throwa+Wb
2. swatow+m3[view] [source] 2015-02-17 02:46:45
>>gglon+(OP)
might be easier to use a language like Idris, which can check that functions are total (i.e. return a finite number in finite time).
replies(1): >>cousin+XM
3. yepguy+v6[view] [source] 2015-02-17 04:06:10
>>gglon+(OP)
My solution in brainfuck, given a finite tape:

    -[>-]-
4. evanb+q9[view] [source] 2015-02-17 05:24:48
>>gglon+(OP)
Mathematica has important whitespace for indicating multiplication, and it's not clear what counts as a keyword, so here are 80 copy-and-pasteable characters:

  u[n_][a_][b_]:=If[n==0,a b,Nest[u[n-1]@a,1,b]];Nest[u[#^#^#][#]@#&,9,u[99][9]@9]
u[n][a][b] gives a (Knuth's up arrow)^n b. The after-the-semicolon expression computes

  f(f(f(f(... u[99][9][9] fs total ... f(9) ... ))))
with the function f(n)=u[n^n^n][n][n]. This clearly results in a finite number, since it is just iterated iterated iterated iterated ... (finitely many "iterated"s) ... iterated exponentiation of finite numbers.

However, even when I try to compute (after $RecursionLimit=Infinity)

  Nest[u[#^#^#][#]@#&,2,u[2][2]@2]
my kernel crashes. This number is BIG.

There is one obvious way to make this number even bigger: make the base case yield a^b. However, then it's not Knuth's up arrow notation, so it's harder to debug by looking at the wikipedia page :). I used all my tricks (like using @) to get rid of extraneous characters, which gave me space to put #^#^# as the first argument of u. I still had 1 character remaining, so a 9 became 99. If you can squeeze a few more characters #^#^# and 99 should be substituted for u[#][#]@# and 9.

https://en.wikipedia.org/wiki/Knuth's_up-arrow_notation

replies(1): >>evanb+Q9
5. leohut+J9[view] [source] 2015-02-17 05:31:31
>>gglon+(OP)

   num = 0; while (true) { try { num++; } except ( mallocFail ) { return num; } }
replies(1): >>Gurken+sg
◧◩
6. evanb+Q9[view] [source] [discussion] 2015-02-17 05:34:41
>>evanb+q9
I just realized 99 should be replaced with "9!".
replies(1): >>evanb+Fa
◧◩◪
7. evanb+Fa[view] [source] [discussion] 2015-02-17 05:54:27
>>evanb+Q9
Using the infix special form ~ we can cram in another ^#:

  u[n_][a_,b_]:=If[n==0,a b,Nest[a~u[n-1]~#&,1,b]];Nest[#~u[#^#^#^#]~#&,9,9~u@9~9]
I should also note that I'm not confident as to which of

  Nest[#~u[#^#^#^#]~#&,9,9~u@9~9]
  Nest[#~u@#~#&,9,9~u[9^9^9^9]~9]
is larger.
replies(1): >>gglon+MZ
8. throwa+Wb[view] [source] 2015-02-17 06:31:05
>>gglon+(OP)
Related, this came up in yesterday's thread about Graham's number:

http://djm.cc/bignum-results.txt

https://news.ycombinator.com/item?id=9054274

◧◩
9. Gurken+sg[view] [source] [discussion] 2015-02-17 08:41:48
>>leohut+J9
Just do -1 on an unsigned number if you're that lazy.
◧◩
10. cousin+XM[view] [source] [discussion] 2015-02-17 16:48:13
>>swatow+m3
Unfortunately, if a language L has the property that all programs in it are total, that means L is not Turing-complete. In fact, that puts a hard limit on the growth speed of functions definable in L. For example, the Busy Beaver function for L won't be definable in L (because otherwise you'd get the same paradox as in the halting problem), but will be easily definable in any Turing-complete language (because you can just dovetail through all possible programs in L without worrying that any of them will loop forever).
◧◩◪◨
11. gglon+MZ[view] [source] [discussion] 2015-02-17 18:30:40
>>evanb+Fa
Very nice. Mathematica can clearly do the job. But I feel like there is still a lot of room for improvement. Clearly though, the proof would be more and more difficult.

Here is my modification:

  M=Nest;
  u[f_][n_][a_]:=If[n<1,f@a,M[u[f][n-1],a,a]];
  u[#][#@9][#@9]&@(u[#!&][#][#]&)
82 chars total.

comments:

  (*start with definition of Knuth up arrow*)
  u1[n_][a_][b_]:=If[n==0,a b,Nest[u[n-1]@a,1,b]]
  (*let treat 1 as symbol and take 1 == b == a *)
  u2[n_][a_]:=If[n==0,a a,Nest[u[n-1],a,a]]
  (*next define for arbitrary function f  instead of multiplication*)
  u[f_][n_][a_]:=If[n==0,f@a,Nest[u[n-1],a,a]]
  (*numerical example when we take n<3 instead of n==0*)
  u[#! &][#][#] &@3 = u[#! &][3][3] = 10^1746 
  (*Next take the function f and parameters a to be: *)
  f = u[#!&][#][#]&
  a = f@9
  (*compute final number*)
  u[f][a][a]
  (*those 3 steps are shortened to: *)
  u[#][#@9][#@9]&@(u[#!&][#][#]&)
replies(2): >>evanb+f51 >>evanb+e71
◧◩◪◨⬒
12. evanb+f51[view] [source] [discussion] 2015-02-17 19:20:50
>>gglon+MZ
Smart. It didn't occur to me to have the base case be an arbitrary function. Yours is much larger than mine. One comment: M=Nest; is a waste of characters. I tried that in my solution too, but it wound up costing me an extra character ;). So I think you're down to 75 characters. It might make sense to remove the factorial, and change the base case of u to f@f@f@f@a.
replies(1): >>gglon+M81
◧◩◪◨⬒
13. evanb+e71[view] [source] [discussion] 2015-02-17 19:45:41
>>gglon+MZ
I think there might be a nice way to use #0 to blow up the numbers even further. But I have to do real work :)
◧◩◪◨⬒⬓
14. gglon+M81[view] [source] [discussion] 2015-02-17 20:02:42
>>evanb+f51
Thanks, I forgot to remove M=Nest that was beneficial in my previous attempts where I used 3 Nests.

But remember:

Never forget that it is a waste of energy to do the same thing twice, and that if you know precisely what is to be done, you need not do it at all. --- E. E. ``Doc'' Smith (1930)

      ...the optimal solution avoids all pattern.
                                        --- Douglas Hofstadter (1983)
http://djm.cc/bignum-results.txt

So I would recommend to avoid things like f@f@f@f@a where there is clearly a pattern.

[go to top]