Anonymous user
Sieve of Eratosthenes: Difference between revisions
→{{header|Elm with immutable arrays}}: fixed header
imported>Polarit (new elm version) |
imported>Polarit (→{{header|Elm with immutable arrays}}: fixed header) |
||
Line 6,647:
Found 78498 primes to 1000000 in 192 milliseconds.</pre>
==
<syntaxhighlight lang="elm">
module PrimeArray exposing (main)
Line 6,654:
import Html exposing (div, h1, p, text)
import Html.Attributes exposing (style)
{-
The Eratosthenes sieve task in Rosetta Code does not
the use of modulo function (allthough Elm functions modBy
Thus the
as Elm has no indexes for lists.
In this method we need no division remainder calculations,
Line 6,666 ⟶ 6,665:
We need the indexes that we know, where the marking of the non-primes
shall be set.
Because everything is immutable in Elm, every change of array values will create a new array save the original array unchanged. That makes the program running slower or consuming more space of memory than with non-functional imperative languages. All conventional loops (for, while, until) are excluded in Elm because immutability requirement.
Live: https://ellie-app.com/pTHJyqXcHtpa1
Line 6,722:
Zero is no integer and may thus be used as marking of non-prime numbers. At the end, only the primes remain in the array and the zeroes are removed from the resulted array to be shown in Html.
-}
-- The recursive loop of variable i follows:▼
loopI : Int -> Int -> Array Int -> Array Int
Line 6,818:
Found 35 primes
</pre>
=={{header|Emacs Lisp}}==
|