Re: Simple math/programming challenge for the "REAL programmer" Feeb

Liste des GroupesRevenir à ol advocacy 
Sujet : Re: Simple math/programming challenge for the "REAL programmer" Feeb
De : yax (at) *nospam* yaxley.in (Yaxley Peaks)
Groupes : comp.os.linux.advocacy
Date : 10. Mar 2024, 09:41:12
Autres entêtes
Organisation : Not a Noiseless Patient Spider
Message-ID : <87h6heilev.fsf@yaxley.in>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13)
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

Date Sujet#  Auteur
10 Mar 24 * Simple math/programming challenge for the "REAL programmer" Feeb19DFS
10 Mar 24 +* Re: Simple math/programming challenge for the "REAL programmer" Feeb17Yaxley Peaks
10 Mar 24 i`* Re: Simple math/programming challenge for the "REAL programmer" Feeb16DFS
10 Mar 24 i +- Re: Simple math/programming challenge for the "REAL programmer" Feeb1Stéphane CARPENTIER
10 Mar 24 i +* Re: Simple math/programming challenge for the "REAL programmer" Feeb12Tyrone
10 Mar 24 i i`* Re: Simple math/programming challenge for the "REAL programmer" Feeb11DFS
10 Mar 24 i i +* Re: Simple math/programming challenge for the "REAL programmer" Feeb5vallor
10 Mar 24 i i i`* Re: Simple math/programming challenge for the "REAL programmer" Feeb4DFS
10 Mar 24 i i i +* Re: Simple math/programming challenge for the "REAL programmer" Feeb2vallor
11 Mar 24 i i i i`- Re: Simple math/programming challenge for the "REAL programmer" Feeb1DFS
10 Mar 24 i i i `- Re: Simple math/programming challenge for the "REAL programmer" Feeb1vallor
10 Mar 24 i i `* Re: Simple math/programming challenge for the "REAL programmer" Feeb5DFS
11 Mar 24 i i  `* Re: Simple math/programming challenge for the "REAL programmer" Feeb4Tyrone
11 Mar 24 i i   +- Re: Simple math/programming challenge for the "REAL programmer" Feeb1DFS
11 Mar 24 i i   `* Re: Simple math/programming challenge for the "REAL programmer" Feeb2Physfitfreak
11 Mar 24 i i    `- Re: Simple math/programming challenge for the "REAL programmer" Feeb1DFS
10 Mar 24 i `* Re: Simple math/programming challenge for the "REAL programmer" Feeb2Yaxley Peaks
10 Mar 24 i  `- Re: Simple math/programming challenge for the "REAL programmer" Feeb1DFS
11 Mar 24 `- Re: Simple math/programming challenge for the "REAL programmer" Feeb1DFS

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal