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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Square but not cube step by step in the Factor 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 Factor programming language

Source code in the factor programming language

USING: combinators interpolate io kernel prettyprint math
math.functions math.order pair-rocket ;
IN: rosetta-code.square-but-not-cube

: fn ( s c n -- s' c' n' )
    dup 31 < [
        2over [ sq ] [ 3 ^ ] bi* <=> {
            +lt+ => [ [ dup sq . 1 + ] 2dip 1 + fn ]
            +eq+ => [ [ dup sq [I ${} cube and squareI] nl 1 + ] [ 1 + ] [ ] tri* fn ]
            +gt+ => [ [ 1 + ] dip fn ]
        } case
    ] when ;

1 1 1 fn 3drop


  

You may also check:How to resolve the algorithm Nth root step by step in the Maple programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Simula programming language
You may also check:How to resolve the algorithm Palindromic gapful numbers step by step in the REXX programming language
You may also check:How to resolve the algorithm Rosetta Code/Find unimplemented tasks step by step in the J programming language
You may also check:How to resolve the algorithm Roots of a function step by step in the Scala programming language