Distinct power numbers: Difference between revisions

m
(Added XPL0 example.)
m (→‎{{header|Wren}}: Minor tidy)
 
(23 intermediate revisions by 17 users not shown)
Line 7:
<br>4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">print(sorted(Array(Set(cart_product(2..5, 2..5).map((a, b) -> a ^ b)))))</syntaxhighlight>
 
{{out}}
<pre>
[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]
</pre>
 
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<syntaxhighlight lang="action!">INCLUDE "D2:SORT.ACT" ;from the Action! Tool Kit
 
INT FUNC Power(INT a,b)
INT res,i
 
res=1
FOR i=1 TO b
DO
res==*a
OD
RETURN (res)
 
BYTE FUNC Contains(INT ARRAY a INT count,x)
INT i
 
FOR i=0 TO count-1
DO
IF a(i)=x THEN
RETURN (1)
FI
OD
RETURN (0)
 
PROC Main()
INT ARRAY a(100)
INT i,j,x,count
 
Put(125) PutE() ;clear the screen
 
count=0
FOR i=2 TO 5
DO
FOR j=2 TO 5
DO
x=Power(i,j)
IF Contains(a,count,x)=0 THEN
a(count)=x
count==+1
FI
OD
OD
SortI(a,count,0)
FOR i=0 TO count-1
DO
PrintI(a(i)) Put(32)
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Distinct_power_numbers.png Screenshot from Atari 8-bit computer]
<pre>
4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_Io;
with Ada.Containers.Doubly_Linked_Lists;
 
procedure Power_Numbers is
 
package Number_Lists is new Ada.Containers.Doubly_Linked_Lists (Integer);
package Number_Sorting is new Number_Lists.Generic_Sorting;
use Number_Lists, Ada.Text_Io;
 
List : Number_Lists.List;
begin
for A in 2 .. 5 loop
for B in 2 .. 5 loop
declare
R : constant Integer := A**B;
begin
if not List.Contains (R) then
List.Append (R);
end if;
end;
end loop;
end loop;
 
Number_Sorting.Sort (List);
 
for E of List loop
Put (Integer'Image (E));
Put (" ");
end loop;
New_Line;
 
end Power_Numbers;</syntaxhighlight>
{{out}}
<pre> 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 </pre>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # show in order, distinct values of a^b where 2 <= a <= b <= 5 #
INT max number = 5;
INT min number = 2;
Line 45 ⟶ 146:
OD;
print( ( newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 53 ⟶ 154:
=={{header|APL}}==
{{works with|Dyalog APL}}
<syntaxhighlight lang APL="apl">(⊂∘⍋⌷⊣)∪,∘.*⍨1+⍳4</langsyntaxhighlight>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
Line 60 ⟶ 161:
===Idiomatic===
Uses an extravagantly long list, but gets the job done quickly and easily.
<langsyntaxhighlight lang="applescript">on task()
script o
property output : {}
Line 79 ⟶ 180:
end task
 
task()</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</langsyntaxhighlight>
----
 
Line 88 ⟶ 189:
Composing a solution from generic primitives, for speed of drafting, and ease of refactoring:
 
<langsyntaxhighlight lang="applescript">use framework "Foundation"
use scripting additions
 
Line 167 ⟶ 268:
((current application's NSArray's arrayWithArray:xs)'s ¬
sortedArrayUsingSelector:"compare:") as list
end sort</langsyntaxhighlight>
{{Out}}
<pre>{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</pre>
Line 173 ⟶ 274:
===AppleScriptObjC===
Throwing together a solution using the most appropriate methods for efficiency and legibility.
<langsyntaxhighlight lang="applescript">use AppleScript version "2.4" -- Mac OS X 10.10 (Yosemite) or later.
use framework "Foundation"
 
Line 190 ⟶ 291:
end task
 
task()</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">print sort unique flatten map 2..5 'a [
map 2..5 'b -> a^b
]</syntaxhighlight>
 
{{out}}
 
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let pow(n, p) =
Line 224 ⟶ 335:
if i=0 | v!i ~= v!(i-1) do writef("%N ", v!i)
wrch('*N')
$)</langsyntaxhighlight>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">∧⍷⥊⋆⌜˜ 2+↕4</syntaxhighlight>
{{out}}
<pre>⟨ 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 ⟩</pre>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <math.h>
Line 255 ⟶ 371:
printf("\n");
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <set>
#include <cmath>
Line 275 ⟶ 391:
std::cout << std::endl;
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
set[for n in 2..5 do for g in 2..5->pown n g]|>Set.iter(printf "%d ")
</syntaxhighlight>
</lang>
{{out}}
<pre>
4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Classes,SysUtils,StdCtrls,Math}}
Uses Delphi's standard StringList control to avoid duplicates and keep the list storted. It uses a trick to make the strings sorted numerically. The number strings are stored with leading zeros to make them sort numericall and the actual number is stored as an object so it can be retrieved without the leading zeros.
 
<syntaxhighlight lang="Delphi">
 
procedure FindDistinctPowers(Memo: TMemo);
{Display list of numbers a^b sort and exclude duplicates}
{tricks Delphi TStringGrid into sorting numerically}
var A,B,I,P: integer;
var SL: TStringList;
begin
SL:=TStringList.Create;
try
SL.Duplicates:=dupIgnore;
SL.Sorted:=True;
for A:=2 to 5 do
for B:=2 to 5 do
begin
P:=Trunc(Power(A,B));
{Add leading zeros to number so it sorts numerically}
SL.AddObject(FormatFloat('00000',P),Pointer(P));
end;
Memo.Text:=IntToStr(integer(SL.Objects[0]));
for I:=1 to SL.Count-1 do Memo.Text:=Memo.Text+','+IntToStr(integer(SL.Objects[I]));
finally SL.Free; end;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125
 
</pre>
 
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang="factor">USING: kernel math.functions math.ranges prettyprint sequences
sets sorting ;
 
2 5 [a,b] dup [ ^ ] cartesian-map concat members natural-sort .</langsyntaxhighlight>
{{out}}
<pre>
{ 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 }
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
redim arr(-1) as uinteger
dim as uinteger i
for a as uinteger = 2 to 5
for b as uinteger = 2 to 5
redim preserve arr(0 to ubound(arr)+1)
i = ubound(arr)
arr(i) = a^b
while arr(i-1)>arr(i) and i > 0
swap arr(i-1), arr(i)
i -= 1
wend
next b
next a
 
for i = 0 to ubound(arr)
if arr(i)<>arr(i-1) then print arr(i),
next i
</syntaxhighlight>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 336 ⟶ 511:
}
fmt.Println("\nFound", len(pows), "such numbers.")
}</langsyntaxhighlight>
 
{{out}}
Line 349 ⟶ 524:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import qualified Data.Set as S
 
 
Line 364 ⟶ 539:
main =
print $
distinctPowerNumbers 2 5</langsyntaxhighlight>
{{Out}}
<pre>[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]</pre>
Line 371 ⟶ 546:
or, as a one-off list comprehension:
 
<langsyntaxhighlight lang="haskell">import qualified Data.Set as S
 
main :: IO ()
main =
(print . S.elems . S.fromList) $
(\xs -> [x ^ y | x <- xs, y <- xs]) [2 .. 5]</langsyntaxhighlight>
 
or a liftA2 expression:
<langsyntaxhighlight lang="haskell">import Control.Applicative (liftA2)
import Control.Monad (join)
import qualified Data.Set as S
Line 388 ⟶ 563:
join
(liftA2 (^))
[2 .. 5]</langsyntaxhighlight>
 
which can always be reduced (shedding imports) to the pattern:
<langsyntaxhighlight lang="haskell">import qualified Data.Set as S
 
main :: IO ()
Line 397 ⟶ 572:
(print . S.elems . S.fromList) $
(\xs -> (^) <$> xs <*> xs)
[2 .. 5]</langsyntaxhighlight>
 
{{Out}}
Line 403 ⟶ 578:
 
=={{header|J}}==
<langsyntaxhighlight lang="j">~./:~;^/~2+i.4</langsyntaxhighlight>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
Line 412 ⟶ 587:
 
For relatively small integers, such as involved in the specified task, the built-in function `pow/2` does the job:
<langsyntaxhighlight lang="jq">[range(2;6) as $a | range(2;6) as $b | pow($a; $b)] | unique</langsyntaxhighlight>
{{out}}
<pre>
[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]
</pre>
However, if using gojq, then for unbounded precision, a special-purpose "power" function is needed:<langsyntaxhighlight 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</langsyntaxhighlight>
{{out}}
As above.
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">println(sort(unique([a^b for a in 2:5, b in 2:5])))</langsyntaxhighlight>{{out}}
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Union @@ Table[a^b, {a, 2, 5}, {b, 2, 5}]</syntaxhighlight>
{{out}}
<pre>{4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125}</pre>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import algorithm, math, sequtils, strutils, sugar
 
let list = collect(newSeq):
Line 433 ⟶ 613:
for b in 2..5: a^b
 
echo sorted(list).deduplicate(true).join(" ")</langsyntaxhighlight>
 
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">module IntSet = Set.Make(Int)
 
let pow x =
let rec aux acc b = function
| 0 -> acc
| y -> aux (if y land 1 = 0 then acc else acc * b) (b * b) (y lsr 1)
in
aux 1 x
 
let distinct_powers first count =
let sq = Seq.(take count (ints first)) in
IntSet.of_seq (Seq.map_product pow sq sq)
 
let () = distinct_powers 2 4
(* output *)
|> IntSet.to_seq |> Seq.map string_of_int
|> List.of_seq |> String.concat " " |> print_endline</syntaxhighlight>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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: #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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 454 ⟶ 655:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl -l
 
use strict; # https://rosettacode.org/wiki/Distinct_power_numbers
Line 460 ⟶ 661:
use List::Util qw( uniq );
 
print join ', ', sort { $a <=> $b } +uniq map { my $e = $_; map $_ ** $e, 2 .. 5} 2 .. 5;</syntaxhighlight>
my $e = $_; map $_ ** $e, 2 .. 5} 2 .. 5;</lang>
{{out}}
<pre>
Line 468 ⟶ 668:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">from itertools import product
print(sorted(set(a**b for (a,b) in product(range(2,6), range(2,6)))))</langsyntaxhighlight>
{{out}}
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre>
Line 475 ⟶ 675:
 
Or, for variation, generalizing a little in terms of '''starmap''' and '''pow''':
<langsyntaxhighlight lang="python">'''Distinct power numbers'''
 
from itertools import product, starmap
Line 506 ⟶ 706:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]</pre>
 
=={{header|R}}==
This only takes one line.
<syntaxhighlight lang="rsplus">unique(sort(rep(2:5, each = 4)^rep(2:5, times = 4)))</syntaxhighlight>
{{out}}
<pre> [1] 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ [] swap
behead swap
witheach
[ 2dup = iff
drop done
dip join ]
join ] is unique ( [ --> [ )
 
[]
4 times
[ i 2 +
4 times
[ dup i 2 + **
rot join swap ]
drop ]
sort unique echo</syntaxhighlight>
 
{{out}}
 
<pre>[ 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 ]</pre>
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>put squish sort [X**] (2..5) xx 2;</langsyntaxhighlight>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|REXX}}==
With this version of REXX, &nbsp; there's no need to sort the found numbers, &nbsp; or to eliminate duplicates.
<langsyntaxhighlight 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*/
if lo=='' | lo=="," then lo= 2 /*Not specified? Then use the default.*/
if hi=='' | hi=="," then hi= 5 /* " " " " " " */
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 1011 /*width of a number in any column. */
title= ' distinct power integers, a^b, where a and b are: ' lo "≤ both ≤" hi
say ' index │'center(title, 1 + cols*(w+1) )
say '───────┼'center("" , 1 + cols*(w+1), '─')
@.= .; mx= 0 $$= /*the default value for the @. array.*/
do a=lo to hi /*traipse through A values (LO──►HI).*/
do b=lo to hi /* " " B " " " */
x= a ** b; if @.x\==. then iterate /*Has it been found before? Then skip.*/
@.x= x; mx$$= max(mx,$$ x) /*assign the power product; fixappend to $$ the max*/
end /*b*/
end /*a*/
found$= 0; idx= 1 /*initialize$$: a list #of distinct power integers.*/
do j=1 while words($$)>0; call getMin $$ /*obtain smallest number in the $$ list*/
$= /*a list of distinct power integers. */
$= $ right(commas(z), max(w, length(z) ) ) /*add a distinct power number ──► list.*/
do j=0 for mx+1; if @.j==. then iterate /*Number not found in 1st DO loop? Skip*/
if foundj//cols\==0 found +then iterate 1; c= commas(j) /*maybe add commas tohave thewe number.populated a line of output? */
say $= $ rightcenter(cidx, max7)'│' substr(w$, length(c2) ) ) ; $= /*adddisplay awhat distinctwe powerhave numberso ──►far list (cols). */
idx= ifidx + found//cols\==0 then iterate /*havebump wethe populated aindex line ofcount output?for the output*/
end /*j*/
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
end /*j*/
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(foundj-1) title
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
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
end /*m*/; $$= delword($$, p, 1); return /*delete the smallest number.*/</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
index │ distinct power integers, a^b, where a and b are: 2 ≤ both ≤ 5
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 4 8 9 16 25 27 32 64 81 125
11 │ 243 256 625 1,024 3,125
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 15 distinct power integers, a^b, where a and b are: 2 ≤ both ≤ 5
</pre>
 
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 0 &nbsp; 5 </tt>}}
<pre>
index │ distinct power integers, a^b, where a and b are: 0 ≤ both ≤ 5
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 0 1 2 3 4 5 8 9 16 25
11 │ 27 32 64 81 125 243 256 625 1,024 3,125
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
</pre>
 
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 0 &nbsp; 9 </tt>}}
<pre>
index │ distinct power integers, a^b, where a and b are: 0 ≤ both ≤ 9
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 0 1 2 3 4 5 6 7 8 9
11 │ 16 25 27 32 36 49 64 81 125 128
21 │ 216 243 256 343 512 625 729 1,024 1,296 2,187
31 │ 2,401 3,125 4,096 6,561 7,776 15,625 16,384 16,807 19,683 32,768
41 │ 46,656 59,049 65,536 78,125 117,649 262,144 279,936 390,625 531,441 823,543
51 │ 1,679,616 1,953,125 2,097,152 4,782,969 5,764,801 10,077,696 16,777,216 40,353,607 43,046,721 134,217,728
61 │ 387,420,489
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 61 distinct power integers, a^b, where a and b are: 0 ≤ both ≤ 9
</pre>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 595 ⟶ 851:
see "Found " + row + " numbers" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 605 ⟶ 861:
Found 15 numbers
done...
</pre>
 
=={{header|RPL}}==
≪ { }
2 5 '''FOR''' a
2 5 '''FOR''' b
a b ^
'''IF''' DUP2 POS '''THEN''' DROP '''ELSE''' + '''END'''
'''NEXT NEXT''' SORT
≫ '<span style="color:blue">DPOWR</span>' STO
{{out}}
<pre>
1: { 4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125 }
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">a = (2..5).to_a
p a.product(a).map{_1 ** _2}.sort.uniq</syntaxhighlight>
{{out}}
<pre>
[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]
</pre>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">[2..5]*2 -> cartesian.map_2d {|a,b| a**b }.sort.uniq.say</langsyntaxhighlight>
 
Alternative solution:
<langsyntaxhighlight lang="ruby">2..5 ~X** 2..5 -> sort.uniq.say</langsyntaxhighlight>
{{out}}
<pre>
Line 620 ⟶ 896:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./seq" for Lst
import "./fmt" for Fmt
 
var pows = []
Line 633 ⟶ 909:
pows = Lst.distinct(pows).sort()
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.printtprint("$,5d", chunkpows, 5)
System.print("\nFound %(pows.count) such numbers.")</langsyntaxhighlight>
 
{{out}}
Line 647 ⟶ 923:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">int A, B, N, Last, Next;
[Last:= 0;
loop [Next:= -1>>1; \infinity
Line 659 ⟶ 935:
Last:= Next;
];
]</langsyntaxhighlight>
 
{{out}}
9,476

edits