Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 935 Bytes

elisp-exercises.org

File metadata and controls

46 lines (36 loc) · 935 Bytes

Write a script that finds the first square number that has at least 5 distinct digits.

Source: Why I love Perl 6 | Damian Conway {blogs.perl.org}

stream

(seq-find
 (lambda (x)
   (and (= x (expt (cl-isqrt x) 2))
        (>= (length (seq-uniq (number-to-string x))) 5)))
 (stream-range 1))

cl-loop

(cl-loop for i from 1
         when (and (= i (expt (cl-isqrt i) 2))
                   (>= (length (seq-uniq (number-to-string i))) 5))
         return i)

while

(let ((i 1))
  (catch 'good
    (while t
      (when (and (= i (expt (cl-isqrt i) 2))
                 (>= (length (seq-uniq (number-to-string i))) 5))
        (throw 'good i))
      (cl-incf i))))