Square but not cube: Difference between revisions

Content added Content deleted
(→‎{{header|Ksh}}: move to UNIX Shell section)
(→‎{{header|Tcl}}: Add implementation.)
Line 2,826: Line 2,826:
1089
1089
</pre>
</pre>

=={{header|Tcl}}==
{{trans|Common Lisp}}
<lang tcl>proc squaregen {{i 0}} {
proc squaregen "{i [incr i]}" [info body squaregen]
expr $i * $i
}

proc is_cube {n} {
for {set i 1} {($i * $i * $i) < $n} {incr i} { }
expr ($i * $i * $i) == $n
}

set cubes {}
set noncubes {}
for {set s [squaregen]} {[llength $noncubes] < 30} {set s [squaregen]} {
if [is_cube $s] {
lappend cubes $s
} else {
lappend noncubes $s
}
}
puts "Squares but not cubes:"
puts $noncubes
puts {}
puts "Both squares and cubes:"
puts $cubes</lang>

{{Out}}
<pre>Squares but not cubes:
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

Both squares and cubes:
1 64 729</pre>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==