44
8
Graham's number G
is defined in this way:
u(3,n,1) = 3^n
u(3,1,m) = 3
u(3,n,m) = u(3,u(3,n-1,m),m-1)
[Knuth's up-arrow notation]
[Conway chained arrow notation]
THEN
g1 = u(3,3,4)
g2 = u(3,3,g1)
g3 = u(3,3,g2)
...
G = u(3,3,g63)
You are given that u(3,3,2)=7625597484987
to check your code.
Your task is to write a program/function that will output the value of G
deterministically, given enough integer size and enough time.
References
Leaderboard
var QUESTION_ID=83873,OVERRIDE_USER=48934;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+(?:\.\d+)?)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
2Related. – Leaky Nun – 2016-06-27T07:30:54.113
7Is randomness allowed? If I just output random values, eventually Graham's number must be produced. – miles – 2016-06-27T07:33:45.353
15@miles Why on earth isn't it already a standard loophole? Clarified. – Leaky Nun – 2016-06-27T07:35:20.087
Are there any small intermediate values for
u
you could give us so we can check our code? – xnor – 2016-06-27T07:57:57.987@xnor Added in. – Leaky Nun – 2016-06-27T08:05:01.027
I've added it as a loophole – Mego – 2016-06-27T08:17:55.627
Related – Peter Taylor – 2016-06-27T08:45:19.223
@PeterTaylor How is not known to terminate? – Leaky Nun – 2016-06-27T08:52:42.163
It's not that. The form of the recursive function is very similar. – Peter Taylor – 2016-06-27T09:37:35.330
18Warning: u(3, 3, 2) = u(3, 2, 3) = 7625597484987, so you’ll also want to test on other values such as u(3, 5, 1) = 243 to make sure you got the argument order right. – Anders Kaseorg – 2016-06-27T10:09:08.853
@miles No, that's not true. Even with infinite trials there's no guarantee that you will ever generate a specific number because the numbers are infinite too. – Bakuriu – 2016-06-28T10:05:53.363
@Bakuriu Solution:
i = 0; while True: print(i); i += 1
– user253751 – 2016-06-28T11:18:31.160@immibis He said generating numbers at random. Yours is a deterministic algorithm. – Bakuriu – 2016-06-28T11:26:29.507
@Bakuriu
i = 0; while(true) {if(random() < 0.5) {print(i); print(i+1);} else {print(i+1); print(i);} i += 2;}
– user253751 – 2016-06-28T11:27:52.790@immibis That's still a fundamentally deterministic algorithm because you always choose either
i
ori+1
. The point is, given random oracle that returns natural numbers completely at random, without using monotonic or "quasi-monotonic" sequences, even infinite numbers generated aren't enough to produce all natural numbers with certainty. – Bakuriu – 2016-06-28T11:30:26.773@Bakuriu I thought the point was to demonstrate a potential loophole? – user253751 – 2016-06-28T11:33:07.463
@immibis Miles wanted to propose a solution like "n=get_random_number(); if n == graham; print n else: loop" saying that this program would fit the requirements. My point is that it does not fit the requirements, because even with infinite time there is no guarantee that it will ever output anything. Also, i don't really see why we should exclude this as a loop hole. Given that the program must output only the graham number you have to basically add some kind of check to avoid printing other invalid results, which fundamentally amounts to computing Graham number itself. – Bakuriu – 2016-06-28T11:36:36.980
Does the base of the output matter? Obviously base-G wouldn't be allowed, but could e.g. base-256 be used? – Mego – 2016-07-25T10:42:00.280
@Mego Any base between 1 and 256 inclusive, would that be ok? Or should I extend to 1114112? – Leaky Nun – 2016-07-25T10:43:45.457
Up to you. Base-unicode could make for some interesting outputs. Unary would be terrifying. – Mego – 2016-07-25T10:44:46.780
2Graham's number? – Beta Decay – 2016-08-09T10:47:23.190
You should have made the challenge to output Gn(m) – Matthew Roh – 2017-02-20T12:08:17.340
You can shorten your example by a lot as I have done here by noting that when evaluating Graham's number, the number on the left is always 3. Basically, make a two argument function that represents
– Simply Beautiful Art – 2017-05-14T22:26:23.9033^^...^^x
.