Square but not cube: Difference between revisions
Content added Content deleted
(Square but not cube in BASIC256 and Yabasic) |
Not a robot (talk | contribs) (Add Miranda) |
||
Line 2,206: | Line 2,206: | ||
<pre>{4, 9, 16, 25, 36, 49, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 784, 841, 900, 961, 1024, 1089} |
<pre>{4, 9, 16, 25, 36, 49, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 784, 841, 900, 961, 1024, 1089} |
||
{1, 64, 729}</pre> |
{1, 64, 729}</pre> |
||
=={{header|Miranda}}== |
|||
<syntaxhighlight lang="miranda">main :: [sys_message] |
|||
main = [Stdout (lay (map show squarenotcube))] |
|||
where squarenotcube = take 30 (squares $notin cubes) |
|||
squares :: [num] |
|||
squares = map (^ 2) [1..] |
|||
cubes :: [num] |
|||
cubes = map (^ 3) [1..] |
|||
|| Values in as not in bs, assuming as and bs are sorted |
|||
notin :: [num] -> [num] -> [num] |
|||
notin as [] = as |
|||
notin (a:as) (b:bs) = a:notin as (b:bs), if a < b |
|||
= notin as bs, if a = b |
|||
= notin (a:as) bs, if a > b</syntaxhighlight> |
|||
{{out}} |
|||
<pre>4 |
|||
9 |
|||
16 |
|||
25 |
|||
36 |
|||
49 |
|||
81 |
|||
100 |
|||
121 |
|||
144 |
|||
169 |
|||
196 |
|||
225 |
|||
256 |
|||
289 |
|||
324 |
|||
361 |
|||
400 |
|||
441 |
|||
484 |
|||
529 |
|||
576 |
|||
625 |
|||
676 |
|||
784 |
|||
841 |
|||
900 |
|||
961 |
|||
1024 |
|||
1089</pre> |
|||
=={{header|MiniScript}}== |
=={{header|MiniScript}}== |