Lisp

Published on February 2017 | Categories: Documents | Downloads: 52 | Comments: 0 | Views: 327
of 6
Download PDF   Embed   Report

Comments

Content

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PECAHAN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun typePemb(n)
(if(integerp n) t nil)
)
(defun typePeny(n)
(if(and (integerp n) (not (equal n 0))) t nil)
)
(defun makeP(x y)
(if (and (typePemb x) (typePeny y))(cons x (cons y nil)) nil)
)
(defun pemb(p)
(car p)
)
(defun peny(p)
(car (cdr p))
)
(defun addP(p1 p2)
(/ (+ (* (peny p2) (pemb p1)) (* (peny p1) (pemb p2))) (* (peny p1) (peny p2)))
)
(defun SubP(p1 p2)
(/ (- (* (peny p2) (pemb p1)) (* (peny p1) (pemb p2))) (* (peny p1) (peny p2)))
)
(defun mulP(p1 p2)
(/ (* (pemb p1)(pemb p2)) (* (peny p1) (peny p2)))
)
(defun divP(p1 p2)
(/ (* (pemb p1) (peny p2)) (* (peny p1) (pemb p2)))
)
(defun desimalP(p)
(/ (* (pemb p) 1.0) (* (peny p) 1.0))
)
(defun isEqP(p1 p2)
(if (= (* (pemb p1) (peny p2)) (* (pemb p2) (peny p1))) t
nil
)
)
(defun isLtP(p1 p2)
(if (< (* (pemb p1) (peny p2)) (* (pemb p2) (peny p1))) t
nil
)
)

(defun isGtP(p1 p2)
(if (> (* (pemb p1) (peny p2)) (* (pemb p2) (peny p1))) t
nil
)
)
(defun isP(p)
(not (integerp (/ (pemb p) (peny p))))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun typeD(n)
(if(and (integerp n) (>= n 1) (<= n 31)) t nil)
)
(defun typeM(n)
(if(and (integerp n) (>= n 1) (<= n 12)) t nil)
)
(defun typeY(n)
(if(and (integerp n) (> n 0)) t nil)
)
(defun typeDate(d m y)
(if (and (typeD d) (typeM m) (typeY y)) t nil)
)
(defun hari(d)
(car d)
)
(defun bulan(d)
(car (cdr d))
)
(defun tahun(d)
(car(cdr(cdr d)))
)
(defun makedate(d m y)
(if
(or
(and (and (integerp d) (>= d 1) (<= d 31))(or (= m 1) (= m 3) (= m 5) (= m 7) (= m 8) (=
m 10) (= m 12)))
(and (and (integerp d) (>= d 1) (<= d 30))(or (= m 4) (= m 6) (= m 9) (= m 11) ))
(and (= m 2)(and (=(mod y 4) 0) (not (= y 1900)))(and (integerp d) (>= d 1) (<= d 29)))
(and (= m 2)(not (and (=(mod y 4) 0) (not (= y 1900))))(and (integerp d) (>= d 1) (<= d
28)))
)

(cons d (cons m (cons y nil)))
nil
)
)
(defun IsEqD(d1 d2)
(if (and (= (hari d1) (hari d2)) (= (bulan d1) (bulan d2)) (= (tahun d1) (tahun d2))) t
nil
)
)
(defun isKabisat(d)
(and (=(mod (tahun d) 4) 0) (not (= (tahun d) 1900)))
)
(defun nextday(d)
(cond
((or (= (bulan d) 1) (= (bulan d) 3) (= (bulan d) 5) (= (bulan d) 7) (= (bulan d) 8) (= (bulan
d) 10))
(if (< (hari d) 31) (makedate (+ (hari d) 1) (bulan d) (tahun d))(makedate 1 (+ (bulan d) 1)
(tahun d)))
)
((or (= (bulan d) 4) (= (bulan d) 6) (= (bulan d) 9) (= (bulan d) 11) )
(if (< (hari d) 30) (makedate (+ (hari d) 1) (bulan d) (tahun d))(makedate 1 (+ (bulan d) 1)
(tahun d)))
)
((= (bulan d) 2)
(if (iskabisat d)
(if(< (hari d) 29) (makedate (+ (hari d) 1) (bulan d) (tahun d))(makedate 1 (+ (bulan d)
1) (tahun d)))
(if(< (hari d) 28) (makedate (+ (hari d) 1) (bulan d) (tahun d))(makedate 1 (+ (bulan d)
1) (tahun d)))
)
)
((= (bulan d) 12)
(if (< (hari d) 31) (makedate (+ (hari d) 1) (bulan d) (tahun d))(makedate 1 1 (+ (tahun d)
1)))
)
)
)
(defun yesterday(d)
(if (= (hari d) 1 )
(cond
((or (= (bulan d) 5 ) (= (bulan
(makedate 30 (- (bulan d) 1)
)
((or (= (bulan d) 2 ) (= (bulan
(makedate 31 (- (bulan d) 1)

d) 7 ) (= (bulan d) 8 ) (= (bulan d) 10 ) (= (bulan d) 12 ))
(tahun d))
d) 4 ) (= (bulan d) 6 ) (= (bulan d) 9 ) (= (bulan d) 11 ))
(tahun d))

)
((= (bulan d) 3)
(if (iskabisat d)
(makedate 29 2 (tahun d))
(makedate 28 2 (tahun d))
)
)
((= (bulan d) 1)
(makedate 31 12 (- (tahun d) 1))
)
)
(makedate (- (hari d) 1) (bulan d) (tahun d))
)
)
(defun harike1900(d)
(+
(cond
((=(bulan d)1) (hari d)
)
((=(bulan d)2) (+(hari d) 31 ))
((=(bulan d)3) (+(hari d) 59 ))
((=(bulan d)4) (+(hari d) 90 ))
((=(bulan d)5) (+(hari d) 120 ))
((=(bulan d)6) (+(hari d) 151 ))
((=(bulan d)7) (+(hari d) 181 ))
((=(bulan d)8) (+(hari d) 212 ))
((=(bulan d)9) (+(hari d) 243 ))
((=(bulan d)10) (+(hari d) 273 ))
((=(bulan d)11) (+(hari d) 304 ))
((=(bulan d)12) (+(hari d) 334 ))
)
(+ (* 365 (- (tahun d) 1900)) (truncate (/ (- (tahun d) 1901) 4))) ;1900 bukan kabisat
(if (and (integerp (/(tahun d) 4)) (> (bulan d) 2)) 1 0)
)
)
(defun nextNDate (d n)
(if (integerp n)
(if (= n 1) (nextday d)
(nextday (nextNDate d (- n 1) ))
)
nil
)
)
(defun isBefore(d1 d2)
(if
(< (harike1900 d1) (harike1900 d2))
t
nil
)

)
(defun isAfter(d1 d2)
(if
(> (harike1900 d1) (harike1900 d2))
t
nil
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; POINT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun absis(p)
(car p)
)
(defun ordinat(p)
(car (cdr p))
)
(defun makePoint(a b)
(cons a (cons b nil))
)
(defun kuadrat(x)
(* x x)
)
(defun jarak(p1 p2)
(sqrt (+ (kuadrat (- (absis p2) (absis p1))) (kuadrat (- (ordinat p2) (ordinat p1))) ))
)
(defun jaraknol(p1)
(sqrt (+ (kuadrat (absis p1)) (kuadrat (ordinat p1))))
)
(defun kuadran(p)
(cond
((and (> (absis p)
((and (< (absis p)
((and (< (absis p)
((and (> (absis p)
(t nil)
)
)

0)
0)
0)
0)

(>
(>
(<
(<

(ordinat
(ordinat
(ordinat
(ordinat

(defun istegaklurusx(p1 p2)
(if
(= (absis p1) (absis p2))
T
nil
)
)

p)
p)
p)
p)

0) )1)
0)) 2)
0)) 3)
0)) 4)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EKIVALENSIDETIK ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ekivalendetik(x)
(list (truncate (/ x 86400))
(truncate (/ (mod x 86400) 3600))
(truncate(/ (mod (mod x 86400) 3600) 60))
(mod (mod (mod x 86400) 3600) 60)
)
)

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close