How to resolve the algorithm Square but not cube step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Square but not cube step by step in the Clojure programming language

Table of Contents

Problem Statement

Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Square but not cube step by step in the Clojure programming language

Source code in the clojure programming language

(def squares (map #(* % %) (drop 1 (range))))
(def square-cubes (map #(int (. Math pow % 6)) (drop 1 (range))))

(def squares-not-cubes (filter #(not (= % (first (drop-while (fn [n] (< n %)) square-cubes)))) squares))

(println "Squares but not cubes:")
(println (take 30 squares-not-cubes))
(println "Both squares and cubes:")
(println (take 15 square-cubes))


  

You may also check:How to resolve the algorithm String interpolation (included) step by step in the REBOL programming language
You may also check:How to resolve the algorithm Strassen's algorithm step by step in the Julia programming language
You may also check:How to resolve the algorithm Day of the week step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Box the compass step by step in the Fortran programming language
You may also check:How to resolve the algorithm Polymorphism step by step in the Wollok programming language