The Pragmatic Programmer

Tulisan iseng kalo ada waktu.
See also: Other Geeks@INDC

Language Contest

I have two numbers:

a. 138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103

b. 138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103

What is the result of their multiplication?

Well, finding the solution using javascript is easy:

<html>
<body>
<script language="javascript">
  var o = 138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103;
  var c = 138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103;
  alert(c*o);
</script>
</body>
</html>

Try that with your language! :P

Share this post: | | | |

Comments

Maximilian Haru Raditya said:

Well, using C# on top of .NET Framework 2.0 and I got the result as follows:

19069353766370892068548154502433793378901751241996600205409773900885066838681547194268166908566896219162417634349707980712502825754769659443011788250398795111604804954440073376226076848408579241488071163858733831686530292084284639347500590196772232353144609

Yup, you're right. It's that easy. Thanks for pointing out!

# July 7, 2007 11:57 PM

cahnom said:

Using google calculator

http://www.google.co.id/search?hl=id&q=138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103*138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103

Hasilnya

1.90693538 × 10^256

# July 8, 2007 11:14 AM

cahnom said:

Mas Maximilian Haru Raditya, bisa dapet angka sepanjang itu pake tipe data apa ya? Kalo .NET 2.0 tipe data bilangan bulat terpanjang adalah ulong (System.UInt64).  Kalo pake Visual Studio Orcas baru ada tipe data baru yaitu BigInteger (http://msdn.microsoft.com/msdnmag/issues/07/04/CLRInsideOut/#S5) yang panjangnya tak terbatas (dibatasi oleh memori yang tersedia).

Jika pake .NET 2.0 bisa share code-nya dong!

# July 8, 2007 4:46 PM

norman said:

Maksud pertanyaan-nya apa sih?

Cuma mau result kayak gini doang?

19069353766370892068548154502433793378901751241996600205409773900885066838681547194268166908566896219162417634349707980712502825754769659443011788250398795111604804954440073376226076848408579241488071163858733831686530292084284639347500590196772232353144609

Atau?

# July 9, 2007 1:13 PM

norman said:

Oh, lupa, code-nya:

In Mathematica, code-nya:

In[1]:=

138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103

*

138091830918309183190839018390182309183901890381290389103810239012839083091809381902830912839012830912839018230918290381092389103

Result-nya:

Out[1]:=

190693537663708920685481545024337933789017512419966002054097739008850668386815\

471942681669085668962191624176343497079807125028257547696594430117882503987951\

116048049544400733762260768484085792414880711638587338316865302920842846393475\

00590196772232353144609

Saya potong2, biar keliatan semua di blog ini.

# July 9, 2007 1:20 PM

Risman Adnan Mattotorang said:

If a and b is equal number let say x, this is a quadratic problem, how you can measure the area of a square with lenght x (N digits). With direct multiplication you need a type with at least N*2. If N is big, no type can accomodate. Good problem right?

Maybe we can expand the problem:

- Optimize in term space and speed :)

# July 9, 2007 2:11 PM

Maximilian Haru Raditya said:

To Mas Masykur (atau punya nama panggilan lain ya?):

Point Anda tersebut sesuai dengan posting baru Anda mengenai BigInteger di .NET 3.5.

Code-nya bisa Anda lihat sendiri di sini:

http://www.codeproject.com/csharp/BigInteger.asp

BTW, panggil saya Max saja dan saya sudah mencoba Google Calculator kok tetep tidak keluar hasilnya ya?

Hope helps and cheers! :)

# July 10, 2007 1:48 PM

cahnom said:

Lho bukannya Anda sebutkan "using C# on top of .NET Framework 2.0". Kalo .NET 3.5 itu mah bisa pake BigInteger, yang saya tanyakan bagaimana melakukannya di .NET 2.0.

Untuk melakukan perhitungan di google calculator, tinggal masukkan ekspresi matematika di search-textbox-nya google. Contoh: masukkan 2*5, tekan [Search] dan hasil perhitungan akan ditampilkan di bawahnya (2 * 5 = 10).

# July 10, 2007 2:49 PM

Maximilian Haru Raditya said:

Nope, you've missed my point actually.

Hal ini relevan dengan posting Anda. Point-nya adalah BigInteger.

Di dalam .NET 3.5, BigInteger sudah built-in di dalam BCL. Sementara di .NET 2.0, Anda harus menggunakan kelas tambahan dari kode sumber yang saya tunjukkan di link di atas.

Jadi, pada prinsipnya (class) BigInteger itu hanya sebuah library saja. BigInteger tidak mesti jalan di atas CLR 3.5, tapi bisa jalan juga di atas CLR 2.0 (atau bahkan CLR 1.0/1.1) dan yang Anda butuhkan adalah library tambahannya. That's my point is all about: menggunakan C# di atas .NET 2.0 (ditambah library tambahan).

I hope I made myself clear about this and thanks for the Google tips!

# July 10, 2007 5:46 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 
Are you human?:  


Enter the numbers above: