Knuth's Up-Arrow Notation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Knuth's Up-Arrow Notation

https://en.m.wikipedia.org/wiki/Knuth%27s_up-arrow_notation Knuth's up-arrow notation, written as "↑" or "^", is an operator used to make large numbers. This operator works as follows: a↑b = a*a*...*a (b "a"s) a↑↑b = a↑a↑...↑a (b "a"s) ... Take 2↑↑↑4 as an example: 2↑↑↑4 = 2↑↑2↑↑2↑↑2 = 2↑↑2↑↑(2↑↑2) = 2↑↑2↑↑(2↑2) = 2↑↑2↑↑4 = 2↑↑(2↑↑4) = 2↑↑(2↑2↑2↑2) = 2↑↑(2↑2↑4) = 2↑↑(2↑16) = 2↑↑65536 = 2↑2↑...↑2 (total 65536 "2"s) Is it possible to do it and output the result as a string?

29th Jun 2017, 6:18 AM
Flandre Scarlet
Flandre Scarlet - avatar
1 Answer
+ 1
totally possible. First, write a tokenizer that spews out the numbers, arrows and nothing else. Avoid decimals for the first version. From the tokenizer's output, the parser will take over. Our grammar is quite simple here. number [ [^+] number]* is all for now. once the parser clears the input, evaluate, call to string on it, and print it out! simples
29th Jun 2017, 7:42 AM
Venkatesh Pitta
Venkatesh Pitta - avatar