Skip to content

Instantly share code, notes, and snippets.

@eush77
Created December 22, 2019 22:43
Show Gist options
  • Save eush77/68d295b1de791080fee9954f0b2025b6 to your computer and use it in GitHub Desktop.
Save eush77/68d295b1de791080fee9954f0b2025b6 to your computer and use it in GitHub Desktop.
Exploration of the letter-counting function for Russian language
;; Exploration of the letter-counting function for Russian language.
;; Inspired by Matt Parker's https://youtu.be/LYKn0yUTIU4
(defvar t-prims
'((1 . "один")
(2 . "два")
(3 . "три")
(4 . "четыре")
(5 . "пять")
(6 . "шесть")
(7 . "семь")
(8 . "восемь")
(9 . "девять")
(10 . "десять")
(11 . "одиннадцать")
(12 . "двенадцать")
(13 . "тринадцать")
(14 . "четырнадцать")
(15 . "пятнадцать")
(16 . "шестнадцать")
(17 . "семнадцать")
(18 . "восемнадцать")
(19 . "девятнадцать")
(20 . "двадцать")
(30 . "тридцать")
(40 . "сорок")
(50 . "пятьдесят")
(60 . "шестьдесят")
(70 . "семьдесят")
(80 . "восемьдесят")
(90 . "девяносто")
(100 . "сто")
(200 . "двести")
(300 . "триста")
(400 . "четыреста")
(500 . "пятьсот")
(600 . "шестьсот")
(700 . "семьсот")
(800 . "восемьсот")
(900 . "девятьсот")
(1000 . "тысяча")))
(defun t-spell (num)
(or (alist-get num t-prims)
(cond
((> num 1000) (error "Not implemented"))
((>= num 100) (concat (alist-get (- num (% num 100)) t-prims)
(t-spell (% num 100))))
((>= num 20) (concat (alist-get (- num (% num 10)) t-prims)
(t-spell (% num 10))))
((zerop num) ""))))
(defun t-count (num)
(length (t-spell num)))
(defun t-steps (num &optional seen)
(let ((seen (cons num seen))
(next (t-count num)))
(if (member next seen)
(reverse seen)
(t-steps next seen))))
(defun t-nsteps (num)
(length (t-steps num)))
(defun t-laststep (num)
(car (last (t-steps num))))
(seq-filter (lambda (num) (>= (t-count num) num)) (number-sequence 1 1000))
;;=> (1 2 3 4 11)
(seq-map (pcase-lambda (`(,num . ,repeats))
(cons num (length repeats)))
(seq-group-by #'identity
(seq-map #'t-laststep (number-sequence 1 1000))))
;;=> ((6 . 2) (3 . 3) (5 . 8) (11 . 227) (4 . 760))
;; Cycles the numbers get stuck at
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment