Home Technical Technical

Latest Comments

Bookmark this!!!

Technical
Scheme Language - basic programs III PDF Print E-mail
Tweet me!
Technical - Technical
Written by Karthikeyan NG Administrator   
Tuesday, 13 October 2009 10:07

(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)
                  
                                 
         

 
Scheme language - basic programs II PDF Print E-mail
Tweet me!
Technical - Technical
Written by Karthikeyan NG Administrator   
Monday, 12 October 2009 16:50

; 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)

Last Updated on Tuesday, 13 October 2009 09:50
 
Scheme Language - basic programs PDF Print E-mail
Tweet me!
Technical - Technical
Written by Karthikeyan NG   
Monday, 12 October 2009 15:48

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)
            

Read more...
 
Storing Tamil fonts into the Database PDF Print E-mail
Tweet me!
User Rating: / 3
PoorBest 
Technical - Technical
Written by Karthikeyan NG   
Sunday, 27 September 2009 19:47

Recently I got a project from one of my relative's organization. It deals about maintaining their customer's details along with their credit amount and it must generate reports based on their specification and exporting the report results into excel sheet.

Actually I thought it was an easy one to do with ASP.Net grid view controls. So I have started with that. In that application we must store the customers name in Tamil font. It was the main one. Every name will be a combination of tamil and english letters. For example, his/her initials will be in english and name will be in tamil.

To store these type of data into the database we can use the data field type "nVarChar" in SQL server.I am using SQL server 2005 express edition. It is mainly for storing UniCodes. While inserting the data into the database add a prefix "N". For example your insert query must be like
insert into karthidb(N'unicodedata',30);

It must be like this. Really it was very much useful for me. I used Thagadoor font and also a java script for toggling from tamil font to english font and vice versa. For any doubts regarding this feel free to contact me.

 
Reverse a Linked List PDF Print E-mail
Tweet me!
Technical - Technical
Written by Karthikeyan NG   
Sunday, 27 September 2009 19:46

It is simple just a four lines of code. It will be more useful for students during placement timings.
Code:


Void ReverseLinkedList(node* header)
{
node *temp,*current,*result;
temp=NULL;
result=NULL;
current=header;
while(current!=NULL)
{
temp=current->next;
current->next=result;
result=current;
current=temp;
}
header=result;

}

 
«StartPrev1234NextEnd»

Page 1 of 4

Copyright © 2010 Karthikeyan NG. All Rights Reserved.
 


I am Karthikeyan NG, working as a software programmer in Hyderabad,India. Exploring new technologies, Bike riding, PC Gaming, Reading Novels, Blogging, Writing thamizh poems are my hobbies.


Who's Online

We have 8 guests online

Follow @ Twitter

Twitter / intrepidkarthi

My Visitors

mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterToday28
mod_vvisit_counterAll days3588

We have: 6 guests, 1 bots online
Your IP: 38.107.191.85
 , 
Today: Mar 12, 2010