Jump to content

Square but not cube: Difference between revisions

Add Miranda
(Square but not cube in BASIC256 and Yabasic)
(Add Miranda)
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}
{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}}==
2,115

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.