unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* where to cut wood
@ 2022-09-01 19:45 Emanuel Berg
  0 siblings, 0 replies; only message in thread
From: Emanuel Berg @ 2022-09-01 19:45 UTC (permalink / raw)
  To: emacs-devel

Where do you cut wood now that you aren't allowed to do that
in the machine shop anymore (or 'engineering workshop' to you
UK guys)?

The anser is <drumroll> at:

  l*n + (b/2)(2n - 1)

It's called algebra, as we see it works well with STATIC
entities! :))

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/wood.el

(require 'cl-lib)

;; Where do you cut a piece of wood if the parts should be
;; length l and the blade is width b?
;;
;; For n cuts in n = 1, 2, ... the cuts should be at:
;;
;;   l*n + (b/2)(2n - 1)
;;
;; So for 3 parts of 60 cm each and a 3 mm blade cuts are made
;; at 60.15, 120.45 and 180.75 cm.

(defun cut-2 (len &optional num blade)
  (or blade (setq blade 0.3))
  (or num   (setq num 1))
  (when (> num 0)
    (let ((hb (/ blade 2.0) ))
      (+ (* len num)
         (* hb (1- (* 2 num))) ))))
;; (cut-2 60 1) ;  60.15
;; (cut-2 60 2) ; 120.45
;; (cut-2 60 3) ; 180.75

(defun cut (len &optional blade n)
  (or blade (setq blade 0.3))
  (or n     (setq n 3))
  (cl-loop repeat n
    with cuts
    with pos = 0
    with hb  = (/ blade 2.0)
    do (cl-incf pos (+ len hb))
       (push pos cuts)
       (cl-incf pos hb)
    finally return (nreverse cuts)) )
;; (cut 60) ; (60.15 120.45 180.75)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-01 19:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 19:45 where to cut wood Emanuel Berg

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).