Jumlah besar mana yang lebih besar?


22

Memasukkan

Integer a1, a2, a3, b1, b2, b3 masing-masing dalam kisaran 1 hingga 20.

Keluaran

True if a1^(a2^a3) > b1^(b2^b3) and False otherwise.

^ adalah eksponensial dalam pertanyaan ini.

Aturan

Ini adalah kode-golf. Kode Anda harus berakhir dengan benar dalam waktu 10 detik untuk setiap input yang valid pada PC desktop standar.

Anda dapat menampilkan apa pun yang Sejati untuk Benar dan apa pun yang Falsey untuk False.

Anda dapat mengasumsikan setiap input yang Anda suka asalkan ditentukan dalam jawaban dan selalu sama.

Untuk pertanyaan ini, kode Anda harus selalu benar. Itu seharusnya tidak gagal karena ketidakakuratan floating point. Karena jangkauan input yang terbatas ini seharusnya tidak terlalu sulit untuk dicapai.

Uji kasus

3^(4^5) > 5^(4^3)
1^(2^3) < 3^(2^1)
3^(6^5) < 5^(20^3)
20^(20^20) > 20^(20^19)
20^(20^20) == 20^(20^20)
2^2^20 > 2^20^2
2^3^12 == 8^3^11
1^20^20 == 1^1^1
1^1^1 == 1^20^20

Komentar bukan untuk diskusi panjang; percakapan ini telah dipindahkan ke obrolan .
DJMcMayhem

Jawaban:


16

Perl 6 , 31 29 byte

-2 byte terima kasih kepada Grimy

*.log10* * ***>*.log10* * ***

Cobalah online!

Percaya atau tidak, ini bukan esolang, bahkan jika itu sebagian besar terdiri dari tanda bintang. Ini menggunakan rumus Arnauld , dengan log10 bukan ln.


Saya percaya ini gagal 2^3^12 == 8^3^11.
Ørjan Johansen

@ ØrjanJohansen Ini harus diperbaiki sekarang. beri tahu saya jika gagal karena hal lain
Jo King


@ Terima kasih kotor! Aku berani bersumpah aku mencobanya ...
Jo King


6

05AB1E , 11 9 11 7 byte

.²Šm*`›

Pelabuhan @Arnauld 's JavaScript dan @digEmAll ' s R pendekatan (aku melihat mereka mengirim sekitar waktu yang sama)
-2 byte berkat @Emigna
2 byte sebagai bug-fix setelah @Arnauld 's dan @digEmAll jawaban' s terkandung kesalahan
-4 byte sekarang karena urutan input yang berbeda diizinkan setelah komentar @LuisMendo

Input [a1,b1], [a3,b3], [a2,b2]tiga dipisahkan input.

Cobalah secara online atau verifikasi semua kasus uji .

Penjelasan:

       # Take the logarithm with base 2 of the implicit [a1,b1]-input
  Š      # Triple-swap a,b,c to c,a,b with the implicit inputs
         #  The stack order is now: [log2(a1),log2(b1)], [a2,b2], [a3,b3]
   m     # Take the power, resulting in [a2**a3,b2**b3]
    *    # Multiply it with the log2-list, resulting in [log2(a1)*a2**a3,log2(b1)*b2**b3]
     `   # Push both values separated to the stack
        # And check if log2(a1)*a2**a3 is larger than log2(b1)*b2**b3
         # (after which the result is output implicitly)

1
Anda versi kedua dapat menjadi εć.²š] P` ›
Emigna

@ Emigna Ah bagus, saya sedang melihat pendekatan dengan ć, tetapi benar-benar lupa menggunakan š(tidak yakin mengapa sekarang saya melihatnya, haha). Terima kasih!
Kevin Cruijssen

Ini tampaknya salah (karena jawaban Arnauld salah sampai perbaikan terbaru).
Anush

@Anush Tetap dan 4 byte disimpan dengan mengambil input dalam urutan yang berbeda sekarang. :)
Kevin Cruijssen



3

J , 11 9 byte

>&(^.@^/)

Cobalah online!

Argumen diberikan sebagai daftar.

  • > apakah yang kiri lebih besar?
  • &(...) tetapi pertama-tama, ubah setiap argumen dengan demikian:
  • ^.@^/kurangi dari kanan ke kiri dengan eksponensial. Tetapi karena eksponensial biasa akan membatasi kesalahan bahkan untuk nomor yang diperluas, kami mengambil log dari kedua sisi


3

Python 3, 68 bytes

lambda a,b,c,d,e,f:log(a,2)*(b**c)>log(d,2)*(e**f)
from math import*

Try it online!

Port of @Arnualds answer, but with the base for log changed.


^ is called ** in Python. And with that changed, you won't be able to run all the OP's test cases.
Ørjan Johansen

Should be all fixed now, 66 bytes though.
Artemis supports Monica

I believe this fails for 2^3^12 == 8^3^11.
Ørjan Johansen

@ØrjanJohansen should be fixed
Artemis supports Monica

Seems like it. Apart from the logarithmic base change for the fix, this looks like Arnauld's method.
Ørjan Johansen

2

05AB1E, 13 bytes

Uses the method from Arnauld's JS answer

2F.²IIm*ˆ}¯`›

Try it online!


This doesn't terminate for a1=20, a2=20, a3=20.
Anush

1
@Anush: Seems to terminate in less than a second to me.
Emigna

you have to set all the variables to 20. See tio.run/##yy9OTMpM/f9f79Du3GK9Q6tzHzXs@v8/2shAB4xiuRBMAA
Anush

@Anush: Ah, you meant b1=b2=b3=20 ,yeah that doesn't terminate.
Emigna

1
@Anush: It is fixed now. Thanks for pointing out my mistake :)
Emigna

2

Excel, 28 bytes

=B1^C1*LOG(A1)>E1^F1*LOG(D1)

Excel implementation of the same formula already used.


My understanding is that Excel has 15 digits of precision, so there may be cases where rounding result in this returning the wrong answer.
Acccumulation

2

JavaScript, 51 bytes

f=(a,b,c,h,i,j)=>(l=Math.log)(a)*b**c-l(h)*i**j>1e-8

Surprisingly, the test cases doesn't show any floating-point error. I don't know if it ever does at this size.

This just compares the logarithm of the numbers.

Equality tolerance is equal to 1e-8.


Welcome to PPCG! Alas this does fail with my 2^3^12 == 8^3^11 test case. In fact your answer is very similar to the original answer by Arnauld (sadly deleted rather than fixed) that inspired most of those which failed it.
Ørjan Johansen

@Ørjan Johansen Moved l(h) to the right, and maybe it works now? Edit: Wait, it doesn't.
Naruyoko

Added equality tolerance 0.01.
Naruyoko

I did a quick search and a tolerance should work, but this is a bit too high. The highest you need to exclude is (5.820766091346741e-11,(8.0,3.0,11,2.0,3.0,12)) (my test case), and the lowest you need to include is (9.486076692724055e-4,(17.0,19.0,1,3.0,7.0,2)) (3^7^2 > 17^19^1.) So something like 1e-8 should be safely in the middle and the same byte length.
Ørjan Johansen

@Ørjan Johansen Ok, thanks!
Naruyoko

1

bc -l, 47 bytes

l(read())*read()^read()>l(read())*read()^read()

with the input read from STDIN, one integer per line.

bc is pretty fast; it handles a=b=c=d=e=f=1,000,000 in a little over a second on my laptop.


I love a bc answer! Just need one in bash now :)
Anush

1

C++ (gcc), 86 bytes

Thanks to @ØrjanJohansen for pointing out a flaw in this and @Ourous for giving a fix.

#import<cmath>
int a(int i[]){return pow(i[1],i[2])/pow(i[4],i[5])>log(i[3])/log(*i);}

Try it online!

Takes input as a 6-integer array. Returns 1 if abc>def, 0 otherwise.


The formula after taking log twice should be i[2]*log(i[1])+log(log(*i)). E.g. the current one will fail for 2^2^20 > 4^2^18.
Ørjan Johansen

@ØrjanJohansen: good catch! I guess I have to use the pow method then.
Neil A.

The alternate one has the 2^3^12 == 8^3^11 problem I've pointed out for others.
Ørjan Johansen

@ØrjanJohansen: well, I guess I'm using your fixed formula then.
Neil A.

Oh, I'm afraid that formula is only mathematically correct. It still has a floating point error problem, just with a different case, 2^3^20 == 8^3^19. In fact on average the power method fails for fewer, probably because it tends to multiply by powers of two exactly. Others have managed to make it work by just tweaking it slightly.
Ørjan Johansen

1

Jelly, 8 bytes

l⁵×*/}>/

Try it online!

Based on Arnauld’s JS answer. Expects as input [a1, b1] as left argument and [[a2, b2], [a3, b3]] as right argument.

Now changed to use log to the base 10 which as far as correctly handles all the possible inputs in the range specified. Thanks to Ørjan Johansen for finding the original problem!


1
I believe this fails for 2^3^12 == 8^3^11.
Ørjan Johansen

Your Python TIO is incorrect.. You have 8* instead of 8**. @ØrjanJohansen is indeed correct that 2**(3**12) > 8**(3**11) is falsey, since they are equal.
Kevin Cruijssen

@KevinCruijssen oops. Yes they are indeed equal. The reason the original two are marked as different relates to floating point error.
Nick Kennedy

1

TI-BASIC, 27 31 bytes

ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4

Input is a list of length 6 in Ans.
Outputs true if the first big number is greater than the second big number. Outputs false otherwise.

Examples:

{3,4,5,5,4,3
   {3 4 5 5 4 3}
prgmCDGF16
               1
{20,20,20,20,20,19       ;these two lines go off-screen
{20 20 20 20 20 19}
prgmCDGF16
               1
{3,6,5,5,20,3
  {3 6 5 5 20 3}
prgmCDGF16
               0

Explanation:

ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4   ;full program
                                                 ;elements of input denoted as:
                                                 ; {#1 #2 #3 #4 #5 #6}

ln(Ans(1))Ans(2)^Ans(3)                          ;calculate ln(#1)*(#2^#3)
                        Ans(5)^Ans(6)(ln(Ans(4   ;calculate (#5^#6)*ln(#4)
                       >                         ;is the first result greater than the
                                                 ; second result?
                                                 ; leave answer in "Ans"
                                                 ;implicit print of "Ans"

Note: TI-BASIC is a tokenized language. Character count does not equal byte count.


I’m not that familiar with TI-BASIC, but this seems to be log(x) × y × z rather than log(x) × y ^ z. This won’t necessarily lead to the same ordering as the original inequality.
Nick Kennedy

@NickKennedy Yes, you are correct about that! I'll update the post to account for this.
Tau

1

APL(NARS), chars 36, bytes 72

{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}

Here below the function z in (a b c )z(x y t) would return 1 if a^(b^c)>x^(y^t) else would return 0; test

  z←{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}
  3 4 5 z 5 4 3
1
  1 2 3 z 3 2 1
0
  3 6 5 z 5 20 3
0
  20 20 20 z 20 20 19
1
  20 20 20 z 20 20 20
0
  2 2 20 z 2 20 2
1
  2 3 12 z 8 3 11
0
  1 20 20 z 1 1 1
0
  1 1 1 z 1 20 20
0
  1 4 5 z 2 1 1
0

{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b} is the function p(a,b,c)=log(log(a))+c*log(b)=log(log(a^b^c)) and if aa=a^(b^c) with a,b,c >0 and a>1 bb=x^(y^t) with x,y,t >0 and x>1 than

aa>bb <=> log(log(a^b^c))>log(log(x^y^t))  <=>  p(a,b,c)>p(x,y,t)

There is a problem with the function p: When a is 1, log log 1 not exist so I choose to represent that with the number -1; when a=2 so log log a is a negative number but > -1 .

PS. Seen the function in its bigger set in which is defined

p(a,b,c)=log(log(a))+c*log(b)

appear range for a,b,c in 1..20 is too few... If one see when it overflow with log base 10, the range for a,b,c could be 1..10000000 or bigger for a 64 bit float type.

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.