newLISP:

 

; 주민등록번호 검증기
; Resident registration number validator

(println "Resident registration number validator")

(define (resregnum? a)
  (if (!= (length a) 13) nil
    (begin
      (setq s 0) 
      (for (i 0 11)   
        (setq s (+ s (* (+ 2 (mod i 8)) (int (a i))))))
      (setq s (mod (- 11 (mod s 11)) 10))
      (= s (int (a 12))))))
 
(while true
  (print "> ")
  (setq rrn (read-line))
  (if (nil? rrn) (exit)
    (println (resregnum? rrn))))

 

Paren:

 

resregnum.paren

 

 

 

JavaScript:

 

resregnum.html

 

resregnum2.html

 

 

Parenjs:

 

resregnumParen.html

 

 

Go:

 

resregnum.go

 

resregnum.exe

 

 

C:

 

// 주민등록번호 검증기
// Resident registration number validator
#include <stdio.h>
#include <string.h>
#include <malloc.h>
 
int isRRN(char *a) {
  if (strlen(a) != 13) return 0;
  int s = 0, i;
  for (i = 0; i <= 11; i++) {
    s += (2 + (i % 8)) * (a[i]-'0');
  }
  s = (11 - (s % 11)) % 10;
  return s == (a[12]-'0');
}
 
char *readline(char *prompt) {
  size_t size = 80;
  char *str = malloc(sizeof(char) * size);
  int c;
  size_t len = 0;
  printf(prompt);
  while (EOF != (c = getchar()) && c != '\r' && c != '\n') {
    str[len++] = c;
    if(len == size) str = realloc(str, sizeof(char) * (size *= 2));
  }
  str[len++]='\0';
  return realloc(str, sizeof(char) * len);
}
 
int main() {
  puts("Resident registration number validator");
  for (;;) {
    char *rrn;
    rrn = readline("> ");
    if (feof(stdin)) break;
    puts(isRRN(rrn) ? "true" : "false");
    free(rrn);
  }
  return 0;
}

 


 

 

 

 

 

 

Arc:

(prn "Resident registration number validator")
(= zero-char ("0" 0))

(def resregnum? (a)
  (if (isnt (len a) 13) nil
    (do
      (= s 0)
      (for i 0 11
        (= s (+ s (* (+ 2 (mod i 8)) (- (int (a i)) zero-char)))))
      (= s (mod (- 11 (mod s 11)) 10)) 
      (is s (- (int (a 12)) zero-char)))))
 
(while t
  (pr "> ")
  (= rrn (readline))
  (unless rrn (quit))
  (prn (resregnum? rrn)))

 

Common Lisp:

 

(princ "Resident registration number validator")
(princ #\newline)
(finish-output)

(defun resregnum? (a)
  (if (/= (length a) 13) nil
    (let ((s 0))
      (loop for i from 0 to 11 do
        (setf s (+ s (* (+ 2 (mod i 8)) (digit-char-p (elt a i))))))
      (setf s (mod (- 11 (mod s 11)) 10))
      (= s (digit-char-p (elt a 12))))))
 
(loop
  (princ "> ")
  (finish-output)
  (let ((rrn (read-line)))
    (unless rrn (quit))
    (princ (resregnum? rrn))
    (princ #\newline)
    (finish-output)))

 

 

 

주민등록번호 (위키백과)

 

 

저작자 표시
신고
Posted by steloflute


Generate bitcoin for me

What's this?

티스토리 툴바