;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/bike.el ;; ;; eval me: [or see sample output last in file] ;; (test-roll-out-program) (require 'cl-lib) (require 'math) (require 'subr-x) (defun bike-compute-step (from to &optional str) (percent (/ (- to from) from 1.0) nil str) ) ;; (bike-compute-step 12 13 t) ; 8% ;; (bike-compute-step 13 12 t) ; -8% (defun bike-steps (sprockets) (cl-loop for s in sprockets with last with steps finally return steps do (when last (push (bike-compute-step last s) steps) ) (setq last s) )) ;; (bike-steps '(34 50)) ;; (bike-steps '(12 13 15 17 19 21 23 25)) (defun test-roll-out-program () (let ((chainrings '(34 50)) (sprockets '(12 13 15 17 19 21 23 25)) (bsd 622) (tire 23) ) (print-roll-outs chainrings sprockets bsd tire) )) (defun roll-out (chainring sprocket bsd tire) (let*((diameter (+ bsd (* 2 tire))) (circum (* diameter float-pi)) (roll-out (* (/ chainring sprocket 1.0) circum)) ) (list chainring sprocket roll-out) )) (defun all-roll-outs (chainrings sprockets bsd tire) (let ((gears)) (dolist (c chainrings) (dolist (s sprockets) (push (roll-out c s bsd tire) gears) )) (cl-sort gears #'< :key #'cl-third) )) (defun numlist-to-string (numbers) (string-join (mapcar (lambda (n) (number-to-string n)) numbers) " ") ) (defun print-intro-data (chainrings sprockets bsd tire) (insert (format "BSD: %3d mm\n" bsd) (format "tire: %3d mm\n" tire) (format "wheel: %d + 2*%d = %d mm\n" bsd tire (+ bsd (* 2 tire))) (format "chainrings: %sT\n" (numlist-to-string chainrings)) (format "sprockets: %sT\n" (numlist-to-string sprockets)) "roll-out = chainring/sprocket * wheel\n\n" " chainring (T) sprocket (T) roll-out (mm)\n\n") ) (defun print-roll-outs (chainrings sprockets bsd tire) (let ((out-buff (get-buffer-create "*gears*"))) (with-current-buffer out-buff (goto-char (point-max)) (print-intro-data chainrings sprockets bsd tire) (let ((ros (all-roll-outs chainrings sprockets bsd tire))) (cl-loop for (c s r) in ros do (insert (format "% 9d% 14d% 15.0f\n" c s r)) ))) (pop-to-buffer out-buff) )) ;; BSD: 622 mm ;; tire: 23 mm ;; wheel: 622 + 2*23 = 668 mm ;; chainrings: 34 50T ;; sprockets: 12 13 15 17 19 21 23 25T ;; roll-out = chainring/sprocket * wheel ;; ;; chainring (T) sprocket (T) roll-out (mm) ;; ;; 34 25 2854 ;; 34 23 3102 ;; 34 21 3398 ;; 34 19 3755 ;; 50 25 4197 ;; 34 17 4197 ;; 50 23 4562 ;; 34 15 4757 ;; 50 21 4997 ;; 34 13 5489 ;; 50 19 5523 ;; 34 12 5946 ;; 50 17 6172 ;; 50 15 6995 ;; 50 13 8071 ;; 50 12 8744 (provide 'bike)