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

TeX 数式ラベル入力補助用 elisp -- texlabel.el v1.0.0

texlabel.el とは TeXの数式ラベル入力補助用の elisp です。 TeXの数式ラベルをいちいち打つのは面倒ですよね。 ラベル名を考えるのすら面倒です。 そんな悩みを解決してくれるようなelispを作りました。 概要 コマンド1つで適切な位置に番号順の数式ラベル…

Problem 22

(require 'calc-ext) (defvar calc-command-flags nil) (with-temp-buffer (insert-file-contents-literally (car argv)) (let (name-lst (i 1) (sum 0)) (while (re-search-forward "\"\\([A-Z]+?\\)\"" nil t) (setq name-lst (cons (match-string-no-prop…

Problem 21

(require 'cl) (require 'calc-ext) (defvar calc-command-flags nil) (defun hash-to-alist (hash) (let (alist) (maphash #'(lambda (key val) (push (cons key val) alist)) hash) alist )) (defun find-factor (num) (catch 'found (let ((i 2)) (while …

Problem 20

(require 'calc-ext) (defvar calc-command-flags nil) (defun factorial (n) (let ((rst 1)) (while (math-lessp 0 n) (setq rst (math-mul rst n)) (setq n (math-sub n 1)) ) rst )) (defun digit-sum (n) (let* ((str (math-format-value n)) (len (leng…

Problem 19

(defvar month-day-alist '((1 . 31) (2 . 28) (3 . 31) (4 . 30) (5 . 31) (6 . 30) (7 . 31) (8 . 31) (9 . 30) (10 . 31) (11 . 30) (12 . 31))) (defun assq-val (key alist) (cdr (assq key alist))) (defun next-month (year month day) (let ((days (…

Probrem 18

(defun read-txt-numbers (file-name) (let (num-lst) (with-temp-buffer (insert-file-contents-literally file-name) (goto-char (point-min)) (while (re-search-forward "[0-9]+" nil t) (setq num-lst (cons (string-to-number (match-string 0)) num-l…

Problem 17

(defvar num-str-alist '((1 . "one") (2 . "two") (3 . "three") (4 . "four") (5 . "five") (6 . "six") (7 . "seven") (8 . "eight") (9 . "nine") (10 . "ten") (11 . "eleven") (12 . "twelve") (13 . "thirteen") (14 . "fourteen") (15 . "fifteen") …

Problem 15

(require 'calc-ext) (defvar calc-command-flags nil) (defun factorial (n) (let ((rst 1)) (while (math-lessp 0 n) (setq rst (math-mul rst n)) (setq n (math-sub n 1)) ) rst )) (let ((size (string-to-number (car argv)))) (princ (math-format-va…

Problem 14

(require 'calc-ext) (defvar calc-command-flags nil) (let ((limit (math-add (math-read-number (car argv)) 1)) (hash (make-hash-table)) (i 1) (max-i 1)) (while (math-lessp i limit) (let ((n i) (len 0) found) (while (not (math-equal n 1)) (if…

Problem 16

(require 'calc-ext) (defvar calc-command-flags nil) (defun convert-decimal-to-binary (d) (let (b (i 0)) (while (> d 0) (setq b (cons (if (eq (% d 2) 0) 0 1) b)) (setq d (/ d 2)) (setq i (1+ i)) ) b)) (defun digits-sum (str) (let ((sum 0)) …

Problem 13

(require 'calc-ext) (defvar calc-command-flags nil) (with-temp-buffer (insert-file-contents-literally (car argv)) (let ((sum 0)) (while (re-search-forward "[0-9]\\{50\\}" nil t) (setq sum (math-add sum (math-read-number (match-string-no-pr…

Problem 11

(require 'cl) (defun make-ad-lst (pivot len grid-size) (let* ((idx (1- len)) (right (loop for i from 0 to idx collect i)) (down (loop for i from 0 to idx collect (* grid-size i))) (right-down (loop for i from 0 to idx collect (+ (* grid-si…

Problem 10

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

(require 'cl) (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) (set…

Problem 9

(let* ((n (string-to-number (car argv))) (a 1) b c ans) (setq ans (catch 'found (while (<= a (/ n 3)) (setq b (1+ a)) (while (<= b (/ (- n a) 2)) (setq c (- n a b)) (if (= (+ (* a a) (* b b)) (* c c)) (throw 'found (list a b c)) ) (setq b …

Problem 8

(require 'cl) (let* ((str "\ 73167176531330624919225119674426574742355349194934\ 96983520312774506326239578318016984801869478851843\ 85861560789112949495459501737958331952853208805511\ 12540698747158523863050715693290963295227443043557\ 66…