ใช้งานการให้แสงเสียง / คำบรรยายโดยไม่ใช้ '^'


28

ความท้าทาย

ติดตั้งtetration (aka Power Tower หรือ Hyperexponentiation) ด้วยจำนวนอักขระน้อยที่สุด

เงื่อนไข

  • อย่าใช้อำนาจ 'ผู้ประกอบการหรือเทียบเท่า (เช่นpow(x,y), x^y, x**yฯลฯ )
  • อินพุตที่ได้รับเป็น: x y(คั่นด้วยช่องว่าง)
  • xมีการอธิบายด้วยตัวเองyครั้ง
  • วิธีการของคุณจะต้องสามารถคำนวณได้อย่างน้อย4 3(4 exponentiated ด้วยตัวเอง 3 ครั้ง)

เกณฑ์การให้คะแนน

  • ชนะคะแนนต่ำสุด: (จำนวนตัวอักษร)
  • การหักโบนัสหากคุณไม่ได้ใช้ตัวดำเนินการคูณ (-5 คะแนน)
  • ไม่มีข้อกำหนดด้านความเร็ว / หน่วยความจำ ใช้เวลานานเท่าที่คุณต้องการ

ตัวอย่าง

x, 0 -> 1

2, 2 -> 2^2 = 4

2, 4 -> 2^(2^(2^2)) = 65536

4, 3 -> 4^(4^4) = 4^256 = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096

เปิดให้คำแนะนำ / แก้ไข / คำถาม


4
การเปลี่ยนแปลงหนึ่งอย่างที่ฉันคิดว่าสำคัญคือการแทนที่ "* โอเปอเรเตอร์" ด้วย "โอเปอเรเตอร์การคูณ" ใน GolfScript *เป็นการคูณในบริบทบางอย่าง แต่ก็ยังเป็นตัวดำเนินการวนรอบอย่างง่าย:{block}N*เทียบเท่ากับ for(i=0;i<N;i++){block}C-สไตล์ กรณีขอบที่ยุ่งยากคือการคูณสตริง / อาร์เรย์ ( 'a'3*ให้'aaa') แต่นั่นไม่น่าเป็นปัญหาเนื่องจากอาร์เรย์ของ4***3องค์ประกอบจะล้น RAM
Peter Taylor

3
นอกจากนี้ยังควรเพิ่มการทดสอบสำหรับเคสตัวเครื่องx 0=> 1. โซลูชันดั้งเดิมของฉันไม่รองรับเคสนั้น
Peter Taylor

3
บทลงโทษสำหรับการใช้การคูณนั้นต่ำเกินไป (: = โบนัสสำหรับการไม่ใช้) ฉันทำวิธีแก้ปัญหาที่ไม่ได้ใช้และต้องแทนที่มันเพื่อหลีกเลี่ยงการล้นสแต็คและได้รับชัยชนะ 7 ถ่านสำหรับการสูญเสียโบนัส 5 ถ่าน
ผู้ใช้ที่ไม่รู้จัก

2
@EngineerToast ฉันโพสต์กอล์ฟนี้ 4 ปีก่อนที่คุณจะเชื่อมโยง ...
MrZander

2
เงื่อนไขและการให้คะแนนนั้นค่อนข้างแปลก คุณไม่อนุญาตให้ใช้การดำเนินการด้านพลังงานหรือไม่? หรือคุณอนุญาตให้พวกเขา แต่พวกเขาเป็นโบนัสจุด +10?
ศิลปะที่สวยงามเพียง

คำตอบ:


16

J, คะแนน 7 (12 ตัวอักษร - 5 คะแนนเพื่อหลีกเลี่ยงการคูณ)

+/@$/@$~/@$~

การใช้งาน:

   4 +/@$/@$~/@$~ 3
1.34078e154
t=.+/@$/@$~/@$~  NB. define a function
   4 t 3
1.34078e154
   2 t 2
4

เพียงไม่กี่เท่าซ้อนกัน:

  • ใช้การคูณมันจะเป็น */@$~/@$~
  • การใช้พลังงานมันจะเป็น^/@$~ที่ที่$~สร้างอาเรย์/เป็นฟังก์ชั่นการพับ

ทำได้ดีมาก (แผ่น)
Gareth

@ Gareth ขอบคุณ แต่นั่นpadหมายความว่ายังไงเหรอ? ขออภัยภาษาอังกฤษไม่ใช่ภาษาแม่ของฉัน
defhlt

5
ข้อความของฉันสั้นเกินไปดังนั้นฉันจึงต้องถอดมันออก :-)
Gareth

คุณจะได้รับการคุมขังเพียงแค่ให้อีกหนึ่งอย่าง@$~ในการรวมกันได้ไหม
โจนาห์

@Jonah คุณต้องการ/แต่ใช่ คุณแค่พับหลาย ๆ ครั้งตามที่ต้องการผ่านฟังก์ชั่นการพับซ้อน
HyperNeutrino

15

Haskell, 87 85 - 5 == 80 82

import Data.List
t x=genericLength.(iterate(sequence.map(const$replicate x[]))[[]]!!)

ไม่ใช้การยกกำลังการคูณหรือการเพิ่ม (!) เพียงแค่แสดงการดำเนินการ สาธิต:

Prelude> :m +Data.List
Prelude Data.List> let t x=genericLength.(iterate(sequence.map(const$replicate x[]))[[]]!!)
Prelude Data.List> t 2 2
4
Prelude Data.List> t 2 4
65536
Prelude Data.List> t 4 3

...
อืม ... คุณไม่ได้พูดอะไรเกี่ยวกับประสิทธิภาพหรือความทรงจำใช่มั้ย แต่ถ้าให้พันล้านปีพอและ RAM บางเพตาไบต์สิ่งนี้จะยังคงให้ผลลัพธ์ที่ถูกต้อง (ความยาวทั่วไปสามารถใช้ bigInt เพื่อนับความยาวของรายการ)


1
ฉันเชื่อว่าคุณจะมีคำตอบให้ฉันภายใน 3012? ;)
MrZander

6
ฉันต้องการความช่วยเหลือจากกฎของมัวร์ แต่นั่นอาจทำให้ฉันได้
หยุดที่จะเปิดล็อค

12

GolfScript, 15 18 ตัวอักษร

~])*1\+{[]+*{*}*}*

ใช่หนึ่งใน*นั้นคือโอเปอเรเตอร์การคูณ (แบบฝึกหัด: อันไหน?) ดังนั้นฉันจึงไม่มีสิทธิ์ได้รับโบนัสถ่าน 5 ตัว ยังคงเป็นเพียงแค่เพิ่งจะสั้นกว่าการแก้ปัญหาของปีเตอร์

รุ่น 15-char รุ่นก่อนหน้านี้เป็นอย่างอื่นเหมือนกัน แต่จะไม่มีเอาต์พุตเมื่ออาร์กิวเมนต์ที่สองคือ 0 ขอบคุณที่ res สำหรับการระบุจุดบกพร่อง

~])*{[]+*{*}*}*

"2 3" ~])*{[]+*{*}*}*นี้ผลิตข้อผิดพลาดร้ายแรงเช่นกับ
res

@res จะสร้างคำตอบที่ถูกต้องสำหรับฉัน
Peter Taylor

@res: สมมติว่าไม่มีอะไรอื่นในสแต็ก แต่อินพุต หากคุณต้องการให้อินพุตในบรรทัดเหมือนในตัวอย่างของคุณใช้ครั้งแรก;เพื่อลบสตริงอินพุตจริงที่ล่ามวางบนสแต็กเมื่อเริ่มต้น หรือเพียงเติม[รหัสa : ทั้งคู่;"2 3" ~])*{[]+*{*}*}*และ"2 3" [~])*{[]+*{*}*}*ใช้ได้ดีสำหรับฉัน
Ilmari Karonen

(+1) ขอบคุณ! รูปแบบเหล่านั้นทำงานและไขปริศนาให้ฉันได้ กวดวิชากล่าวว่า "คุณไม่จำเป็นต้องป้อนข้อมูลในท่อ แต่ถ้าคุณทำไม่ได้ก็จะไม่พร้อมในการป้อนข้อมูลแทนก็จะถือว่ามีการป้อนข้อมูลที่ไม่มี ." ดังนั้นฉันจึงใช้แค่ruby golfscript.rb my_script.gsบรรทัดคำสั่งโดยไม่รู้ว่ามันทำให้บางสิ่งบางอย่าง ("" ชัด) อยู่ในสแต็กก่อนที่สคริปต์จะทำงาน - ซึ่งบางครั้งก็ใช้งานได้ (ยังมีecho 2 3 | ruby golfscript.rb my_script.gsโปรแกรมของคุณไม่ทำงานตามที่ได้รับ.)
res


10

J, 16 19 12 ตัวอักษร

*/@$~/1,~$~/

หรือเป็นคำกริยา (17 ตัวอักษร):

h=:[:*/@$~/1,~$~/

การใช้งาน:

   h 2 4
65536

หรือการป้อนข้อมูลจากแป้นพิมพ์ ( 24 27 20 ตัวอักษร):

*/@$~/1,~$~/".1!:1]1

ด้วยขอบคุณFUZxxl ที่ชี้ให้เห็นถึงความโง่เขลาของฉัน :-)

คำอธิบาย:

J อ่านจากขวาไปซ้ายดังนั้นการใช้2 4:

/ใช้เพื่อแทรกคำกริยา$~ระหว่างรายการแต่ละคู่ในรายการ $~ใช้เวลารายการด้านซ้ายและรูปร่างมัน$ใช้รายการที่เหมาะสม (เช่น~หลีขัดแย้ง) - ดังนั้นนี้จะเทียบเท่ากับ4 $ 2ที่ช่วยให้คุณรายการของ2s 2 2 2 2ซึ่งเป็นสี่รายการยาว

ตอนนี้เราผนวก 1 เข้าไปในรายการ1,~แล้วทำสิ่งเดียวกันอีกครั้ง /ใส่กริยา*/@$~ระหว่างแต่ละรายการในรายการ คำกริยานี้เริ่มต้นในลักษณะเดียวกัน$~แต่คราวนี้มัน/แทรก*ระหว่างแต่ละรายการของรายการที่สร้างขึ้นใหม่ @เพียงแค่ทำให้แน่ใจว่า*/@$~การทำงานเป็นหนึ่งในคำกริยาแทนของทั้งสอง สิ่งนี้ให้2คูณด้วยเวลามากพอที่จะเทียบเท่า2^4ได้

หน้าคำศัพท์ของ J - ฉันพบว่าการแก้ปัญหาด้วย J fun เพียงเพราะวิธีที่แตกต่างที่บางครั้งมันก็ทำสิ่งต่าง ๆ

การเพิ่มการวนซ้ำหนึ่งครั้งเพื่อลบ*ผู้ปฏิบัติงานมี 2 ปัญหา

  • มันออกมาที่ 17 ตัวอักษร ( +/@$~/,@$~/1,~$~/) ซึ่งถึงแม้จะมีโบนัส -5 นานเกินไป
  • It runs out of memory if the number gets too large so doesn't meet the requirement of being able to calculate 4 3

Could you provide an explanation? This looks interesting.
MrZander

@MrZander I've edited my answer to add an explanation.
Gareth

Not sure if I have a better understanding or more confusion, but thanks haha.
MrZander

The explanation implies that the whole thing is doing exponentiation rather than tetration. Which of us is missing something?
Peter Taylor

@PeterTaylor I suspect my explanation is not very clear. If it was doing tetration I would have just used ^/]$[ which creates the list 2 2 2 2 and sticks the exponentiation operator between them. What this is doing is going a step further and doing the exponentiation by repeated multiplication.
Gareth

8

GolfScript (24 chars - 5 = 19 points)

~\1{1{0{+}?}?}{@\+@*}:?~

is insanely slow.

(or 20 chars)

~\1{1{*}?}{@\+@*}:?~

is much faster.


2
Since GolfScript is a Ruby program, we can test on ideone :) ideone.com/GTIfP. I've also emailed ideone suggesting they add support for GolfScript.
mellamokb

@mellamokb, it'll be nice if they do add it, but I'm not too optimistic because their stated policy is to add languages which are supported by their distro.
Peter Taylor

I read that too... but since they support Ruby, and GolfScript is just a Ruby program, it should be easy :) Just create a bash script that passes in the parameters.
mellamokb


6

Python, 70

This uses nested eval calls, eventually producing a string "a*a*a*a...*a" which gets evaluated. Almost half of the score is wasted on getting the arguments... though I've noticed that a few other solutions don't bother with that.

a,b=map(int,raw_input().split())
exec"eval('*'.join('a'*"*b+'1'+'))'*b

If we assume the arguments are comma sepearated, you could use input() or use eval(raw_input()) Cheers
st0le

1
@st0le, please read the question
boothby

Nice one. The second line can be golfed even more: exec"eval('a*'*"*b+'1'+"+'1')"*b
flornquake

@flornquake good catch! thanks!
boothby

4

Scala:110

type B=BigInt
def r(a:B,b:B,f:(B,B)=>B):B=if(b>1)f(a,r(a,b-1,f))else a
def h(a:B,b:B)=r(a,b,r(_,_,r(_,_,(_+_))))

ungolfed:

type B=BigInt
def recursive (a:B, b:B, f:(B,B)=>B): B = 
  if (b>1) f (a, recursive (a, b-1, f)) 
  else a
recursive (2, 3, recursive (_, _, recursive (_, _, (_ + _))))

explanation:

type B=BigInt
def p (a:B, b:B):B = a+b
def m (a:B, b:B):B = if (b>1) p (a, m (a, b-1)) else a
def h (a:B, b:B):B = if (b>1) m (a, h (a, b-1)) else a
def t (a:B, b:B):B = if (b>1) h (a, t (a, b-1)) else a

plus, mul, high(:=pow), tetration all work in the same manner. The common pattern can be extracted as recursive method, which takes two BigInts and a basic function:

def r (a:B, b:B, f:(B,B)=>B):B = 
  if (b>1) f(a, r(a, b-1, f)) else a
r (4, 3, r (_,_, r(_,_, (_+_))))

The underlines are placeholder for something which gets called in this sequence, for example the addition plus(a,b)=(a+b); therefore (+) is a function which takes two arguments and adds them (a+b).

unfortunately, I get issues with the stack size. It works for small values for 4 (for example: 2) or if I reduce the depth for one step:

def h(a:B,b:B)=r(a,b,r(_,_,(_*_))) // size -7, penalty + 5
def h(a:B,b:B)=r(a,b,r(_,_,r(_,_,(_+_)))) 

The original code is 112 characters and would score, if valid, 107. Maybe I find out how to increase the stack.

The expanded algorithm can be transformed to tailrecursive calls:

type B=BigInt
def p(a:B,b:B):B=a+b
import annotation._
@tailrec
def m(a:B,b:B,c:B=0):B=if(b>0)m(a,b-1,p(a,c))else c
@tailrec
def h(a:B,b:B,c:B=1):B=if(b>0)h(a,b-1,m(a,c))else c
@tailrec
def t(a:B,b:B,c:B=1):B=if(b>0)t(a,b-1,h(a,c))else c

The tailrecursive call is longer than the original method, but didn't raise a stackoverflow in the long version - however it doesn't yield a result in reasonable time. t(2,4) is fine, but t(3,3) already was stopped by me after 5 min. However, it is very elegant, isn't it?

// 124 = 119-5 bonus
type B=BigInt
def r(a:B,b:B,c:B,f:(B,B)=>B):B=if(b>0)r(a,b-1,f(a,c),f)else c
def t(a:B,b:B)=r(a,b,1,r(_,_,1,r(_,_,0,(_+_))))

And now the same as above: use stinky multiplication (we even profit while rejecting the bonus of 5, because we save 7 characters: win=4 chars:)

// 115 without bonus
type B=BigInt
def r(a:B,b:B,c:B,f:(B,B)=>B):B=if(b>0)r(a,b-1,f(a,c),f)else c
def t(a:B,b:B)=r(a,b,1,r(_,_,1,(_*_)))

invocation:

timed ("t(4,3)")(t(4,3)) 
t(4,3): 1
scala> t(4,3)
res89: B = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096

runtime: 1ms.


4

Br**nfuck, 128-5=123 bytes

+<<+<<,<,[>[>+>>+<<<-]>[<+>-]>[>[>>+>+<<<-]>>>[<<<+>>>-]<<[>[>+>+<<-]>>[<<+>>-]<<<-]>[-]>[<<+>>-]<<<<-]>>[<<+>>-]+<[-]<<<<-]>>>.

Input is in the form of characters with code points of the numbers desired as inputs. Output is the same.

An explanation is coming when I have the time below. Do I get bonus points for not using exponentiation, multiplication, OR even addition?

Cell 3 (0-indexed) is the running total x.
This calculates the nth tetration of a.

+<<+<<,<,                                       Initialize tape with [n, a, 0, 1, 0, 1]
[                                               While n:
  >[>+>>+<<<-]>[<+>-]                             Copy a 3 cells to right: [n, a, 0, x, a, 1]
  >[                                              While x:
    >[>>+>+<<<-]>>>[<<<+>>>-]                       Copy a 2 cells to right: [n, a, 0, x, a, 1, a, 0]
    <<[>[>+>+<<-]>>[<<+>>-]<<<-]                    Cell 7 = prod(cell 5, cell 6)
    >[-]>[<<+>>-]<<<<-]                             Move this value to cell 5. End while.
  >>[<<+>>-]+<[-]<<<<-]                           Update x to result of exponentiation. End while.
>>>.                                            Print the result!

This works (tested) for x 0, 0 x, x 1, 1 x, x 2, 2 3, and 2 4. I tried 3 3, but it ran for several hours without finishing (in my Java implementation—probably not optimal) (EDIT: in @Timwi's EsotericIDE [It's great! Y'all should try it] as well. No luck.). In theory, this works up to the cell size of the specific implementation.


1
"Br**nfuck" Yes "brain" is a very offensive word xD. sorry I needed to
FireCubez

3

Python, 161 - 5 (no * operator) = 156

r=xrange
def m(x,y):
 i=0
 for n in r(y):i+=x
 return i
def e(x,y):
 i=1
 for n in r(1,y+1):i=m(i,x)
 return i
def t(x,y):
 i=1
 for n in r(y):i=e(x,i)
 return i

invoke:

t(2, 4)

1
Is multiplication by iterated addition really fast enough to evaluate 4***3?!
Peter Taylor

2
@PeterTaylor yes? it completes in less than a second for me
Blazer

Wow. The equivalent GolfScript version takes aaaaaaages.
Peter Taylor

As in, I've left it running overnight and it still hasn't finished.
Peter Taylor

1
Six years later, you can also save some bytes by replacing your m function with m=lambda x,y:sum(x for _ in r(y))
Jack Brounstein


3

Mathematica, 40 33

This doesn't quite conform to the rules but it is not in contention for the shortest code anyway, and I hope that it will be of interest to someone.

m@f_:=Fold[f,1,#2~Table~{#}]&;

m[m@Sum]

This builds a "tetration" function when it is run, but the arguments must be given in reverse order. Example:

m[m@Sum][3, 4]

1340780792994259709957402499820584612747936582059239337772356144372176 4030073546976801874298166903427690031858186486050853753882811946569946 433649006084096


Would you explain the code? Or display results on symbols rather than numbers? I notice that Fold[g, 1, #2~Table~{#}] &[3, 4] will produce g[g[g[1, 4], 4], 4] for instance.
DavidC

@David m[Times] produces Fold[Times, 1, Table[#2, {#1}]] &, which is a power function: m[Times][5, x] ---> x^5; the same method is used for this new power function to produce a tetration function. Logically one could start with Plus but that fails almost immediately.
Mr.Wizard

To eliminate Times, try this: t[h_, n_] := Sum[h, {i, n}]. Then run m[m@t][3, 4].
DavidC

@David, yes, that should work, but not for Code-Golf. ;-) (BTW you could write Sum[h, n].)
Mr.Wizard

Look at the scoring rules. You save 9 points by not using Times. The total score is still not better than yours but getting closer.
DavidC

3

Haskell:  58  51 chars, with or without multiplication.

i f x 1=x;i f x n=f$i f x$n-1
t=i(\o n->i(o n)n)(+)4

Ungolfed:

bump op n a = iterate (op n) n !! (fromIntegral $ a-1)
tetrate = iterate bump (+) !! 3

Shorter definition comes from inlining “bump”, and defining a custom version of “iterate”. Unfortunately the result is impossibly inefficient, but starting with (*) instead of (+) gives decent speed. In ghci:

Prelude> let i f x 1=x;i f x n=f$i f x$n-1
(0.00 secs, 1564024 bytes)
Prelude> let t=i(\o n->i(o n)n)(*)3
(0.00 secs, 1076200 bytes)
Prelude> t 4 3
13407807929942597099574024998205846127479365820592393377723561443721764030073546
976801874298166903427690031858186486050853753882811946569946433649006084096
(0.01 secs, 1081720 bytes)


2

Python, 112 chars

The numbers should be the 1st and 2nd argument: python this.py 4 3
** operator not used.
* used. It's quite trivial to implement, exactly like **, but costs more than 5 chars.

import sys
p=lambda y:y and x*p(y-1)or 1
t=lambda y:y>1 and p(t(y-1))or x
x,y=map(long,sys.argv[1:])
print t(y)

How do I use the code to compute 4 3? And, just of curiosity: Have you tried to implement * that way, and to compute 4 3 then?
user unknown

@userunknown, Input is by parameters. I added an explanation to the answer. I didn't try to add the * implementation, I believe the recursion depth would be too large for 4 3.
ugoren

2

C, 117 105 99 chars

EDIT: Merged the two functions p and r into one, saving some chars.
Of 99 chars, 52 do the actual calculation (including variable definitions). The other 47 are for handling input and output.
BUG: Badly handles powers of 0 (e.g. 0 2). Should find a minimum cost fix. This isn't a bug, I forgot that 0 2 is undefined.

Successfully handles 4 3, and even gives an exact result. However, can be inaccurate for some smaller numbers.
Prints the number with a trailing .000000.

x,y,z;
double R(){return--y?!z?y=R(),R(z=1):x*R():x;}
main(){
    scanf("%d%d",&x,&y);
    printf("%f\n",R());
}

Looks like 118 chars to me: ideone.com/9D5SU
mellamokb

Testing this with 4 3 is only accurate to about 18 places, double doesn't have nearly enough precision to support an exact representation.
Sir_Lagsalot

@Sir_Lagsalot, double has more than enough precision for 4^256. It only has one significant digit.
ugoren

Ah good point, I wasn't thinking in binary. Does it actually print out the exact value for you? It gets truncated after the first 18 or so decimal digits on my machine, but I'm willing to accept that's system specific.
Sir_Lagsalot

@Sir_Lagsalot: See the ideone link I provided. It prints out the whole number.
mellamokb

2

Factor, 187 characters

USING: eval io kernel locals math prettyprint sequences ;
IN: g
:: c ( y x o! -- v )
o 0 = [ x y * ] [ o 1 - o!
y x <repetition> 1 [ o c ] reduce ] if ;
contents eval( -- x y ) swap 2 c .

Before golf:

USING: eval io kernel locals math prettyprint sequences ;
IN: script

! Calculate by opcode:
!   0 => x * y, multiplication
!   1 => x ^ y, exponentiation
!   2 => x ^^ y, tetration
:: calculate ( y x opcode! -- value )
    opcode 0 = [
        x y *
    ] [
        ! Decrement the opcode. Tetration is repeated exponentiation,
        ! and exponentiation is repeated multiplication.
        opcode 1 - opcode!

        ! Do right-associative reduction. The pattern is
        !   seq reverse 1 [ swap ^ ] reduce
        ! but a repetition equals its own reverse, and 'calculate'
        ! already swaps its inputs.
        y x <repetition> 1 [ opcode calculate ] reduce
    ] if ;

contents eval( -- x y )         ! Read input.
swap 2 calculate .              ! Calculate tetration. Print result.

I did not remove the multiplication operator *. If I did so, then I would need to add some logic expressing that the sum of an empty sequence is 0, not 1. This extra logic would cost more than the -5 bonus.


Rule breaker, 124 + 10 = 134 characters

USING: eval kernel math.functions prettyprint sequences ;
contents eval( -- x y ) swap <repetition> 1 [ swap ^ ] reduce .

This program has a lower score, but the exponentiation operator ^ breaks the rules. The rules say "(# of characters) + (10 * (# of 'power' operators))", so I applied the +10 penalty. However, the rules also say "Don't use the 'power' operator", so any program taking this penalty does break the rules. Therefore, this program of 134 characters is not a correct answer, and I must present my longer program of 187 characters as my answer.


2

Haskell 110 - 5 = 105

Tetration Peano Style. This is the most insanely slow solution possible, just a warning, but also avoids even addition.

data N=Z|S N
a&+Z=a
a&+S b=S$a&+b
_&*Z=Z
a&*S b=a&+(a&*b)
_&^Z=S Z
a&^S b=a&*(a&^b)
_&>Z=S Z
a&>S b=a&^(a&>b)

This relies on you having the patience to type out Peano numbers (and won't show the answer, If you actually want to run it, add these few lines (90 chars):

f 0=Z
f a=S$f$a-1
t Z=0
t(S a)=1+t a
main=interact$show.f.(\[x,y]->x&>y).map(f.read).words


2

Lua: 133 chars, multiplication-less

a,b=io.read():match"(%d+) (%d+)"a,b,ba=a+0,b+0,a for i=1,b-1 do o=1 for i=1,a do o=o+o for i=1,ba-b do o=o+o end end a=o end print(o)

I was originally going to use string repetition hacks to do fake multiplication, but it likes to fail on large values. I could possibly use dynamic compilation and loadstring to make it smaller, but it's getting late here... I need sleep.

Entering "4 3" into stdin outputs:

1.3407807929943e+154

2

VBA, 90 Chars

*Perhaps the no multiplication bonus is not good enough. I think the no multiplication answer is much more interesting, but this is code golf, so it's not the best. Here's an answer without *, and a better (shorter, and better scoring) answer with it:

90 chars, no power operators, uses multiplication = 90

Sub c(x,y)
f=IIf(y,x,1):For l=2 To y:b=x:For j=2 To f:b=b*x:Next:f=b:Next:MsgBox f
End Sub

116 chars, no power operators, no multiplication bonus (-5) = 111

Sub c(x,y)
f=IIf(y,x,1):For l=2 To y:b=x:For j=2 To f:For i=1 To x:a=a+b:Next:b=a:a=0:Next:f=b:Next:MsgBox f
End Sub

NOTE: VBA has issues printing the number when the result is very large (i.e. 4, 3), but it does calculate correctly, so if, for example, you wanted to USE that number, you would be good to go. Also, even BIGGER numbers overflow (i.e. 3, 4).


2

Perl 6, 32 bytes

->\a,\b{(1,{[*] a xx$_}...*)[b]}

Try it online!

(1, { [*] a xx $_ } ... *) is a lazy sequence that generates the power tower, each element being the a list which consists of the first input parameter a replicated (xx) a number of times equal to the previous element ($_), that list then being reduced with multiplication ([*]). From that sequence we simply pluck out the b-th element.


2

Lambda calculus, 10-5

(using Church encoding and De Bruijn indeces)
λλ(1λ13)λ1

Explanation

Without De Bruijn indeces: λa,b.(b λc.ca)λc.c:

λa,b.                                                 define the anonymous function f(a,b)=
     (b                                                apply the following function b times
        λc.                                                    the anonymous function g(c)=
           ca)                 apply c to a because of church encoding this is equal to a^c
              λc.c                              the identity function, 1 in church encoding

If you define exp_a(x)=a^x this program defines a↑↑b=exp_a^b(1) where ^b denotes function itteration.

I'm not sure if this is allowed because ca is technically equivalent to a^c how ever it is not a real built-in and only a side effect of the way integers are encoded in lambda calculus.


Hm, is there an interpreter so that I can try this? If there's no implementation of a language, then you can't use it to solve challenges here. Languages are based on their implementations here.
Erik the Outgolfer

1

Javascript: 116 chars

function t(i){y=i.split(' ');a=y[0];b=y[1];return+b&&p(a,t(a+' '+(b-1)))||1}function p(a,b){return+b&&a*p(a,b-1)||1}

t('4 3') Outputs:

1.3407807929942597e+154

1

Python (111) (113) no *

r=lambda x,y:(x for _ in range(y));t=lambda x,y:reduce(lambda y,x:reduce(lambda x,y:sum(r(x,y)),r(x,y)),r(x,y),1)

6***3 - 36k digits))

Upd: Have to add initial value, to fit t(X,0)=1


Impressive, how long did the 36k take?
MrZander

1
9.375 seconds including print.
Ev_genus

1

Haskell: 88-5 chars without multiplication, 59 chars with multiplication

Without multiplication:

h x y=foldr(\x y->foldl(\x y->foldl(+)0(replicate x y))1(replicate y x))1(replicate y x)

There are probably ways that I could golf that down a little.

With multiplication:

h x y=foldr(\x y->foldl(*)1(replicate y x))1(replicate y x)

And finally, the ungolfed program:

mult x y = foldl (+) 0 (replicate x y)
expo x y = foldl (mult) 1 (replicate y x)
h x y = foldr (expo) 1 (replicate y x)

This is probably the simplest way to do this problem, which is defining multiplication as repeated addition, exponentiation as repeated multiplication, and tetration as repeated exponentiation.



1

Common Lisp, 85 chars

(lambda(b c)(let((r b)u)(dotimes(c c r)(setf u 1 r(dotimes(c b u)(setf u(* u r)))))))

I tried doing the multiplications through repeated addition, but it was way more than 5 characters. Same thing with macrolets, the declarations were not worth the gains.

Another solution, inspired by boothby's python solution. It's 1 character less than the above solution.

(lambda(a b)(eval`(*,@(loop for x below b nconc(loop for x below a nconc`(,a,a))))))



1

R, 71 - 5 = 66 bytes

function(x,y,b=x){for(i in 2:y)b=cumprod(z<-rep(x,b))[sum(z|1)];cat(b)}

Try it online!

-5 for avoiding *, which was harder than I expected. It explodes really fast and won't work (unless it had more memory) but it satisfies all necessary criteria.

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.