Browsed by
Month: October 2009

Scheme Language – basic programs set 1

Scheme Language – basic programs set 1

Here I have listed some basic programs in scheme language. Ask me if you have any doubts :).

_____________________
;;Bubble sort

(define (bubble inputList)
(define (swap inputList index1 index2)
(let ((item1 (list-ref inputList index1)) (item2 (list-ref inputList index2)))
(set-car! (list-tail inputList index1) item2)
(set-car! (list-tail inputList index2) item1)
)
)
(let loop1((count1 0) (len1 (- (length inputList) 1)))
(if(< count1 len1)
(begin
(let loop2((count2 (+ count1 1)) (len2 (length inputList)))

(if(< count2 len2)
(begin
(if(> (list-ref inputList count1) (list-ref inputList count2))
(begin
(swap inputList count1 count2)
(loop2 (+ count2 1) len2)
)
(loop2 (+ count2 1) len2)
)
) (loop1 (+ count1 1) len1)
)

)
)inputList
)
))
sample input:
(bubble (list 5 2 6 1 3))
output:
(1 2 3 5 6)
For calculating NCR
_______________

;;ncr calculation

(define (factorial num)

(if(= num 0)
1
(* num (factorial (- num 1)))
)
)

(define (ncr n r)
(if(inexact? n)

(let ((result 0))
(set! result (/ (factorial n) (* (factorial r) (factorial (- n r)))))

(display result))
))
input:
;(factorial 5.0)
(ncr 10.0 5)

output:
252.0

_______________________________________________

;;arithmetic progression

(define (arithprogress a d n)
(define result 0)
(let loop((temp 0) (start 0) (count n))
(if(< start count)
(begin
(set! temp (+ a (* start d)))
(set! result (+ result temp))
(loop result (+ start 1) count)
)
result
)
)
)
input:
(arithprogress 4 5 6)

output:
99

Scheme Language – basic programs set 2

Scheme Language – basic programs set 2

; string reverse

(define (stringrev inputString)
(define len (string-length inputString))
(define result “”)
(let loop((count len))
(if(> count 0)
(begin
(set! result (string-append result (make-string 1 (string-ref inputString (- count 1)))))
(loop (- count 1))
))
result
)
)
input:
;(stringrev “karthi”)
output:
“ihtrak”

_____________________________________
; fibonacci series

(define (fibonacci num)
(define num1 0)
(define num2 1)
(define result(list))
(let loop((count 0) (temp 0))
(if(< count num)
(begin
(set! result (append result (list num1)))
(set! temp num2)
(set! num2 (+ num1 num2))
(set! num1 temp)
(loop (+ count 1) temp)
)
result
)
)
)
input:
(fibonacci 5)
output:
(0 1 1 2 3)

___________________________
;struct

(define-struct std(roll name))
(define (pro clist)

(std-roll (list-ref clist 0))
(set-std-roll! (list-ref clist 0) 2)
(std-roll (list-ref clist 0))

)

(pro (list (make-std 11 “gg”) (make-std 12 “tt”)))
2

______________________________
(define (checkprime num)
(if(< num 2)
#f
(begin
(let loop((count 2) (end (round(sqrt num))))
(if(<= count end)
(begin
(if(= (modulo num count) 0)
#f
(loop (+ count 1) end)

)
)
#t
)
)
)
)
)
;(checkprime 8)
;(checkprime 9)
;(checkprime 1)
;(checkprime 2)
(define (prime num)
(define result(list))
(let looping((count 2) (end num))
(if(<= count num)
(begin
(if(checkprime count)
(begin
(set! result (append result (list count)))
(looping (+ count 1) end)
)
(looping (+ count 1) end)
)
)
result
)
)
)
input:
(prime 50)
output:
(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47)

Scheme Language – basic programs set 3

Scheme Language – basic programs set 3

(define (checkperfect num)
(define total 0)
(let loop((count 1) (end(round(/ num 2))) (temp 0))
(if(<= count end)
(begin
(if(= (modulo num count) 0)
(begin
(set! temp count)
(set! total (+ total temp))
(loop (+ count 1) end temp)
)
(loop (+ count 1) end temp)
)
)
(begin
(if(= total num)
#t
#f
)  )   )  )  )
;(checkperfect 28)

(define (findperfects start end)
(define result(list))
(let loop((count start))
(if(<= count end)
(begin
(if(checkperfect count)
(begin
(set! result (append result (list count)))
(loop (+ count 1))
)
(loop (+ count 1))
)    )
result
)   )  )
Input:
(findperfects 1 5000)
Output:
(6 28 496)

Movie Review – Aadhavan

Movie Review – Aadhavan

To avoid swine flu problems, they didn’t allow us to go to home for this deepavali. So we have planned to go for a movie here. We went to Anjali theatre in trivandrum on saturday morning. We thought there won’t be any crowd since it is releasing in thamizh. But we didn’t expect that much crowd there. There was a heavy crowd than we can see in tamilnadu theatres. There is a lot of fans for surya. One friend from Kerala told that Vijay has more fans than other thamizh actors. I was really wondering. In Tamilnadu there won’t be any other language films. But here it is not like that. They like other language films a lot, especiallt Thamizh movies. There is a lot of fan clubs for Surya, Vijay and vikram here. me, kavin, Raveen and Samuel went to the film.

 

Aadhavan is directed by K S Ravikumar and produced by Udhayanidhi Stalin, starring Surya and Nayanthara. In over all the film was good. We can see once.

Story:

The whole film was suited in Kolkata and its surrondings.Surya is a local gangster with some fellows around him. He gets a job for killing a judge.The judge is supposed to submit a report regarding many illegal activities. So somebody pays money to hero’s gang to kill him. But he misses his chance to kill him.  So he plans to kill him with in ten days. So he goes into his home with the help of Vadivel.His every attempt fails in home also with Gun and Bombs. Our heroine also lives in that home. In the mean time his fightings also good. Some of the fight sequences copied from the movies Wanted and District.
In the mean time hero reveals the truth to heroine that he is her cousin at childhood. Then heroine falls in love with hero. Songs are really nice to hear and also to see.Nayanthara acts perfectly without any glamour. Laterly there was a flash back story.They have tried a new thing. Surya looks like a ten year old boy in it with some graphics. The judge is his father. He doesn’t like hero. His aunt(nayan’s mom) shows care on him.Nayanthata’s mom and dad was killed by some enemies of the judge. So hero again

 

kills them and joins with a local gang. Hero fights with his own gang since he is trying to save the judge becausehe is his father. Thats why he goes to his home as a servant. His gang tries to kill him but hero saves his father from them. The fight continues till the end with vadivel comedies and some duet songs in between.In the climax fight they have made some unbelievable things in a flying helicopter.That must be avoided. Except that everything is good. Nice family movie to watch once.

TCS days starts

TCS days starts

On 29.09.2009 our training starts in TCS, Trivandrum technopark campus. It is really cool here both infra structure and also our accommodation. Training ends on March 4th approximately.  They have conducted some induction program for two days. It was interesting. Today they have divided us into batches and starts their training program. They gave some programs to do. All are simple programs which we have done in our first year C programming lab 🙂 . They have given some 25 programs to do like that. Three days leave now. Tomorrow all are going to kovalam beach, padmanabapuram temple, museum and zoo blah blah blah.. for roaming for the next three days 🙂 . We are going to book tickets for deepavali trip.I will update everything often.