Deutsch   English   Français   Italiano  
<87h6heilev.fsf@yaxley.in>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Yaxley Peaks <yax@yaxley.in>
Newsgroups: comp.os.linux.advocacy
Subject: Re: Simple math/programming challenge for the "REAL programmer" Feeb
Date: Sun, 10 Mar 2024 13:11:12 +0530
Organization: Not a Noiseless Patient Spider
Lines: 23
Message-ID: <87h6heilev.fsf@yaxley.in>
References: <usj06r$2jn18$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="31aa803055a52cd57cfe794de9b3254d";
	logging-data="3007191"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19NWRye0s6Cr2Je9Pnq2L44HV9tULzAkl0="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:QCRFX3VjYrw2jYynXI9tEJShNtQ=
	sha1:ZuFIu0UB7hKKLnkQOQLs/p4t4WI=
Bytes: 1749

Does emacs lisp count?

;; ------------------
(defun kaprekarp (n)
  (let* ((num (* n n))
         (snum (number-to-string num))
         (num-digits (length (number-to-string n)))
         (num-list (string-split snum "" t))
         (right-side (reverse (take num-digits (reverse num-list))))
         (left-side (reverse (nthcdr num-digits (reverse num-list))))
         (left-side-num (string-to-number (mapconcat 'identity left-side)))
         (right-side-num (string-to-number (mapconcat 'identity right-side))))
    (= n (+ right-side-num left-side-num))))
(defun solve-problem (low high)
  (seq-keep (lambda (x)
              (and (kaprekarp x) x))
            (number-sequence low high)))
(solve-problem 1 100000000)
;; ------------------

A very naive solution, but I am sorry, I am very drunk right now lol
-- 
(yaxp me) => t