|
From: | Emanuel Berg |
Subject: | Re: problems of everyday life |
Date: | Wed, 16 Nov 2022 21:39:05 +0100 |
User-agent: | Gnus/5.13 (Gnus v5.13) |
Akib Azmain Turja wrote: > Someone implemented addition using sleep. Now I have implemented > subtraction: > > (defun subtract (x y) > (when (< y x) > (let ((tmp x)) > (setq x y) > (setq y tmp))) > (let ((time-a (current-time))) > (sleep-for x) > (let ((time-b (current-time))) > (while (< (float-time (time-subtract nil time-a)) y) > (sleep-for 0.9)) > (floor (float-time (time-subtract nil time-b)))))) > > (subtract 0 1) ; => 1 > (subtract 3 5) ; => 2 What about recursive counting? (defun recursive-count (n) (if (zerop n) 0 (1+ (recursive-count (1- n))) )) (recursive-count 5) ; 5 -- underground experts united https://dataswamp.org/~incal
[Prev in Thread] | Current Thread | [Next in Thread] |