-
Lisp 비교 : 암호 문자열 감추기 문제 풀이Programmer/Programming 2016. 1. 13. 18:53
"케빈 TV 12회 (상) - 느 언어엔 이런거 없지?"에 주어진 글자수만큼 '*'를 가진 문자열을 생성하는 문제가 나왔다.
여러 언어별 구현이 나왔지만, Common Lisp와 Emacs Lisp, Scheme, Clojure가 없어서 여기에 적어본다.
Common Lisp:
(
defun
hide-password
(passwd)
(coerce (mapcar #'(
lambda
(x) #\*)
(coerce passwd 'list))
'string))
Emacs Lisp:
(
defun
hide-password
(passwd)
(coerce (mapcar (
lambda
(x) ?\*)
(coerce passwd 'list))
'string))
Scheme:
(
define
(
hide-password
passwd)
(list->string (
map
(
lambda
(x) #\*)
(string->list passwd))))
Clojure:
(require '[clojure.string :as str])
(
defn
hide-password
[password]
(str/join (map (
fn
[x] \*) password)))
'Programmer > Programming' 카테고리의 다른 글
Lisp에서 클로저(closures) (0) 2016.02.18 Lisp에서 lexical과 dynamic 변수 타입 (0) 2016.02.18 리습(Lisp)을 위한 SyntaxHighlighter 3.0 플러그인 작성 (0) 2015.03.17 초반에는 문제의 원인을 충분히 넓게 잡아라. (1) 2014.07.15 리스프 개발 팁: 명령창 결과 저장하기 (0) 2014.06.27