100 doors: Difference between revisions
Content deleted Content added
Langurmonkey (talk | contribs) |
→{{header|Haxe}}: Added unoptimised version and tweak the optimised version |
||
Line 6,743:
=={{header|Haxe}}==
===Unoptimised===
<syntaxhighlight lang="haxe">
class Main
{
static public function main()
{
findOpenDoors( 100 );
}
static function findOpenDoors( n : Int )
{
var door = [];
for( i in 0...n + 1 ){ door[ i ] = false; }
for( i in 1...n + 1 ){
var j = i;
while( j <= n ){
door[ j ] = ! door[ j ];
j += i;
}
}
for( i in 1...n + 1 ){
if( door[ i ] ){ Sys.print( ' $i' ); }
}
}
}</syntaxhighlight>
{{out}}
<pre>
1 4 9 16 25 36 49 64 81 100
</pre>
===Optimised===
<syntaxhighlight lang="haxe">class RosettaDemo
{
Line 6,756 ⟶ 6,789:
while((i*i) <= n)
{
Sys.
i++;
}
|