Untouchable numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|C}}: Runs quicker if compiled without any optimizations (used -O3 before).)
m (→‎{{header|Wren}}: Minor tidy)
Line 1,893: Line 1,893:


=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-seq}}
{{libheader|Wren-math}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
Line 1,899: Line 1,898:
===Version 1===
===Version 1===
Run time about 70 seconds on my Core i7 machine.
Run time about 70 seconds on my Core i7 machine.
<syntaxhighlight lang="ecmascript">import "/math" for Int, Nums
<syntaxhighlight lang="wren">import "./math" for Int, Nums
import "/seq" for Lst
import "./fmt" for Fmt
import "/fmt" for Fmt


var sieve = Fn.new { |n|
var sieve = Fn.new { |n|
Line 1,924: Line 1,922:


System.print("List of untouchable numbers <= 2,000:")
System.print("List of untouchable numbers <= 2,000:")
for (chunk in Lst.chunks(untouchable.where { |n| n <= 2000 }.toList, 10)) {
Fmt.tprint("$,6d", untouchable.where { |n| n <= 2000 }, 10)
Fmt.print("$,6d", chunk)
}
System.print()
System.print()
Fmt.print("$,6d untouchable numbers were found <= 2,000", untouchable.count { |n| n <= 2000 })
Fmt.print("$,6d untouchable numbers were found <= 2,000", untouchable.count { |n| n <= 2000 })
Line 1,978: Line 1,974:


Run time for untouchable numbers up to 100,000 (m = 14) is now only 1.4 seconds and 1,000,000 (m = 63) is reached in 132 seconds.
Run time for untouchable numbers up to 100,000 (m = 14) is now only 1.4 seconds and 1,000,000 (m = 63) is reached in 132 seconds.
<syntaxhighlight lang="ecmascript">import "/math" for Int, Nums
<syntaxhighlight lang="wren">import "./math" for Int, Nums
import "/seq" for Lst
import "./fmt" for Fmt
import "/fmt" for Fmt


var limit = 1e6
var limit = 1e6
Line 2,006: Line 2,001:
}
}
System.print("List of untouchable numbers <= 2,000:")
System.print("List of untouchable numbers <= 2,000:")
for (chunk in Lst.chunks(untouchable.where { |n| n <= 2000 }.toList, 10)) {
Fmt.tprint("$,6d", untouchable.where { |n| n <= 2000 }, 10)
Fmt.print("$,6d", chunk)
}
System.print()
System.print()
Fmt.print("$,7d untouchable numbers were found <= 2,000", untouchable.count { |n| n <= 2000 })
Fmt.print("$,7d untouchable numbers were found <= 2,000", untouchable.count { |n| n <= 2000 })