2012-01-01から1ヶ月間の記事一覧

Problem 7

(require 'calc-ext) (defvar calc-command-flags nil) (defun find-factor (num) (catch 'found (let ((i 2)) (while (math-lessp (math-sub i 1) (math-floor (math-sqrt num))) (if (math-equal (math-mod num i) 0) (throw 'found i) (setq i (math-add …

Problem 6

(require 'cl) (defun make-1-to-n-list (n) (loop for i from 1 to n collect i)) (defun 2pow (x) (* x x)) (let* ((num-lst (make-1-to-n-list (string-to-number(car argv)))) (x (apply #'+ (mapcar #'2pow num-lst))) (y (2pow (apply #'+ num-lst))))…

Problem 5

(require 'cl) (defun make-1-to-n-list (n) (loop for i from 1 to n collect i)) (princ (apply #'lcm (make-1-to-n-list (string-to-number (car argv))))) (princ "\n") 追記 make-1-to-n-list を定義しなくても, emacs の標準関数により汎用的な関数 nu…

Problem 4

(defun mirror-num (num) (let* ((str (int-to-string num)) (len (length str)) elt) (dotimes (i (floor (/ len 2))) (setq elt (aref str i)) (aset str i (aref str (1- (- len i)))) (aset str (1- (- len i)) elt)) (string-to-int str) )) (let ((i 1…

Problem 3

(require 'calc-ext) (defvar calc-command-flags nil) (defun find-factor (num) (catch 'found (let ((i 2)) (while (math-lessp (math-sub i 1) (math-floor (math-sqrt num))) (if (math-equal (math-mod num i) 0) (throw 'found i) (setq i (math-add …

Problem 2

(let ((a 1) (b 1) (c 0) (rst 0)) (while (< a 4000000) (if (eq (% a 2) 0) (setq rst (+ rst a)) ) (setq c a) (setq a (+ a b)) (setq b c) ) (princ rst) (princ "\n"))

Problem 1

(let ((rst 0)) (dotimes (i 1000) (if (or (eq (% i 3) 0) (eq (% i 5) 0) ) (setq rst (+ rst i)) )) (princ rst) (princ "\n") ) elisp でやっていくぜよ