Напишите кратчайшую возможную программу (длина измеряется в байтах), удовлетворяющую следующим требованиям:
- нет ввода
- вывод на стандартный вывод
- исполнение в конечном итоге прекращается
- общее количество выходных байтов превышает число Грэма
Предположим, что программы работают до «нормального» завершения на идеальном компьютере 1, способном получить доступ к неограниченным ресурсам, и что общие языки программирования модифицируются, если необходимо (без изменения синтаксиса), чтобы разрешить это. Из-за этих предположений мы могли бы назвать это своего рода Gedankenexperiment.
Для начала, вот 73-байтовая программа Ruby, которая вычисляет f ω + 1 (99) в быстро растущей иерархии :
f=proc{|k,n|k>0?n.times{n=f[k-1,n]}:n+=1;n};n=99;n.times{n=f[n,n]};puts n
1 РЕДАКТИРОВАТЬ: Точнее, предположим, что мы берем существующую систему и модифицируем ее только для того, чтобы не было верхнего предела размера хранилища (но он всегда конечен). Время выполнения инструкций не должно изменяться, но предполагается, что машина идеальна в том смысле, что у нее не будет верхнего предела срока ее службы.
Ответы:
GolfScript (
4947 символов)Смотрите Lifetime червя для большого количества объяснений. Короче говоря, это печатает число больше, чем f ω ω (2).
источник
Haskell,
59575563How it works:
%
simply takes a function and composes itn-1
times on top ofs
; i.e.%3
takes a functionf
and returns a function ofn
that equals applying itf
to 3,n-1
times in a row. If we iterate the application of this higher-order function, we get a fast-growing sequence of functions – starting with exponentiation, it's exactly the sequence of Knuth-arrow-forest sizes:((%3)%(3^))1 n = (3^)n = 3ⁿ = 3↑n
((%3)%(3^))2 n = ((3^)%3)n = (3↑)ⁿ⁻¹ $ 3 = 3↑↑n
((%3)%(3^))3 n = (((3^)%3)%3)n = (3↑↑)ⁿ⁻¹ $ 3 = 3↑↑↑n
and so on.
((%3)%(3^))n 3
is3 ↑ⁿ 3
, which is what appears in the calculation to Graham's number. All that's left to do is composing the function(\n -> 3 ↑ⁿ 3) ≡ flip((%3)%(3^))3
more than 64 times, on top of 4 (the number of arrows the calculation starts with), to get a number larger than Graham's number. It's obvious that the logarithm (what a lamely slow function that is!) ofg₆₅
is still larger thang₆₄=G
, so if we print that number the output length exceedsG
.⬛
источник
print$((flip((%3)%(3*))3)%2)1
, there's a run-time error - can you say why? It succeeds when the2
is changed to1
(output is 81).Int
quickly. On a 64-bit system, that consumes too much memory to reproduce, but of course it still won't allow to reachG
. I need the (big-int)Integer
type, so I can't use!!
; wait...%
.((%3)%(3*))2 n
actually grows faster than you say (a good thing), but my Haskell-fu is inadequate to understand why. Forn = 0, 1, 2, ...
, instead of giving3, 3^3, 3^(3^3), ...
, it gives3, 3^(3+1), 3^((3^(3+1))+1), ...
.((%3)%(3*))n 3
is larger than3 ↑ⁿ 3
". Or do you mean something else? Anyway, I changed the definition so that it's all equalities (at least I think so, to lazy to check now...) rather than larger-thans. And if you change66
to65
, it actually producesG
itself, ain't that nice?Pyth,
2928 bytesDefines a lambda for hyper-operation and recursively calls it. Like the definition for Graham's number, but with larger values.
This:
Defines a lambda, roughly equal to the python
This gives the hyper-operation function, g(G,H) = 3↑G+1(H+1).
So, for example, g(1,2)=3↑23 = 7,625,597,484,987, which you can test here.
V<x><y>
starts a loop that executes the body,y
,x
times.=gZT
is the body of the loop here, which is equivalent toZ=g(Z,10)
The code:
Should recursively call the hyperoperation above 64 times, giving Graham's Number.
In my answer, however, I've replaced the single digits with
T
, which is initialized to 10, and increased the depth of recursion to 99. Using Graham Array Notation, Graham's Number is [3,3,4,64], and my program outputs the larger [10,11,11,99]. I've also removed the)
that closes the loop to save one byte, so it prints each successive value in the 99 iterations.источник
Python (111+n), n=length(x)
Although this one is not as short as the answerer's Ruby program, I'll post it anyway, to rule this possibility out.
It uses the Ackermann function, and calls the Ackermann function with m and n being the values from another call to the Ackermann function, and recurses 1000 times.
This is probably bigger than Graham's number, but I'm not sure, because nobody knows the exact length of it. It can be easily extended, if it's not bigger.
источник
return
statement or alambda
.exec'x=A(x,x);'*x;print x
, then the program is ok and the output is approximately f_(ω+1)(x) (assumimg the Ackermann function code is correct), which has more than G bytes even for x=99, say. (In my Ruby program,f[m,n]
is a version ofA(m,n)
.)eval
instead ofexec
, your last line could bef=lambda x:A(x,x);print eval('f('*x+'x'+')'*x)
. Also, your def of A(m,n) needs to be corrected per boothby's comment.Ruby,
545250 bytesRuby,
858176716864635957 bytesPretty much fast growing hierarchy with f(a+1) > fω+1(a).
Ruby, 61 bytes
Basically an Ackermann function with a twist.
Ruby,
6359 bytesAnother Ruby,
7471 bytesBasically Ackermann function to itself 99 times.
источник
Python: 85
Which maybe could be shortened to 74 +
length(X)
:Where
X
is an appropriate big number such that the resultant hyperoperation on3, 3
is bigger than Grahams number(if this number is less than99999999999
then some byte is saved).Note: I assume the python code is executed on the interactive interpreter hence the result is printed to stdout, otherwise add
9
bytes to each solution for the call toprint
.источник
Javascript, 83 bytes
Another Ackermann function solution.
источник
JavaScript, 68 bytes, however uncompeting for using ES6
a
function is similar to up-arrow notation with base 9.b
function is: b(x)=bx(9).b(99)
is ~fω+1(99), compared to Graham's number<fω+1(64).источник