Distinct power numbers: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 11: | Line 11: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">print(sorted(Array(Set(cart_product(2..5, 2..5).map((a, b) -> a ^ b)))))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 20: | Line 20: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
{{libheader|Action! Tool Kit}} |
{{libheader|Action! Tool Kit}} |
||
< |
<syntaxhighlight lang="action!">INCLUDE "D2:SORT.ACT" ;from the Action! Tool Kit |
||
INT FUNC Power(INT a,b) |
INT FUNC Power(INT a,b) |
||
Line 66: | Line 66: | ||
PrintI(a(i)) Put(32) |
PrintI(a(i)) Put(32) |
||
OD |
OD |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Distinct_power_numbers.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Distinct_power_numbers.png Screenshot from Atari 8-bit computer] |
||
Line 74: | Line 74: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
with Ada.Containers.Doubly_Linked_Lists; |
with Ada.Containers.Doubly_Linked_Lists; |
||
Line 105: | Line 105: | ||
New_Line; |
New_Line; |
||
end Power_Numbers;</ |
end Power_Numbers;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 </pre> |
<pre> 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 </pre> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang="algol68">BEGIN # show in order, distinct values of a^b where 2 <= a <= b <= 5 # |
||
INT max number = 5; |
INT max number = 5; |
||
INT min number = 2; |
INT min number = 2; |
||
Line 146: | Line 146: | ||
OD; |
OD; |
||
print( ( newline ) ) |
print( ( newline ) ) |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 154: | Line 154: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
{{works with|Dyalog APL}} |
{{works with|Dyalog APL}} |
||
<lang |
<syntaxhighlight lang="apl">(⊂∘⍋⌷⊣)∪,∘.*⍨1+⍳4</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
||
Line 161: | Line 161: | ||
===Idiomatic=== |
===Idiomatic=== |
||
Uses an extravagantly long list, but gets the job done quickly and easily. |
Uses an extravagantly long list, but gets the job done quickly and easily. |
||
< |
<syntaxhighlight lang="applescript">on task() |
||
script o |
script o |
||
property output : {} |
property output : {} |
||
Line 180: | Line 180: | ||
end task |
end task |
||
task()</ |
task()</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
< |
<syntaxhighlight lang="applescript">{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</syntaxhighlight> |
||
---- |
---- |
||
Line 189: | Line 189: | ||
Composing a solution from generic primitives, for speed of drafting, and ease of refactoring: |
Composing a solution from generic primitives, for speed of drafting, and ease of refactoring: |
||
< |
<syntaxhighlight lang="applescript">use framework "Foundation" |
||
use scripting additions |
use scripting additions |
||
Line 268: | Line 268: | ||
((current application's NSArray's arrayWithArray:xs)'s ¬ |
((current application's NSArray's arrayWithArray:xs)'s ¬ |
||
sortedArrayUsingSelector:"compare:") as list |
sortedArrayUsingSelector:"compare:") as list |
||
end sort</ |
end sort</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</pre> |
<pre>{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</pre> |
||
Line 274: | Line 274: | ||
===AppleScriptObjC=== |
===AppleScriptObjC=== |
||
Throwing together a solution using the most appropriate methods for efficiency and legibility. |
Throwing together a solution using the most appropriate methods for efficiency and legibility. |
||
< |
<syntaxhighlight lang="applescript">use AppleScript version "2.4" -- Mac OS X 10.10 (Yosemite) or later. |
||
use framework "Foundation" |
use framework "Foundation" |
||
Line 291: | Line 291: | ||
end task |
end task |
||
task()</ |
task()</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
< |
<syntaxhighlight lang="applescript">{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</syntaxhighlight> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">print sort unique flatten map 2..5 'a [ |
||
map 2..5 'b -> a^b |
map 2..5 'b -> a^b |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 307: | Line 307: | ||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
< |
<syntaxhighlight lang="bcpl">get "libhdr" |
||
let pow(n, p) = |
let pow(n, p) = |
||
Line 335: | Line 335: | ||
if i=0 | v!i ~= v!(i-1) do writef("%N ", v!i) |
if i=0 | v!i ~= v!(i-1) do writef("%N ", v!i) |
||
wrch('*N') |
wrch('*N') |
||
$)</ |
$)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
||
=={{header|BQN}}== |
=={{header|BQN}}== |
||
<lang |
<syntaxhighlight lang="bqn">∧⍷⥊⋆⌜˜ 2+↕4</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>⟨ 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 ⟩</pre> |
<pre>⟨ 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 ⟩</pre> |
||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <math.h> |
#include <math.h> |
||
Line 371: | Line 371: | ||
printf("\n"); |
printf("\n"); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#include <set> |
#include <set> |
||
#include <cmath> |
#include <cmath> |
||
Line 391: | Line 391: | ||
std::cout << std::endl; |
std::cout << std::endl; |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
set[for n in 2..5 do for g in 2..5->pown n g]|>Set.iter(printf "%d ") |
set[for n in 2..5 do for g in 2..5->pown n g]|>Set.iter(printf "%d ") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 406: | Line 406: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-06-02}} |
{{works with|Factor|0.99 2021-06-02}} |
||
< |
<syntaxhighlight lang="factor">USING: kernel math.functions math.ranges prettyprint sequences |
||
sets sorting ; |
sets sorting ; |
||
2 5 [a,b] dup [ ^ ] cartesian-map concat members natural-sort .</ |
2 5 [a,b] dup [ ^ ] cartesian-map concat members natural-sort .</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 416: | Line 416: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic"> |
||
redim arr(-1) as uinteger |
redim arr(-1) as uinteger |
||
dim as uinteger i |
dim as uinteger i |
||
Line 434: | Line 434: | ||
if arr(i)<>arr(i-1) then print arr(i), |
if arr(i)<>arr(i-1) then print arr(i), |
||
next i |
next i |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
{{libheader|Go-rcu}} |
{{libheader|Go-rcu}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 473: | Line 473: | ||
} |
} |
||
fmt.Println("\nFound", len(pows), "such numbers.") |
fmt.Println("\nFound", len(pows), "such numbers.") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 486: | Line 486: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import qualified Data.Set as S |
||
Line 501: | Line 501: | ||
main = |
main = |
||
print $ |
print $ |
||
distinctPowerNumbers 2 5</ |
distinctPowerNumbers 2 5</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]</pre> |
<pre>[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]</pre> |
||
Line 508: | Line 508: | ||
or, as a one-off list comprehension: |
or, as a one-off list comprehension: |
||
< |
<syntaxhighlight lang="haskell">import qualified Data.Set as S |
||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
(print . S.elems . S.fromList) $ |
(print . S.elems . S.fromList) $ |
||
(\xs -> [x ^ y | x <- xs, y <- xs]) [2 .. 5]</ |
(\xs -> [x ^ y | x <- xs, y <- xs]) [2 .. 5]</syntaxhighlight> |
||
or a liftA2 expression: |
or a liftA2 expression: |
||
< |
<syntaxhighlight lang="haskell">import Control.Applicative (liftA2) |
||
import Control.Monad (join) |
import Control.Monad (join) |
||
import qualified Data.Set as S |
import qualified Data.Set as S |
||
Line 525: | Line 525: | ||
join |
join |
||
(liftA2 (^)) |
(liftA2 (^)) |
||
[2 .. 5]</ |
[2 .. 5]</syntaxhighlight> |
||
which can always be reduced (shedding imports) to the pattern: |
which can always be reduced (shedding imports) to the pattern: |
||
< |
<syntaxhighlight lang="haskell">import qualified Data.Set as S |
||
main :: IO () |
main :: IO () |
||
Line 534: | Line 534: | ||
(print . S.elems . S.fromList) $ |
(print . S.elems . S.fromList) $ |
||
(\xs -> (^) <$> xs <*> xs) |
(\xs -> (^) <$> xs <*> xs) |
||
[2 .. 5]</ |
[2 .. 5]</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 540: | Line 540: | ||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang="j">~./:~;^/~2+i.4</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
||
Line 549: | Line 549: | ||
For relatively small integers, such as involved in the specified task, the built-in function `pow/2` does the job: |
For relatively small integers, such as involved in the specified task, the built-in function `pow/2` does the job: |
||
< |
<syntaxhighlight lang="jq">[range(2;6) as $a | range(2;6) as $b | pow($a; $b)] | unique</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125] |
[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125] |
||
</pre> |
</pre> |
||
However, if using gojq, then for unbounded precision, a special-purpose "power" function is needed:< |
However, if using gojq, then for unbounded precision, a special-purpose "power" function is needed:<syntaxhighlight lang="jq">def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in); |
||
[range(2;6) as $a | range(2;6) as $b | $a|power($b)] | unique</ |
[range(2;6) as $a | range(2;6) as $b | $a|power($b)] | unique</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
As above. |
As above. |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">println(sort(unique([a^b for a in 2:5, b in 2:5])))</syntaxhighlight>{{out}} |
||
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre> |
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">Union @@ Table[a^b, {a, 2, 5}, {b, 2, 5}]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</pre> |
<pre>{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import algorithm, math, sequtils, strutils, sugar |
||
let list = collect(newSeq): |
let list = collect(newSeq): |
||
Line 575: | Line 575: | ||
for b in 2..5: a^b |
for b in 2..5: a^b |
||
echo sorted(list).deduplicate(true).join(" ")</ |
echo sorted(list).deduplicate(true).join(" ")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 581: | Line 581: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">sqpn</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sq_power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">})</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">sqpn</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sq_power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">})</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%,5d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">({</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">},</span><span style="color: #000000;">sqpn</span><span style="color: #0000FF;">),</span><span style="color: #008000;">""</span><span style="color: #0000FF;">))})</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%,5d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">({</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">},</span><span style="color: #000000;">sqpn</span><span style="color: #0000FF;">),</span><span style="color: #008000;">""</span><span style="color: #0000FF;">))})</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d found:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d found:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 596: | Line 596: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/perl -l |
||
use strict; # https://rosettacode.org/wiki/Distinct_power_numbers |
use strict; # https://rosettacode.org/wiki/Distinct_power_numbers |
||
Line 602: | Line 602: | ||
use List::Util qw( uniq ); |
use List::Util qw( uniq ); |
||
print join ', ', sort { $a <=> $b } uniq map { my $e = $_; map $_ ** $e, 2 .. 5} 2 .. 5;</ |
print join ', ', sort { $a <=> $b } uniq map { my $e = $_; map $_ ** $e, 2 .. 5} 2 .. 5;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 609: | Line 609: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">from itertools import product |
||
print(sorted(set(a**b for (a,b) in product(range(2,6), range(2,6)))))</ |
print(sorted(set(a**b for (a,b) in product(range(2,6), range(2,6)))))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre> |
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre> |
||
Line 616: | Line 616: | ||
Or, for variation, generalizing a little in terms of '''starmap''' and '''pow''': |
Or, for variation, generalizing a little in terms of '''starmap''' and '''pow''': |
||
< |
<syntaxhighlight lang="python">'''Distinct power numbers''' |
||
from itertools import product, starmap |
from itertools import product, starmap |
||
Line 647: | Line 647: | ||
# MAIN --- |
# MAIN --- |
||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main()</ |
main()</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre> |
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre> |
||
Line 653: | Line 653: | ||
=={{header|R}}== |
=={{header|R}}== |
||
This only takes one line. |
This only takes one line. |
||
< |
<syntaxhighlight lang="rsplus">unique(sort(rep(2:5, each = 4)^rep(2:5, times = 4)))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> [1] 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
<pre> [1] 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>put squish sort [X**] (2..5) xx 2;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre> |
||
Line 664: | Line 664: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
With this version of REXX, there's no need to sort the found numbers, or to eliminate duplicates. |
With this version of REXX, there's no need to sort the found numbers, or to eliminate duplicates. |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm finds and displays distinct power integers: a^b, where a and b are 2≤both≤5*/ |
||
parse arg lo hi cols . /*obtain optional arguments from the CL*/ |
parse arg lo hi cols . /*obtain optional arguments from the CL*/ |
||
if lo=='' | lo=="," then lo= 2 /*Not specified? Then use the default.*/ |
if lo=='' | lo=="," then lo= 2 /*Not specified? Then use the default.*/ |
||
Line 698: | Line 698: | ||
getMin: parse arg z .; p= 1; #= words($$) /*assume min; # words in $$.*/ |
getMin: parse arg z .; p= 1; #= words($$) /*assume min; # words in $$.*/ |
||
do m=2 for #-1; a= word($$, m); if a>=z then iterate; z= a; p= m |
do m=2 for #-1; a= word($$, m); if a>=z then iterate; z= a; p= m |
||
end /*m*/; $$= delword($$, p, 1); return /*delete the smallest number.*/</ |
end /*m*/; $$= delword($$, p, 1); return /*delete the smallest number.*/</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 736: | Line 736: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
load "stdlib.ring" |
load "stdlib.ring" |
||
Line 769: | Line 769: | ||
see "Found " + row + " numbers" + nl |
see "Found " + row + " numbers" + nl |
||
see "done..." + nl |
see "done..." + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 782: | Line 782: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">[2..5]*2 -> cartesian.map_2d {|a,b| a**b }.sort.uniq.say</syntaxhighlight> |
||
Alternative solution: |
Alternative solution: |
||
< |
<syntaxhighlight lang="ruby">2..5 ~X** 2..5 -> sort.uniq.say</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 794: | Line 794: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/seq" for Lst |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
Line 808: | Line 808: | ||
System.print("Ordered distinct values of a ^ b for a in [2..5] and b in [2..5]:") |
System.print("Ordered distinct values of a ^ b for a in [2..5] and b in [2..5]:") |
||
for (chunk in Lst.chunks(pows, 5)) Fmt.print("$,5d", chunk) |
for (chunk in Lst.chunks(pows, 5)) Fmt.print("$,5d", chunk) |
||
System.print("\nFound %(pows.count) such numbers.")</ |
System.print("\nFound %(pows.count) such numbers.")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 821: | Line 821: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">int A, B, N, Last, Next; |
||
[Last:= 0; |
[Last:= 0; |
||
loop [Next:= -1>>1; \infinity |
loop [Next:= -1>>1; \infinity |
||
Line 833: | Line 833: | ||
Last:= Next; |
Last:= Next; |
||
]; |
]; |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |