Jumat, 13 Maret 2009

Contoh Lisp coding (Terbesar dari 49 bilangan)

Algoritma
-------------------------------------------------------------------------------------
JUDUL : BILANGAN TERBESAR DARI 49 BILANGAN

DEFINISI DAN SPESIFIKASI :
big : 49 bilangan integer
{big (a b c d e f g h i j a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 a2 b2 c2 d2 e2 f2 g2 h2 i2 j2
a3 b3 c3 d3 e3 f3 g3 h3 i3 j3 k l m n o p q r s) menghasilkan maksimum dari 49 bilangan}

REALISASI :
let ((big (max a b c d e f g h i j a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 a2 b2 c2 d2 e2 f2 g2 h2 i2 j2
a3 b3 c3 d3 e3 f3 g3 h3 i3 j3 k l m n o p q r s)))

APLIKASI :
TERBESAR (12 12 3 4 2 6 8 3 2 6 3 5 7 3 5 2 5 7 3 3 6 8 0 45 3 2 5 7 4 -2 4 6 2 4 6 3 3 5 7 8
3 2 6 8 4 99 77 34 43)
-------------------------------------------------------------------------------------

Coding
-------------------------------------------------------------------------------------

(defun terbesar (a b c d e f g h i j
a1 b1 c1 d1 e1 f1 g1 h1 i1 j1
a2 b2 c2 d2 e2 f2 g2 h2 i2 j2
a3 b3 c3 d3 e3 f3 g3 h3 i3 j3
k l m n o p q r s)
(let ((big (max a b c d e f g h i j
a1 b1 c1 d1 e1 f1 g1 h1 i1 j1
a2 b2 c2 d2 e2 f2 g2 h2 i2 j2
a3 b3 c3 d3 e3 f3 g3 h3 i3 j3
k l m n o p q r s)))
(format t "~A ~A" big big)))
-------------------------------------------------------------------------------------

Just one touch!!
dengan satu fungsi bisa menemukan bilangan terbesar dari 49 bilangan..
cara yang sangat simple..
mungkin masih ada yang lebih simple atau lebih ribet lagi..
cara lain untuk membuat max49 adalah dengan cara menentukan terbesar dari 2 bilangan baru kemudian empat bilangan dan seterusnya..
cukup panjang tapi lebih bagus dalam hal pembelajaran..

Tidak ada komentar:

Posting Komentar

how about this post??