Datasets:
task_url
stringlengths 30
116
| task_name
stringlengths 2
86
| task_description
stringlengths 0
14.4k
| language_url
stringlengths 2
53
| language_name
stringlengths 1
52
| code
stringlengths 0
61.9k
|
---|---|---|---|---|---|
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #ALGOL_68 | ALGOL 68 | BEGIN # find all primes with strictly increasing digits #
PR read "primes.incl.a68" PR # include prime utilities #
PR read "rows.incl.a68" PR # include array utilities #
[ 1 : 512 ]INT primes; # there will be at most 512 (2^9) primes #
INT p count := 0; # number of primes found so far #
FOR d1 FROM 0 TO 1 DO
INT n1 = d1;
FOR d2 FROM 0 TO 1 DO
INT n2 = IF d2 = 1 THEN ( n1 * 10 ) + 2 ELSE n1 FI;
FOR d3 FROM 0 TO 1 DO
INT n3 = IF d3 = 1 THEN ( n2 * 10 ) + 3 ELSE n2 FI;
FOR d4 FROM 0 TO 1 DO
INT n4 = IF d4 = 1 THEN ( n3 * 10 ) + 4 ELSE n3 FI;
FOR d5 FROM 0 TO 1 DO
INT n5 = IF d5 = 1 THEN ( n4 * 10 ) + 5 ELSE n4 FI;
FOR d6 FROM 0 TO 1 DO
INT n6 = IF d6 = 1 THEN ( n5 * 10 ) + 6 ELSE n5 FI;
FOR d7 FROM 0 TO 1 DO
INT n7 = IF d7 = 1 THEN ( n6 * 10 ) + 7 ELSE n6 FI;
FOR d8 FROM 0 TO 1 DO
INT n8 = IF d8 = 1 THEN ( n7 * 10 ) + 8 ELSE n7 FI;
FOR d9 FROM 0 TO 1 DO
INT n9 = IF d9 = 1 THEN ( n8 * 10 ) + 9 ELSE n8 FI;
IF n9 > 0 THEN
IF is probably prime( n9 ) THEN
# have a prime with strictly ascending digits #
primes[ p count +:= 1 ] := n9
FI
FI
OD
OD
OD
OD
OD
OD
OD
OD
OD;
QUICKSORT primes FROMELEMENT 1 TOELEMENT p count; # sort the primes #
FOR i TO p count DO # display the primes #
print( ( " ", whole( primes[ i ], -8 ) ) );
IF i MOD 10 = 0 THEN print( ( newline ) ) FI
OD
END |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Arturo | Arturo | ascending?: function [x][
initial: digits x
and? [equal? sort initial initial][equal? size initial size unique initial]
]
candidates: select (1..1456789) ++ [
12345678, 12345679, 12345689, 12345789, 12346789,
12356789, 12456789, 13456789, 23456789, 123456789
] => prime?
ascendingNums: select candidates => ascending?
loop split.every:10 ascendingNums 'nums [
print map nums 'num -> pad to :string num 10
] |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #AWK | AWK |
# syntax: GAWK -f ASCENDING_PRIMES.AWK
BEGIN {
start = 1
stop = 23456789
for (i=start; i<=stop; i++) {
if (is_prime(i)) {
primes++
leng = length(i)
flag = 1
for (j=1; j<leng; j++) {
if (substr(i,j,1) >= substr(i,j+1,1)) {
flag = 0
break
}
}
if (flag) {
printf("%9d%1s",i,++count%10?"":"\n")
}
}
}
printf("\n%d-%d: %d primes, %d ascending primes\n",start,stop,primes,count)
exit(0)
}
function is_prime(n, d) {
d = 5
if (n < 2) { return(0) }
if (n % 2 == 0) { return(n == 2) }
if (n % 3 == 0) { return(n == 3) }
while (d*d <= n) {
if (n % d == 0) { return(0) }
d += 2
if (n % d == 0) { return(0) }
d += 4
}
return(1)
}
|
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #F.23 | F# |
// Ascending primes. Nigel Galloway: April 19th., 2022
[2;3;5;7]::List.unfold(fun(n,i)->match n with []->None |_->let n=n|>List.map(fun(n,g)->[for n in n.. -1..1->(n-1,i*n+g)])|>List.concat in Some(n|>List.choose(fun(_,n)->if isPrime n then Some n else None),(n|>List.filter(fst>>(<)0),i*10)))([(2,3);(6,7);(8,9)],10)
|>List.concat|>List.sort|>List.iter(printf "%d "); printfn ""
|
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Factor | Factor | USING: grouping math math.combinatorics math.functions
math.primes math.ranges prettyprint sequences sequences.extras ;
9 [1,b] all-subsets [ reverse 0 [ 10^ * + ] reduce-index ]
[ prime? ] map-filter 10 group simple-table. |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Go | Go | package main
import (
"fmt"
"rcu"
"sort"
)
var ascPrimesSet = make(map[int]bool) // avoids duplicates
func generate(first, cand, digits int) {
if digits == 0 {
if rcu.IsPrime(cand) {
ascPrimesSet[cand] = true
}
return
}
for i := first; i < 10; i++ {
next := cand*10 + i
generate(i+1, next, digits-1)
}
}
func main() {
for digits := 1; digits < 10; digits++ {
generate(1, 0, digits)
}
le := len(ascPrimesSet)
ascPrimes := make([]int, le)
i := 0
for k := range ascPrimesSet {
ascPrimes[i] = k
i++
}
sort.Ints(ascPrimes)
fmt.Println("There are", le, "ascending primes, namely:")
for i := 0; i < le; i++ {
fmt.Printf("%8d ", ascPrimes[i])
if (i+1)%10 == 0 {
fmt.Println()
}
}
} |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #J | J | extend=: {{ y;(1+each i._1+{.y),L:0 y }}
$(#~ 1 p: ])10#.&>([:~.@;extend each)^:# >:i.9
100
10 10$(#~ 1 p: ])10#.&>([:~.@;extend each)^:# >:i.9
2 3 13 23 5 7 17 37 47 67
127 137 347 157 257 457 167 367 467 1237
2347 2357 3457 1367 2467 3467 1567 4567 12347 12457
13457 13567 23567 123457 124567 19 29 59 79 89
139 239 149 349 359 269 569 179 379 479
389 1249 1259 1459 2459 3469 1279 1579 2579 4679
1289 2389 1489 2689 5689 1789 2789 4789 23459 13469
12569 12379 12479 13679 34679 15679 25679 12589 34589 12689
23689 13789 23789 123479 124679 235679 145679 345679 234589 345689
134789 125789 235789 245789 1245689 1234789 1235789 1456789 12356789 23456789
timex'(#~ 1 p: ])10#.&>([:~.@;extend each)^:# >:i.9' NB. seconds (take with grain of salt)
0.003818
|
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #jq | jq |
# Output: the stream of ascending primes, in order
def ascendingPrimes:
# Generate the stream of primes beginning with the digit .
# and with strictly ascending digits, without regard to order
def generate:
# strings
def g:
. as $first
| tonumber as $n
| select($n <= 9)
| $first,
((range($n + 1;10) | tostring | g) as $x
| $first + $x );
tostring | g | tonumber | select(is_prime);
[range(1;10) | generate] | sort[];
def task:
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
[ascendingPrimes]
| "There are \(length) ascending primes, namely:",
( _nwise(10) | map(lpad(10)) | join(" ") );
task |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Julia | Julia | using Combinatorics
using Primes
function ascendingprimes()
return filter(isprime, [evalpoly(10, reverse(x))
for x in powerset([1, 2, 3, 4, 5, 6, 7, 8, 9]) if !isempty(x)])
end
foreach(p -> print(rpad(p[2], 10), p[1] % 10 == 0 ? "\n" : ""), enumerate(ascendingprimes()))
@time ascendingprimes()
|
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Lua | Lua | local function is_prime(n)
if n < 2 then return false end
if n % 2 == 0 then return n==2 end
if n % 3 == 0 then return n==3 end
for f = 5, n^0.5, 6 do
if n%f==0 or n%(f+2)==0 then return false end
end
return true
end
local function ascending_primes()
local digits, candidates, primes = {1,2,3,4,5,6,7,8,9}, {0}, {}
for i = 1, #digits do
for j = 1, #candidates do
local value = candidates[j] * 10 + digits[i]
if is_prime(value) then primes[#primes+1] = value end
candidates[#candidates+1] = value
end
end
table.sort(primes)
return primes
end
print(table.concat(ascending_primes(), ", ")) |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | ps=Sort@Select[FromDigits /@ Subsets[Range@9, {1, \[Infinity]}], PrimeQ];
Multicolumn[ps, {Automatic, 6}, Appearance -> "Horizontal"] |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Perl | Perl | #!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/Ascending_primes
use warnings;
use ntheory qw( is_prime );
print join('', map { sprintf "%10d", $_ } sort { $a <=> $b }
grep /./ && is_prime($_),
glob join '', map "{$_,}", 1 .. 9) =~ s/.{50}\K/\n/gr; |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Phix | Phix | with javascript_semantics
function ascending_primes(sequence res, atom p=0)
for d=remainder(p,10)+1 to 9 do
integer np = p*10+d
if odd(d) and is_prime(np) then res &= np end if
res = ascending_primes(res,np)
end for
return res
end function
sequence r = apply(true,sprintf,{{"%8d"},sort(ascending_primes({2}))})
printf(1,"There are %,d ascending primes:\n%s\n",{length(r),join_by(r,1,10," ")})
|
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Picat | Picat | import util.
main =>
DP = [N : S in power_set("123456789"), S != [], N = S.to_int, prime(N)].sort,
foreach({P,I} in zip(DP,1..DP.len))
printf("%9d%s",P,cond(I mod 10 == 0,"\n",""))
end,
nl,
println(len=DP.len) |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Python | Python | from sympy import isprime
def ascending(x=0):
for y in range(x*10 + (x%10) + 1, x*10 + 10):
yield from ascending(y)
yield(y)
print(sorted(x for x in ascending() if isprime(x))) |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Quackery | Quackery | [ 0 swap witheach
[ swap 10 * + ] ] is digits->n ( [ --> n )
[]
' [ 1 2 3 4 5 6 7 8 9 ] powerset
witheach
[ digits->n dup isprime
iff join else drop ]
sort echo |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Raku | Raku | put (flat 2, 3, 5, 7, sort +*, gather (1..8).map: &recurse ).batch(10)».fmt("%8d").join: "\n";
sub recurse ($str) {
.take for ($str X~ (3, 7, 9)).grep: { .is-prime && [<] .comb };
recurse $str × 10 + $_ for $str % 10 ^.. 9;
}
printf "%.3f seconds", now - INIT now; |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Ring | Ring |
load "stdlibcore.ring"
limit = 1000
row = 0
for n = 1 to limit
flag = 0
strn = string(n)
if isprime(n) = 1
for m = 1 to len(strn)-1
if number(substr(strn,m)) > number(substr(strn,m+1))
flag = 1
ok
next
if flag = 1
row++
see "" + n + " "
ok
if row % 10 = 0
see nl
ok
ok
next
|
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Sidef | Sidef | func primes_with_ascending_digits(base = 10) {
var list = []
var digits = @(1..^base -> flip)
var end_digits = digits.grep { .is_coprime(base) }
list << digits.grep { .is_prime && !.is_coprime(base) }...
for k in (0 .. digits.end) {
digits.combinations(k, {|*a|
var v = a.digits2num(base)
end_digits.each {|d|
var n = (v*base + d)
next if ((n >= base) && (a[0] >= d))
list << n if (n.is_prime)
}
})
}
list.sort
}
var arr = primes_with_ascending_digits()
say "There are #{arr.len} ascending primes.\n"
arr.each_slice(10, {|*a|
say a.map { '%8s' % _ }.join(' ')
}) |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Vlang | Vlang | fn is_prime(n int) bool {
if n < 2 {
return false
} else if n%2 == 0 {
return n == 2
} else if n%3 == 0 {
return n == 3
} else {
mut d := 5
for d*d <= n {
if n%d == 0 {
return false
}
d += 2
if n%d == 0 {
return false
}
d += 4
}
return true
}
}
fn generate(first int, cand int, digits int, mut asc map[int]bool) {
if digits == 0 {
if is_prime(cand) {
asc[cand] = true
}
return
}
for i in first..10 {
next := cand*10 + i
generate(i+1, next, digits-1, mut asc)
}
}
fn main() {
mut asc_primes_set := map[int]bool{} // avoids duplicates
for digits in 1..10 {
generate(1, 0, digits, mut asc_primes_set)
}
le := asc_primes_set.keys().len
mut asc_primes := []int{len: le}
mut i := 0
for k,_ in asc_primes_set {
asc_primes[i] = k
i++
}
asc_primes.sort()
println("There are $le ascending primes, namely:")
for q in 0..le {
print("${asc_primes[q]:8} ")
if (q+1)%10 == 0 {
println('')
}
}
} |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #Wren | Wren | import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
var isAscending = Fn.new { |n|
if (n < 10) return true
var digits = Int.digits(n)
for (i in 1...digits.count) {
if (digits[i] <= digits[i-1]) return false
}
return true
}
var higherPrimes = []
var candidates = [
12345678, 12345679, 12345689, 12345789, 12346789,
12356789, 12456789, 13456789, 23456789, 123456789
]
for (cand in candidates) if (Int.isPrime(cand)) higherPrimes.add(cand)
var primes = Int.primeSieve(3456789)
var ascPrimes = []
for (p in primes) if (isAscending.call(p)) ascPrimes.add(p)
ascPrimes.addAll(higherPrimes)
System.print("There are %(ascPrimes.count) ascending primes, namely:")
for (chunk in Lst.chunks(ascPrimes, 10)) Fmt.print("$8d", chunk) |
http://rosettacode.org/wiki/Ascending_primes | Ascending primes | Generate and show all primes with strictly ascending decimal digits.
Aside: Try solving without peeking at existing solutions. I had a weird idea for generating
a prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial
but generating them quickly is at least mildly interesting.
Tip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is
at least one significantly better and much faster way, needing a mere 511 odd/prime tests.
See also
OEIS:A052015 - Primes with distinct digits in ascending order
Related
Primes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)
Pandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)
| #XPL0 | XPL0 | func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
func Ascending(N); \Return 'true' if digits are ascending
int N, D;
[N:= N/10;
D:= rem(0);
while N do
[N:= N/10;
if rem(0) >= D then return false;
D:= rem(0);
];
return true;
];
int Cnt, N;
[Cnt:= 0;
Format(9, 0);
for N:= 2 to 123_456_789 do
if Ascending(N) then
if IsPrime(N) then
[RlOut(0, float(N));
Cnt:= Cnt+1;
if rem(Cnt/10) = 0 then CrLf(0);
];
] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #11l | 11l | V arr1 = [1, 2, 3]
V arr2 = [4, 5, 6]
print(arr1 [+] arr2) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #68000_Assembly | 68000 Assembly | ArrayRam equ $00FF2000 ;this label points to 4k of free space.
;concatenate Array1 + Array2
LEA ArrayRam,A0
LEA Array1,A1
MOVE.W #5-1,D1 ;LEN(Array1), measured in words.
JSR memcpy_w
;after this, A0 will point to the destination of the second array.
LEA Array2,A1 ;even though the source arrays are stored back-to-back in memory, we'll assume they're not just for demonstration purposes.
MOVE.W #5-1,D1 ;LEN(Array2), measured in words
JSR memcpy_w
JMP * ;halt the CPU
memcpy_w:
MOVE.W (A1)+,(A0)+
DBRA D1,memcpy_w
rts
Array1:
DC.W 1,2,3,4,5
Array2:
DC.W 6,7,8,9,10 |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #8th | 8th |
[1,2,3] [4,5,6] a:+ .
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program concAreaString.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ NBMAXITEMS, 20 //
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessLenArea: .asciz "The length of area 3 is : @ \n"
szCarriageReturn: .asciz "\n"
/* areas strings */
szString1: .asciz "Apples"
szString2: .asciz "Oranges"
szString3: .asciz "Pommes"
szString4: .asciz "Raisins"
szString5: .asciz "Abricots"
/* pointer items area 1*/
tablesPoi1:
pt1_1: .quad szString1
pt1_2: .quad szString2
ptVoid_1: .quad 0
/* pointer items area 2*/
tablesPoi2:
pt2_1: .quad szString3
pt2_2: .quad szString4
pt2_3: .quad szString5
ptVoid_2: .quad 0
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
tablesPoi3: .skip 8 * NBMAXITEMS
sZoneConv: .skip 30
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
// copy area 1 -> area 3
ldr x1,qAdrtablesPoi1 // begin pointer area 1
ldr x3,qAdrtablesPoi3 // begin pointer area 3
mov x0,0 // counter
1:
ldr x2,[x1,x0,lsl 3] // read string pointer address item x0 (8 bytes by pointer)
cbz x2,2f // is null ?
str x2,[x3,x0,lsl 3] // no store pointer in area 3
add x0,x0,1 // increment counter
b 1b // and loop
2: // copy area 2 -> area 3
ldr x1,qAdrtablesPoi2 // begin pointer area 2
ldr x3,qAdrtablesPoi3 // begin pointer area 3
mov x4,#0 // counter area 2
3: // x0 contains the first void item in area 3
ldr x2,[x1,x4,lsl #3] // read string pointer address item x0 (8 bytes by pointer)
cbz x2,4f // is null ?
str x2,[x3,x0,lsl #3] // no store pointer in area 3
add x0,x0,1 // increment counter
add x4,x4,1 // increment counter
b 3b // and loop
4:
// count items number in area 3
ldr x1,qAdrtablesPoi3 // begin pointer table
mov x0,#0 // counter
5: // begin loop
ldr x2,[x1,x0,lsl #3] // read string pointer address item x0 (8 bytes by pointer)
cmp x2,#0 // is null ?
cinc x0,x0,ne // no increment counter
bne 5b // and loop
ldr x1,qAdrsZoneConv // conversion decimal
bl conversion10S
ldr x0,qAdrszMessLenArea
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at @ character
bl affichageMess
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrtablesPoi1: .quad tablesPoi1
qAdrtablesPoi2: .quad tablesPoi2
qAdrtablesPoi3: .quad tablesPoi3
qAdrszMessLenArea: .quad szMessLenArea
qAdrsZoneConv: .quad sZoneConv
qAdrszCarriageReturn: .quad szCarriageReturn
/****************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ABAP | ABAP |
report z_array_concatenation.
data(itab1) = value int4_table( ( 1 ) ( 2 ) ( 3 ) ).
data(itab2) = value int4_table( ( 4 ) ( 5 ) ( 6 ) ).
append lines of itab2 to itab1.
loop at itab1 assigning field-symbol(<line>).
write <line>.
endloop.
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ACL2 | ACL2 | (append xs ys) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Action.21 | Action! | BYTE FUNC Concat(INT ARRAY src1,src2,dst BYTE size1,size2)
BYTE i
FOR i=0 TO size1-1
DO
dst(i)=src1(i)
OD
FOR i=0 TO size2-1
DO
dst(size1+i)=src2(i)
OD
RETURN (size1+size2)
PROC PrintArray(INT ARRAY a BYTE size)
BYTE i
Put('[)
FOR i=0 TO size-1
DO
PrintI(a(i))
IF i<size-1 THEN
Put(' )
FI
OD
Put('])
RETURN
PROC Test(INT ARRAY src1,src2 BYTE size1,size2)
INT ARRAY res(20)
BYTE size
size=Concat(src1,src2,res,size1,size2)
PrintArray(src1,size1)
Put('+)
PrintArray(src2,size2)
Put('=)
PrintArray(res,size)
PutE() PutE()
RETURN
PROC Main()
INT ARRAY
a1=[1 2 3 4],
a2=[5 6 7 8 9 10],
;a workaround for a3=[-1 -2 -3 -4 -5]
a3=[65535 65534 65533 65532 65531]
Test(a1,a2,4,6)
Test(a2,a1,6,4)
Test(a3,a2,5,4)
RETURN |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ActionScript | ActionScript | var array1:Array = new Array(1, 2, 3);
var array2:Array = new Array(4, 5, 6);
var array3:Array = array1.concat(array2); //[1, 2, 3, 4, 5, 6] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Ada | Ada | type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6); -- Concatenate X and (4, 5, 6) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Aime | Aime | ac(list a, b)
{
list o;
o.copy(a);
b.ucall(l_append, 1, o);
o;
}
main(void)
{
list a, b, c;
a = list(1, 2, 3, 4);
b = list(5, 6, 7, 8);
c = ac(a, b);
c.ucall(o_, 1, " ");
0;
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ALGOL_68 | ALGOL 68 | MODE ARGTYPE = INT;
MODE ARGLIST = FLEX[0]ARGTYPE;
OP + = (ARGLIST a, b)ARGLIST: (
[LWB a:UPB a - LWB a + 1 + UPB b - LWB b + 1 ]ARGTYPE out;
(
out[LWB a:UPB a]:=a,
out[UPB a+1:]:=b
);
out
);
# Append #
OP +:= = (REF ARGLIST lhs, ARGLIST rhs)ARGLIST: lhs := lhs + rhs;
OP PLUSAB = (REF ARGLIST lhs, ARGLIST rhs)ARGLIST: lhs := lhs + rhs;
# Prefix #
OP +=: = (ARGLIST lhs, REF ARGLIST rhs)ARGLIST: rhs := lhs + rhs;
OP PLUSTO = (ARGLIST lhs, REF ARGLIST rhs)ARGLIST: rhs := lhs + rhs;
ARGLIST a := (1,2),
b := (3,4,5);
print(("a + b",a + b, new line));
VOID(a +:= b);
print(("a +:= b", a, new line));
VOID(a +=: b);
print(("a +=: b", b, new line)) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ALGOL_W | ALGOL W | begin
integer array a ( 1 :: 5 );
integer array b ( 2 :: 4 );
integer array c ( 1 :: 8 );
% concatenates the arrays a and b into c %
% the lower and upper bounds of each array must be specified in %
% the corresponding *Lb and *Ub parameters %
procedure arrayConcatenate ( integer array a ( * )
; integer value aLb, aUb
; integer array b ( * )
; integer value bLb, bUb
; integer array c ( * )
; integer value cLb, cUb
) ;
begin
integer cPos;
assert( ( cUb - cLb ) + 1 >= ( ( aUb + bUb ) - ( aLb + bLb ) ) - 2 );
cPos := cLb;
for aPos := aLb until aUb do begin
c( cPos ) := a( aPos );
cPos := cPos + 1
end for_aPos ;
for bPos := bLb until bUb do begin
c( cPos ) := b( bPos );
cPos := cPos + 1
end for_bPos
end arrayConcatenate ;
% test arrayConcatenate %
for aPos := 1 until 5 do a( aPos ) := aPos;
for bPos := 2 until 4 do b( bPos ) := - bPos;
arrayConcatenate( a, 1, 5, b, 2, 4, c, 1, 8 );
for cPos := 1 until 8 do writeon( i_w := 1, s_w := 1, c( cPos ) )
end. |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Amazing_Hopper | Amazing Hopper |
#include <hbasic.h>
Begin
a1 = {}
a2 = {}
Take(100,"Hola",0.056,"Mundo!"), and Push All(a1)
Take("Segundo",0,"array",~True,~False), and Push All(a2)
Concat (a1, a2) and Print ( a2, Newl )
End
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #AntLang | AntLang | a:<1; <2; 3>>
b: <"Hello"; 42>
c: a,b |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Apex | Apex | List<String> listA = new List<String> { 'apple' };
List<String> listB = new List<String> { 'banana' };
listA.addAll(listB);
System.debug(listA); // Prints (apple, banana) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #APL | APL |
1 2 3 , 4 5 6
1 2 3 4 5 6
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #AppleScript | AppleScript |
set listA to {1, 2, 3}
set listB to {4, 5, 6}
return listA & listB
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program concAreaString.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
.equ NBMAXITEMS, 20 @
/* Initialized data */
.data
szMessLenArea: .ascii "The length of area 3 is : "
sZoneconv: .fill 12,1,' '
szCarriageReturn: .asciz "\n"
/* areas strings */
szString1: .asciz "Apples"
szString2: .asciz "Oranges"
szString3: .asciz "Pommes"
szString4: .asciz "Raisins"
szString5: .asciz "Abricots"
/* pointer items area 1*/
tablesPoi1:
pt1_1: .int szString1
pt1_2: .int szString2
ptVoid_1: .int 0
/* pointer items area 2*/
tablesPoi2:
pt2_1: .int szString3
pt2_2: .int szString4
pt2_3: .int szString5
ptVoid_2: .int 0
/* UnInitialized data */
.bss
tablesPoi3: .skip 4 * NBMAXITEMS
/* code section */
.text
.global main
main: /* entry of program */
push {fp,lr} /* saves 2 registers */
@ copy area 1 -> area 3
ldr r1,iAdrtablesPoi1 @ begin pointer area 1
ldr r3,iAdrtablesPoi3 @ begin pointer area 3
mov r0,#0 @ counter
1:
ldr r2,[r1,r0,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
cmp r2,#0 @ is null ?
strne r2,[r3,r0,lsl #2] @ no store pointer in area 3
addne r0,#1 @ increment counter
bne 1b @ and loop
@ copy area 2 -> area 3
ldr r1,iAdrtablesPoi2 @ begin pointer area 2
ldr r3,iAdrtablesPoi3 @ begin pointer area 3
mov r4,#0 @ counter area 2
2: @ r0 contains the first void item in area 3
ldr r2,[r1,r4,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
cmp r2,#0 @ is null ?
strne r2,[r3,r0,lsl #2] @ no store pointer in area 3
addne r0,#1 @ increment counter
addne r4,#1 @ increment counter
bne 2b @ and loop
@ count items number in area 3
ldr r1,iAdrtablesPoi3 @ begin pointer table
mov r0,#0 @ counter
3: @ begin loop
ldr r2,[r1,r0,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
cmp r2,#0 @ is null ?
addne r0,#1 @ no increment counter
bne 3b @ and loop
ldr r1,iAdrsZoneconv @ conversion decimal
bl conversion10S
ldr r0,iAdrszMessLenArea
bl affichageMess
100: /* standard end of the program */
mov r0, #0 @ return code
pop {fp,lr} @restaur 2 registers
mov r7, #EXIT @ request to exit program
swi 0 @ perform the system call
iAdrtablesPoi1: .int tablesPoi1
iAdrtablesPoi2: .int tablesPoi2
iAdrtablesPoi3: .int tablesPoi3
iAdrszMessLenArea: .int szMessLenArea
iAdrsZoneconv: .int sZoneconv
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {fp,lr} /* save registres */
push {r0,r1,r2,r7} /* save others registers */
mov r2,#0 /* counter length */
1: /* loop length calculation */
ldrb r1,[r0,r2] /* read octet start position + index */
cmp r1,#0 /* if 0 its over */
addne r2,r2,#1 /* else add 1 in the length */
bne 1b /* and loop */
/* so here r2 contains the length of the message */
mov r1,r0 /* address message in r1 */
mov r0,#STDOUT /* code to write to the standard output Linux */
mov r7, #WRITE /* code call system "write" */
swi #0 /* call systeme */
pop {r0,r1,r2,r7} /* restaur others registers */
pop {fp,lr} /* restaur des 2 registres */
bx lr /* return */
/***************************************************/
/* conversion register signed décimal */
/***************************************************/
/* r0 contient le registre */
/* r1 contient l adresse de la zone de conversion */
conversion10S:
push {r0-r5,lr} /* save des registres */
mov r2,r1 /* debut zone stockage */
mov r5,#'+' /* par defaut le signe est + */
cmp r0,#0 /* nombre négatif ? */
movlt r5,#'-' /* oui le signe est - */
mvnlt r0,r0 /* et inversion en valeur positive */
addlt r0,#1
mov r4,#10 /* longueur de la zone */
1: /* debut de boucle de conversion */
bl divisionpar10 /* division */
add r1,#48 /* ajout de 48 au reste pour conversion ascii */
strb r1,[r2,r4] /* stockage du byte en début de zone r5 + la position r4 */
sub r4,r4,#1 /* position précedente */
cmp r0,#0
bne 1b /* boucle si quotient different de zéro */
strb r5,[r2,r4] /* stockage du signe à la position courante */
subs r4,r4,#1 /* position précedente */
blt 100f /* si r4 < 0 fin */
/* sinon il faut completer le debut de la zone avec des blancs */
mov r3,#' ' /* caractere espace */
2:
strb r3,[r2,r4] /* stockage du byte */
subs r4,r4,#1 /* position précedente */
bge 2b /* boucle si r4 plus grand ou egal a zero */
100: /* fin standard de la fonction */
pop {r0-r5,lr} /*restaur desregistres */
bx lr
/***************************************************/
/* division par 10 signé */
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
/* and http://www.hackersdelight.org/ */
/***************************************************/
/* r0 contient le dividende */
/* r0 retourne le quotient */
/* r1 retourne le reste */
divisionpar10:
/* r0 contains the argument to be divided by 10 */
push {r2-r4} /* save registers */
mov r4,r0
ldr r3, .Ls_magic_number_10 /* r1 <- magic_number */
smull r1, r2, r3, r0 /* r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0) */
mov r2, r2, ASR #2 /* r2 <- r2 >> 2 */
mov r1, r0, LSR #31 /* r1 <- r0 >> 31 */
add r0, r2, r1 /* r0 <- r2 + r1 */
add r2,r0,r0, lsl #2 /* r2 <- r0 * 5 */
sub r1,r4,r2, lsl #1 /* r1 <- r4 - (r2 * 2) = r4 - (r0 * 10) */
pop {r2-r4}
bx lr /* leave function */
bx lr /* leave function */
.Ls_magic_number_10: .word 0x66666667
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Arturo | Arturo | arr1: [1 2 3]
arr2: ["four" "five" "six"]
print arr1 ++ arr2 |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ATS | ATS | (* The Rosetta Code array concatenation task, in ATS2. *)
(* In a way, the task is misleading: in a language such as ATS, one
can always devise a very-easy-to-use array type, put the code for
that in a library, and overload operators. Thus we can have
"array1 + array2" as array concatenation in ATS, complete with
garbage collection when the result no longer is needed.
It depends on what libraries are in one's repertoire.
Nevertheless, it seems fair to demonstrate how to concatenate two
barebones arrays at the nitpicking lowest level, without anything
but the barest contents of the ATS2 prelude. It will make ATS
programming look difficult; but ATS programming *is* difficult,
when you are using it to overcome the programming safety
deficiencies of a language such as C, without losing the runtime
efficiency of C code.
What we want is the kind of routine that would be used *in the
implementation* of "array1 + array2". So let us begin ... *)
#include "share/atspre_staload.hats" (* Loads some needed template
code. *)
fn {t : t@ype}
(* The demonstration will be for arrays of a non-linear type t. Were
the arrays to contain a *linear* type (vt@ype), then either the old
arrays would have to be destroyed or a copy procedure would be
needed for the elements. *)
arrayconcat1 {m, n : nat}
{pa, pb, pc : addr}
(pfa : !(@[t][m]) @ pa,
pfb : !(@[t][n]) @ pb,
pfc : !(@[t?][m + n]) @ pc >> @[t][m + n] @ pc |
pa : ptr pa,
pb : ptr pb,
pc : ptr pc,
m : size_t m,
n : size_t n) : void =
(* The routine takes as arguments three low-level arrays, passed by
value, as pointers with associated views. The first array is of
length m, with elements of type t, and the array must have been
initialized; the second is a similar array of length n. The third
array is uninitialized (thus the "?" character) and must have
length m+n; its type will change to "initialized". *)
{
prval (pfleft, pfright) = array_v_split {t?} {pc} {m + n} {m} pfc
(* We have had to split the view of array c into a left part pfleft,
of length m, and a right part pfright of length n. Arrays a and b
will be copied into the respective parts of c. *)
val _ = array_copy<t> (!pc, !pa, m)
val _ = array_copy<t> (!(ptr_add<t> (pc, m)), !pb, n)
(* Copying an array *safely* is more complex than what we are doing
here, but above the task has been given to the "array_copy"
template in the prelude. The "!" signs appear because array_copy is
call-by-reference but we are passing it pointers. *)
(* pfleft and pfright now refer to *initialized* arrays: one of length
m, starting at address pc; the other of length n, starting at
address pc+(m*sizeof<t>). *)
prval _ = pfc := array_v_unsplit {t} {pc} {m, n} (pfleft, pfright)
(* Before we can exit, the view of array c has to be replaced. It is
replaced by "unsplitting" the (now initialized) left and right
parts of the array. *)
(* We are done. Everything should now work, and the result will be
safe from buffer overruns or underruns, and against accidental
misuse of uninitialized data. *)
}
(* arrayconcat2 is a pass-by-reference interface to arrayconcat1. *)
fn {t : t@ype}
arrayconcat2 {m, n : nat}
(a : &(@[t][m]),
b : &(@[t][n]),
c : &(@[t?][m + n]) >> @[t][m + n],
m : size_t m,
n : size_t n) : void =
arrayconcat1 (view@ a, view@ b, view@ c |
addr@ a, addr@ b, addr@ c, m, n)
(* Overloads to let you say "arrayconcat" for either routine above. *)
overload arrayconcat with arrayconcat1
overload arrayconcat with arrayconcat2
implement
main0 () =
(* A demonstration program. *)
let
(* Some arrays on the stack. Because they are on the stack, they
will not need explicit freeing. *)
var a = @[int][3] (1, 2, 3)
var b = @[int][4] (5, 6, 7, 8)
var c : @[int?][7]
in
(* Compute c as the concatenation of a and b. *)
arrayconcat<int> (a, b, c, i2sz 3, i2sz 4);
(* The following simply prints the result. *)
let
(* Copy c to a linear linked list, because the prelude provides
means to easily print such a list. *)
val lst = array2list (c, i2sz 7)
in
println! (lst); (* Print the list. *)
free lst (* The list is linear and must be freed. *)
end
end |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #AutoHotkey | AutoHotkey | List1 := [1, 2, 3]
List2 := [4, 5, 6]
cList := Arr_concatenate(List1, List2)
MsgBox % Arr_disp(cList) ; [1, 2, 3, 4, 5, 6]
Arr_concatenate(p*) {
res := Object()
For each, obj in p
For each, value in obj
res.Insert(value)
return res
}
Arr_disp(arr) {
for each, value in arr
res .= ", " value
return "[" SubStr(res, 3) "]"
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #AutoIt | AutoIt |
_ArrayConcatenate($avArray, $avArray2)
Func _ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource, $iStart = 0)
If Not IsArray($avArrayTarget) Then Return SetError(1, 0, 0)
If Not IsArray($avArraySource) Then Return SetError(2, 0, 0)
If UBound($avArrayTarget, 0) <> 1 Then
If UBound($avArraySource, 0) <> 1 Then Return SetError(5, 0, 0)
Return SetError(3, 0, 0)
EndIf
If UBound($avArraySource, 0) <> 1 Then Return SetError(4, 0, 0)
Local $iUBoundTarget = UBound($avArrayTarget) - $iStart, $iUBoundSource = UBound($avArraySource)
ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]
For $i = $iStart To $iUBoundSource - 1
$avArrayTarget[$iUBoundTarget + $i] = $avArraySource[$i]
Next
Return $iUBoundTarget + $iUBoundSource
EndFunc ;==>_ArrayConcatenate
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Avail | Avail | <1, 2, 3> ++ <¢a, ¢b, ¢c> |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #AWK | AWK | #!/usr/bin/awk -f
BEGIN {
split("cul-de-sac",a,"-")
split("1-2-3",b,"-")
concat_array(a,b,c)
for (i in c) {
print i,c[i]
}
}
function concat_array(a,b,c, nc) {
for (i in a) {
c[++nc]=a[i]
}
for (i in b) {
c[++nc]=b[i]
}
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Babel | Babel | [1 2 3] [4 5 6] cat ; |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #bash | bash | x=("1 2" "3 4")
y=(5 6)
sum=( "${x[@]}" "${y[@]}" )
for i in "${sum[@]}" ; do echo "$i" ; done
1 2
3 4
5
6 |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #BASIC | BASIC | DECLARE a[] = { 1, 2, 3, 4, 5 }
DECLARE b[] = { 6, 7, 8, 9, 10 }
DECLARE c ARRAY UBOUND(a) + UBOUND(b)
FOR x = 0 TO 4
c[x] = a[x]
c[x+5] = b[x]
NEXT |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #BASIC256 | BASIC256 | arraybase 1
global c
dimen = 5
dim a(dimen)
dim b(dimen)
# Array initialization
for i = 1 to dimen
a[i] = i
b[i] = i + dimen
next i
nt = ConcatArrays(a, b)
for i = 1 to nt
print c[i];
if i < nt then print ", ";
next i
end
function ConcatArrays(a, b)
ta = a[?]
tb = b[?]
nt = ta + tb
redim c(nt)
for i = 1 to ta
c[i] = a[i]
next i
for i = 1 to tb
c[i + ta] = b[i]
next i
return nt
end function |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #BQN | BQN | 1‿2‿3 ∾ 4‿5‿6 |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Bracmat | Bracmat | {?} (a,b,c,d,e),(n,m)
{!} a,b,c,d,e,n,m
{?} (a,m,y),(b,n,y,z)
{!} a,m,y,b,n,y,z
{?} (a m y) (b n y z)
{!} a m y b n y z
{?} (a+m+y)+(b+n+y+z)
{!} a+b+m+n+2*y+z
{?} (a*m*y)*(b*n*y*z)
{!} a*b*m*n*y^2*z |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Burlesque | Burlesque |
blsq ) {1 2 3}{4 5 6}_+
{1 2 3 4 5 6}
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #C | C | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define ARRAY_CONCAT(TYPE, A, An, B, Bn) \
(TYPE *)array_concat((const void *)(A), (An), (const void *)(B), (Bn), sizeof(TYPE));
void *array_concat(const void *a, size_t an,
const void *b, size_t bn, size_t s)
{
char *p = malloc(s * (an + bn));
memcpy(p, a, an*s);
memcpy(p + an*s, b, bn*s);
return p;
}
// testing
const int a[] = { 1, 2, 3, 4, 5 };
const int b[] = { 6, 7, 8, 9, 0 };
int main(void)
{
unsigned int i;
int *c = ARRAY_CONCAT(int, a, 5, b, 5);
for(i = 0; i < 10; i++)
printf("%d\n", c[i]);
free(c);
return EXIT_SUCCCESS;
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #C.23 | C# | using System;
namespace RosettaCode
{
class Program
{
static void Main(string[] args)
{
int[] a = { 1, 2, 3 };
int[] b = { 4, 5, 6 };
int[] c = new int[a.Length + b.Length];
a.CopyTo(c, 0);
b.CopyTo(c, a.Length);
foreach(int n in c)
{
Console.WriteLine(n.ToString());
}
}
}
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #C.2B.2B | C++ | #include <vector>
#include <iostream>
int main()
{
std::vector<int> a(3), b(4);
a[0] = 11; a[1] = 12; a[2] = 13;
b[0] = 21; b[1] = 22; b[2] = 23; b[3] = 24;
a.insert(a.end(), b.begin(), b.end());
for (int i = 0; i < a.size(); ++i)
std::cout << "a[" << i << "] = " << a[i] << "\n";
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Ceylon | Ceylon | shared void arrayConcatenation() {
value a = Array {1, 2, 3};
value b = Array {4, 5, 6};
value c = concatenate(a, b);
print(c);
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Clojure | Clojure | (concat [1 2 3] [4 5 6]) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #COBOL | COBOL | identification division.
program-id. array-concat.
environment division.
configuration section.
repository.
function all intrinsic.
data division.
working-storage section.
01 table-one.
05 int-field pic 999 occurs 0 to 5 depending on t1.
01 table-two.
05 int-field pic 9(4) occurs 0 to 10 depending on t2.
77 t1 pic 99.
77 t2 pic 99.
77 show pic z(4).
procedure division.
array-concat-main.
perform initialize-tables
perform concatenate-tables
perform display-result
goback.
initialize-tables.
move 4 to t1
perform varying tally from 1 by 1 until tally > t1
compute int-field of table-one(tally) = tally * 3
end-perform
move 3 to t2
perform varying tally from 1 by 1 until tally > t2
compute int-field of table-two(tally) = tally * 6
end-perform
.
concatenate-tables.
perform varying tally from 1 by 1 until tally > t1
add 1 to t2
move int-field of table-one(tally)
to int-field of table-two(t2)
end-perform
.
display-result.
perform varying tally from 1 by 1 until tally = t2
move int-field of table-two(tally) to show
display trim(show) ", " with no advancing
end-perform
move int-field of table-two(tally) to show
display trim(show)
.
end program array-concat. |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #CoffeeScript | CoffeeScript |
# like in JavaScript
a = [1, 2, 3]
b = [4, 5, 6]
c = a.concat b
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Common_Lisp | Common Lisp | (concatenate 'vector #(0 1 2 3) #(4 5 6 7))
=> #(0 1 2 3 4 5 6 7) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Component_Pascal | Component Pascal |
MODULE ArrayConcat;
IMPORT StdLog;
PROCEDURE Concat(x: ARRAY OF INTEGER; y: ARRAY OF INTEGER; OUT z: ARRAY OF INTEGER);
VAR
i: INTEGER;
BEGIN
ASSERT(LEN(x) + LEN(y) <= LEN(z));
FOR i := 0 TO LEN(x) - 1 DO z[i] := x[i] END;
FOR i := 0 TO LEN(y) - 1 DO z[i + LEN(x)] := y[i] END
END Concat;
PROCEDURE Concat2(x: ARRAY OF INTEGER;y: ARRAY OF INTEGER): POINTER TO ARRAY OF INTEGER;
VAR
z: POINTER TO ARRAY OF INTEGER;
i: INTEGER;
BEGIN
NEW(z,LEN(x) + LEN(y));
FOR i := 0 TO LEN(x) - 1 DO z[i] := x[i] END;
FOR i := 0 TO LEN(y) - 1 DO z[i + LEN(x)] := y[i] END;
RETURN z;
END Concat2;
PROCEDURE ShowArray(x: ARRAY OF INTEGER);
VAR
i: INTEGER;
BEGIN
i := 0;
StdLog.Char('[');
WHILE (i < LEN(x)) DO
StdLog.Int(x[i]);IF i < LEN(x) - 1 THEN StdLog.Char(',') END;
INC(i)
END;
StdLog.Char(']');StdLog.Ln;
END ShowArray;
PROCEDURE Do*;
VAR
x: ARRAY 10 OF INTEGER;
y: ARRAY 15 OF INTEGER;
z: ARRAY 25 OF INTEGER;
w: POINTER TO ARRAY OF INTEGER;
i: INTEGER;
BEGIN
FOR i := 0 TO LEN(x) - 1 DO x[i] := i END;
FOR i := 0 TO LEN(y) - 1 DO y[i] := i END;
Concat(x,y,z);StdLog.String("1> ");ShowArray(z);
NEW(w,LEN(x) + LEN(y));
Concat(x,y,z);StdLog.String("2:> ");ShowArray(z);
StdLog.String("3:> ");ShowArray(Concat2(x,y));
END Do;
END ArrayConcat.
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Crystal | Crystal | arr1 = [1, 2, 3]
arr2 = ["foo", "bar", "baz"]
arr1 + arr2 #=> [1, 2, 3, "foo", "bar", "baz"] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #D | D | import std.stdio: writeln;
void main() {
int[] a = [1, 2];
int[] b = [4, 5, 6];
writeln(a, " ~ ", b, " = ", a ~ b);
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Delphi | Delphi | type
TReturnArray = array of integer; //you need to define a type to be able to return it
function ConcatArray(a1,a2:array of integer):TReturnArray;
var
i,r:integer;
begin
{ Low(array) is not necessarily 0 }
SetLength(result,High(a1)-Low(a1)+High(a2)-Low(a2)+2); //BAD idea to set a length you won't release, just to show the idea!
r:=0; //index on the result may be different to indexes on the sources
for i := Low(a1) to High(a1) do begin
result[r] := a1[i];
Inc(r);
end;
for i := Low(a2) to High(a2) do begin
result[r] := a2[i];
Inc(r);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a1,a2:array of integer;
r1:array of integer;
i:integer;
begin
SetLength(a1,4);
SetLength(a2,3);
for i := Low(a1) to High(a1) do
a1[i] := i;
for i := Low(a2) to High(a2) do
a2[i] := i;
TReturnArray(r1) := ConcatArray(a1,a2);
for i := Low(r1) to High(r1) do
showMessage(IntToStr(r1[i]));
Finalize(r1); //IMPORTANT!
ShowMessage(IntToStr(High(r1)));
end; |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Dyalect | Dyalect | var xs = [1,2,3]
var ys = [4,5,6]
var alls = Array.Concat(xs, ys)
print(alls) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #E | E | ? [1,2] + [3,4]
# value: [1, 2, 3, 4] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #EasyLang | EasyLang | a[] = [ 1 2 3 ]
b[] = [ 4 5 6 ]
c[] = a[]
while i < len b[]
c[] &= b[i]
i += 1
.
print c[] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #EchoLisp | EchoLisp |
;;;; VECTORS
(vector-append (make-vector 6 42) (make-vector 4 666))
→ #( 42 42 42 42 42 42 666 666 666 666)
;;;; LISTS
(append (iota 5) (iota 6))
→ (0 1 2 3 4 0 1 2 3 4 5)
;; NB - append may also be used with sequences (lazy lists)
(lib 'sequences)
(take (append [1 .. 7] [7 6 .. 0]) #:all)
→ (1 2 3 4 5 6 7 6 5 4 3 2 1)
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ECL | ECL |
A := [1, 2, 3, 4];
B := [5, 6, 7, 8];
C := A + B; |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Efene | Efene |
@public
run = fn () {
A = [1, 2, 3, 4]
B = [5, 6, 7, 8]
C = A ++ B
D = lists.append([A, B])
io.format("~p~n", [C])
io.format("~p~n", [D])
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #EGL | EGL |
program ArrayConcatenation
function main()
a int[] = [ 1, 2, 3 ];
b int[] = [ 4, 5, 6 ];
c int[];
c.appendAll(a);
c.appendAll(b);
for (i int from 1 to c.getSize())
SysLib.writeStdout("Element " :: i :: " = " :: c[i]);
end
end
end
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Ela | Ela | xs = [1,2,3]
ys = [4,5,6]
xs ++ ys |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Elena | Elena | import extensions;
public program()
{
var a := new int[]{1,2,3};
var b := new int[]{4,5};
console.printLine(
"(",a.asEnumerable(),") + (",b.asEnumerable(),
") = (",(a + b).asEnumerable(),")").readChar();
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Elixir | Elixir | iex(1)> [1, 2, 3] ++ [4, 5, 6]
[1, 2, 3, 4, 5, 6]
iex(2)> Enum.concat([[1, [2], 3], [4], [5, 6]])
[1, [2], 3, 4, 5, 6]
iex(3)> Enum.concat([1..3, [4,5,6], 7..9])
[1, 2, 3, 4, 5, 6, 7, 8, 9] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Elm | Elm | import Element exposing (show, toHtml) -- elm-package install evancz/elm-graphics
import Html.App exposing (beginnerProgram)
import Array exposing (Array, append, initialize)
xs : Array Int
xs =
initialize 3 identity -- [0, 1, 2]
ys : Array Int
ys =
initialize 3 <| (+) 3 -- [3, 4, 5]
main = beginnerProgram { model = ()
, view = \_ -> toHtml (show (append xs ys))
, update = \_ _ -> ()
}
-- Array.fromList [0,1,2,3,4,5] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Emacs_Lisp | Emacs Lisp | (vconcat '[1 2 3] '[4 5] '[6 7 8 9])
=> [1 2 3 4 5 6 7 8 9] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Erlang | Erlang |
1> [1, 2, 3] ++ [4, 5, 6].
[1,2,3,4,5,6]
2> lists:append([1, 2, 3], [4, 5, 6]).
[1,2,3,4,5,6]
3>
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #ERRE | ERRE |
PROGRAM ARRAY_CONCAT
DIM A[5],B[5],C[10]
!
! for rosettacode.org
!
BEGIN
DATA(1,2,3,4,5)
DATA(6,7,8,9,0)
FOR I=1 TO 5 DO ! read array A[.]
READ(A[I])
END FOR
FOR I=1 TO 5 DO ! read array B[.]
READ(B[I])
END FOR
FOR I=1 TO 10 DO ! append B[.] to A[.]
IF I>5 THEN
C[I]=B[I-5]
ELSE
C[I]=A[I]
END IF
PRINT(C[I];) ! print single C value
END FOR
PRINT
END PROGRAM
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Euphoria | Euphoria | sequence s1,s2,s3
s1 = {1,2,3}
s2 = {4,5,6}
s3 = s1 & s2
? s3 |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #F.23 | F# | let a = [|1; 2; 3|]
let b = [|4; 5; 6;|]
let c = Array.append a b |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Factor | Factor | append |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Fantom | Fantom |
> a := [1,2,3]
> b := [4,5,6]
> a.addAll(b)
> a
[1,2,3,4,5,6]
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #FBSL | FBSL | #APPTYPE CONSOLE
DIM aint[] ={1, 2, 3}, astr[] ={"one", "two", "three"}, asng[] ={!1, !2, !3}
FOREACH DIM e IN ARRAYMERGE(aint, astr, asng)
PRINT e, " ";
NEXT
PAUSE |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Forth | Forth | : $!+ ( a u a' -- a'+u )
2dup + >r swap move r> ;
: cat ( a2 u2 a1 u1 -- a3 u1+u2 )
align here dup >r $!+ $!+ r> tuck - dup allot ;
\ TEST
create a1 1 , 2 , 3 ,
create a2 4 , 5 ,
a2 2 cells a1 3 cells cat dump
8018425F0: 01 00 00 00 00 00 00 00 - 02 00 00 00 00 00 00 00 ................
801842600: 03 00 00 00 00 00 00 00 - 04 00 00 00 00 00 00 00 ................
801842610: 05 00 00 00 00 00 00 00 - ........
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Fortran | Fortran | program Concat_Arrays
implicit none
! Note: in Fortran 90 you must use the old array delimiters (/ , /)
integer, dimension(3) :: a = [1, 2, 3] ! (/1, 2, 3/)
integer, dimension(3) :: b = [4, 5, 6] ! (/4, 5, 6/)
integer, dimension(:), allocatable :: c, d
allocate(c(size(a)+size(b)))
c(1 : size(a)) = a
c(size(a)+1 : size(a)+size(b)) = b
print*, c
! alternative
d = [a, b] ! (/a, b/)
print*, d
end program Concat_Arrays |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Free_Pascal | Free Pascal | array2 := array0 + array1 |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #FreeBASIC | FreeBASIC |
' FB 1.05.0 Win64
Sub ConcatArrays(a() As String, b() As String, c() As String)
Dim aSize As Integer = UBound(a) - LBound(a) + 1
Dim bSize As Integer = UBound(b) - LBound(b) + 1
Dim cSize As Integer = aSize + bSize
Redim c(0 To cSize - 1)
Dim i As Integer
For i = 0 To aSize - 1
c(i) = a(LBound(a) + i)
Next
For i = 0 To bSize - 1
c(UBound(a) + i + 1) = b(LBound(b) + i)
Next
End Sub
Dim a(3) As String = {"The", "quick", "brown", "fox"}
Dim b(4) As String = {"jumped", "over", "the", "lazy", "dog"}
Dim c() As String
ConcatArrays(a(), b(), c())
For i As Integer = LBound(c) To UBound(c)
Print c(i); " ";
Next
Print : Print
Print "Press any key to quit the program"
Sleep
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Frink | Frink |
a = [1,2]
b = [3,4]
a.pushAll[b]
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #FunL | FunL | arr1 = array( [1, 2, 3] )
arr2 = array( [4, 5, 6] )
arr3 = array( [7, 8, 9] )
println( arr1 + arr2 + arr3 ) |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Futhark | Futhark |
concat as bs cd
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #FutureBasic | FutureBasic | void local fn DoIt
CFArrayRef array = @[@"Alpha",@"Bravo",@"Charlie"]
print array
array = fn ArrayByAddingObjectsFromArray( array, @[@"Delta",@"Echo",@"FutureBasic"] )
print array
end fn
window 1
fn DoIt
HandleEvents |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Gambas | Gambas | Public Sub Main()
Dim sString1 As String[] = ["The", "quick", "brown", "fox"]
Dim sString2 As String[] = ["jumped", "over", "the", "lazy", "dog"]
sString1.Insert(sString2)
Print sString1.Join(" ")
End |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #GAP | GAP | # Concatenate arrays
Concatenation([1, 2, 3], [4, 5, 6], [7, 8, 9]);
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
# Append to a variable
a := [1, 2, 3];
Append(a, [4, 5, 6);
Append(a, [7, 8, 9]);
a;
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Genie | Genie | [indent=4]
/*
Array concatenation, in Genie
Tectonics: valac array-concat.gs
*/
/* Creates a new array */
def int_array_concat(x:array of int, y:array of int):array of int
var a = new Array of int(false, true, 0) /* (zero-terminated, clear, size) */
a.append_vals (x, x.length)
a.append_vals (y, y.length)
z:array of int = (owned) a.data
return z
def int_show_array(a:array of int)
for element in a do stdout.printf("%d ", element)
stdout.printf("\n")
init
x: array of int = {1, 2, 3}
y: array of int = {3, 2, 1, 0, -1}
z: array of int = int_array_concat(x, y)
stdout.printf("x: "); int_show_array(x)
stdout.printf("y: "); int_show_array(y)
stdout.printf("z: "); int_show_array(z)
print "%d elements in new array", z.length |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #GLSL | GLSL |
#define array_concat(T,a1,a2,returned) \
T[a1.length()+a2.length()] returned; \
{ \
for(int i = 0; i < a1.length(); i++){ \
returned[i] = a1[i]; \
} \
for(int i = 0; i < a2.length(); i++){ \
returned[i+a1.length()] = a2[i]; \
} \
}
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Go | Go | package main
import "fmt"
func main() {
// Example 1: Idiomatic in Go is use of the append function.
// Elements must be of identical type.
a := []int{1, 2, 3}
b := []int{7, 12, 60} // these are technically slices, not arrays
c := append(a, b...)
fmt.Println(c)
// Example 2: Polymorphism.
// interface{} is a type too, one that can reference values of any type.
// This allows a sort of polymorphic list.
i := []interface{}{1, 2, 3}
j := []interface{}{"Crosby", "Stills", "Nash", "Young"}
k := append(i, j...) // append will allocate as needed
fmt.Println(k)
// Example 3: Arrays, not slices.
// A word like "array" on RC often means "whatever array means in your
// language." In Go, the common role of "array" is usually filled by
// Go slices, as in examples 1 and 2. If by "array" you really mean
// "Go array," then you have to do a little extra work. The best
// technique is almost always to create slices on the arrays and then
// use the copy function.
l := [...]int{1, 2, 3}
m := [...]int{7, 12, 60} // arrays have constant size set at compile time
var n [len(l) + len(m)]int
copy(n[:], l[:]) // [:] creates a slice that references the entire array
copy(n[len(l):], m[:])
fmt.Println(n)
} |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Gosu | Gosu |
var listA = { 1, 2, 3 }
var listB = { 4, 5, 6 }
var listC = listA.concat( listB )
print( listC ) // prints [1, 2, 3, 4, 5, 6]
|
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Groovy | Groovy | def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"] |
http://rosettacode.org/wiki/Array_concatenation | Array concatenation | Task
Show how to concatenate two arrays in your language.
If this is as simple as array1 + array2, so be it.
| #Haskell | Haskell | (++) :: [a] -> [a] -> [a] |
Dataset Card for the Rosetta Code Dataset
Dataset Summary
Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in learning another. Rosetta Code currently has 1,203 tasks, 389 draft tasks, and is aware of 883 languages, though we do not (and cannot) have solutions to every task in every language.
Supported Tasks and Leaderboards
[More Information Needed]
Languages
['ALGOL 68', 'Arturo', 'AWK', 'F#', 'Factor', 'Go', 'J', 'jq', 'Julia', 'Lua', 'Mathematica/Wolfram Language',
'Perl', 'Phix', 'Picat', 'Python', 'Quackery', 'Raku', 'Ring', 'Sidef', 'Vlang', 'Wren', 'XPL0', '11l',
'68000 Assembly', '8th', 'AArch64 Assembly', 'ABAP', 'ACL2', 'Action!', 'ActionScript', 'Ada', 'Aime', 'ALGOL W',
'Amazing Hopper', 'AntLang', 'Apex', 'APL', 'AppleScript', 'ARM Assembly', 'ATS', 'AutoHotkey', 'AutoIt', 'Avail',
'Babel', 'bash', 'BASIC', 'BASIC256', 'BQN', 'Bracmat', 'Burlesque', 'C', 'C#', 'C++', 'Ceylon', 'Clojure', 'COBOL',
'CoffeeScript', 'Common Lisp', 'Component Pascal', 'Crystal', 'D', 'Delphi', 'Dyalect', 'E', 'EasyLang', 'EchoLisp',
'ECL', 'Efene', 'EGL', 'Ela', 'Elena', 'Elixir', 'Elm', 'Emacs Lisp', 'Erlang', 'ERRE', 'Euphoria', 'Fantom', 'FBSL',
'Forth', 'Fortran', 'Free Pascal', 'FreeBASIC', 'Frink', 'FunL', 'Futhark', 'FutureBasic', 'Gambas', 'GAP', 'Genie',
'GLSL', 'Gosu', 'Groovy', 'Haskell', 'HicEst', 'Hy', 'i', 'Icon and Unicon', 'IDL', 'Idris', 'Inform 7', 'Ioke', 'Java',
'JavaScript', 'K', 'Klingphix', 'Klong', 'Kotlin', 'LabVIEW', 'Lambdatalk', 'Lang5', 'langur', 'Lasso', 'LFE', 'Liberty BASIC',
'LIL', 'Limbo', 'Lingo', 'Little', 'Logo', 'M2000 Interpreter', 'Maple', 'Mathcad', 'Mathematica / Wolfram Language',
'MATLAB / Octave', 'Maxima', 'Mercury', 'min', 'MiniScript', 'Nanoquery', 'Neko', 'Nemerle', 'NetRexx', 'NewLISP', 'Nial',
'Nim', 'Oberon-2', 'Objeck', 'Objective-C', 'OCaml', 'Oforth', 'Onyx', 'ooRexx', 'Order', 'OxygenBasic', 'Oz', 'PARI/GP',
'Pascal', 'Phixmonti', 'PHP', 'PicoLisp', 'Pike', 'PL/I', 'Pony', 'PostScript', 'PowerShell', 'Processing', 'Prolog',
'PureBasic', 'Q', 'QBasic', 'QB64', 'R', 'Racket', 'RapidQ', 'REBOL', 'Red', 'ReScript', 'Retro', 'REXX', 'RLaB', 'Ruby',
'Rust', 'S-lang', 'SASL', 'Scala', 'Scheme', 'Seed7', 'SenseTalk', 'SETL', 'Simula', '360 Assembly', '6502 Assembly', 'Slate',
'Smalltalk', 'Ol', 'SNOBOL4', 'Standard ML', 'Stata', 'Swift', 'Tailspin', 'Tcl', 'TI-89 BASIC', 'Trith', 'UNIX Shell',
'Ursa', 'Vala', 'VBA', 'VBScript', 'Visual Basic .NET', 'Wart', 'BaCon', 'Bash', 'Yabasic', 'Yacas', 'Batch File', 'Yorick',
'Z80 Assembly', 'BBC BASIC', 'Brat', 'zkl', 'zonnon', 'Zsh', 'ZX Spectrum Basic', 'Clipper/XBase++', 'ColdFusion', 'Dart',
'DataWeave', 'Dragon', 'FurryScript', 'Fōrmulæ', 'Harbour', 'hexiscript', 'Hoon', 'Janet', '0815', 'Jsish', 'Latitude', 'LiveCode',
'Aikido', 'AmigaE', 'MiniZinc', 'Asymptote', 'NGS', 'bc', 'Befunge', 'Plorth', 'Potion', 'Chef', 'Clipper', 'Relation', 'Robotic',
'dc', 'DCL', 'DWScript', 'Shen', 'SPL', 'SQL', 'Eiffel', 'Symsyn', 'Emojicode', 'TI-83 BASIC', 'Transd', 'Excel', 'Visual Basic',
'FALSE', 'WDTE', 'Fermat', 'XLISP', 'Zig', 'friendly interactive shell', 'Zoea', 'Zoea Visual', 'GEORGE', 'Haxe', 'HolyC', 'LSE64',
'M4', 'MAXScript', 'Metafont', 'МК-61/52', 'ML/I', 'Modula-2', 'Modula-3', 'MUMPS', 'NSIS', 'Openscad', 'Panda', 'PHL', 'Piet',
'Plain English', 'Pop11', 'ProDOS', '8051 Assembly', 'Python 3.x Long Form', 'Raven', 'ALGOL 60', 'Run BASIC', 'Sass/SCSS', 'App Inventor',
'smart BASIC', 'SNUSP', 'Arendelle', 'SSEM', 'Argile', 'Toka', 'TUSCRIPT', '4DOS Batch', '8080 Assembly', 'Vedit macro language',
'8086 Assembly', 'Axe', 'Elisa', 'Verilog', 'Vim Script', 'x86 Assembly', 'Euler Math Toolbox', 'Acurity Architect', 'XSLT', 'BML',
'Agena', 'Boo', 'Brainf***', 'LLVM', 'FOCAL', 'Frege', 'ALGOL-M', 'ChucK', 'Arbre', 'Clean', 'Hare', 'MATLAB', 'Astro', 'Applesoft BASIC',
'OOC', 'Bc', 'Computer/zero Assembly', 'SAS', 'Axiom', 'B', 'Dao', 'Caché ObjectScript', 'CLU', 'Scilab', 'DBL', 'Commodore BASIC', 'Diego',
'Dc', 'BCPL', 'Alore', 'Blade', 'Déjà Vu', 'Octave', 'Cowgol', 'BlitzMax', 'Falcon', 'BlooP', 'SequenceL', 'Sinclair ZX81 BASIC', 'GW-BASIC',
'Lobster', 'C1R', 'Explore', 'Clarion', 'Locomotive Basic', 'GUISS', 'Clio', 'TXR', 'Ursala', 'CLIPS', 'Microsoft Small Basic', 'Golfscript',
'Beads', 'Coco', 'Little Man Computer', 'Chapel', 'Comal', 'Curry', 'GML', 'NewLisp', 'Coq', 'Gastona', 'uBasic/4tH', 'Pyret', 'Dhall',
'Plain TeX', 'Halon', 'Wortel', 'FormulaOne', 'Dafny', 'Ksh', 'Eero', 'Fan', 'Draco', 'DUP', 'Io', 'Metapost', 'Logtalk', 'Dylan', 'TI-83_BASIC',
'Sather', 'Rascal', 'SIMPOL', 'IS-BASIC', 'KonsolScript', 'Pari/Gp', 'Genyris', 'EDSAC order code', 'Egel', 'Joy', 'lang5', 'XProc', 'XQuery',
'POV-Ray', 'Kitten', 'Lisaac', 'LOLCODE', 'SVG', 'MANOOL', 'LSL', 'Moonscript', 'Fhidwfe', 'Inspired by Rascal', 'Fish', 'MIPS Assembly',
'Monte', 'FUZE BASIC', 'NS-HUBASIC', 'Qi', 'GDScript', 'Glee', 'SuperCollider', 'Verbexx', 'Huginn', 'I', 'Informix 4GL', 'Isabelle', 'KQL',
'lambdatalk', 'RPG', 'Lhogho', 'Lily', 'xTalk', 'Scratch', 'Self', 'MAD', 'RATFOR', 'OpenEdge/Progress', 'Xtend', 'Suneido', 'Mirah',
'mIRC Scripting Language', 'ContextFree', 'Tern', 'MMIX', 'AmigaBASIC', 'AurelBasic', 'TorqueScript', 'MontiLang', 'MOO', 'MoonScript',
'Unicon', 'fermat', 'q', 'Myrddin', 'உயிர்/Uyir', 'MySQL', 'newLISP', 'VHDL', 'Oberon', 'Wee Basic', 'OpenEdge ABL/Progress 4GL', 'X86 Assembly',
'XBS', 'KAP', 'Perl5i', 'Peloton', 'PL/M', 'PL/SQL', 'Pointless', 'Polyglot:PL/I and PL/M', 'ToffeeScript', 'TMG', 'TPP', 'Pure', 'Pure Data',
'Xidel', 'S-BASIC', 'Salmon', 'SheerPower 4GL', 'Sparkling', 'Spin', 'SQL PL', 'Transact-SQL', 'True BASIC', 'TSE SAL', 'Tiny BASIC', 'TypeScript',
'Uniface', 'Unison', 'UTFool', 'VAX Assembly', 'VTL-2', 'Wrapl', 'XBasic', 'Xojo', 'XSLT 1.0', 'XSLT 2.0', 'MACRO-10', 'ANSI Standard BASIC',
'UnixPipes', 'REALbasic', 'Golo', 'DM', 'X86-64 Assembly', 'GlovePIE', 'PowerBASIC', 'LotusScript', 'TIScript', 'Kite', 'V', 'Powershell', 'Vorpal',
'Never', 'Set lang', '80386 Assembly', 'Furor', 'Input conversion with Error Handling', 'Guile', 'ASIC', 'Autolisp', 'Agda', 'Swift Playground',
'Nascom BASIC', 'NetLogo', 'CFEngine', 'OASYS Assembler', 'Fennel', 'Object Pascal', 'Shale', 'GFA Basic', 'LDPL', 'Ezhil', 'SMEQL', 'tr', 'WinBatch',
'XPath 2.0', 'Quite BASIC', 'Gema', '6800 Assembly', 'Applescript', 'beeswax', 'gnuplot', 'ECMAScript', 'Snobol4', 'Blast', 'C/C++', 'Whitespace',
'Blue', 'C / C++', 'Apache Derby', 'Lychen', 'Oracle', 'Alternative version', 'PHP+SQLite', 'PILOT', 'PostgreSQL', 'PowerShell+SQLite', 'PureBasic+SQLite',
'Python+SQLite', 'SQLite', 'Tcl+SQLite', 'Transact-SQL (MSSQL)', 'Visual FoxPro', 'SmileBASIC', 'Datalog', 'SystemVerilog', 'Smart BASIC', 'Snobol', 'Terraform',
'ML', 'SQL/PostgreSQL', '4D', 'ArnoldC', 'ANSI BASIC', 'Delphi/Pascal', 'ooREXX', 'Dylan.NET', 'CMake', 'Lucid', 'XProfan', 'sed', 'Gnuplot', 'RPN (HP-15c)',
'Sed', 'JudoScript', 'ScriptBasic', 'Unix shell', 'Niue', 'Powerbuilder', 'C Shell', 'Zoomscript', 'MelonBasic', 'ScratchScript', 'SimpleCode', 'OASYS',
'HTML', 'tbas', 'LaTeX', 'Lilypond', 'MBS', 'B4X', 'Progress', 'SPARK / Ada', 'Arc', 'Icon', 'AutoHotkey_L', 'LSE', 'N/t/roff', 'Fexl', 'Ra', 'Koka',
'Maclisp', 'Mond', 'Nix', 'ZED', 'Inform 6', 'Visual Objects', 'Cind', 'm4', 'g-fu', 'pascal', 'Jinja', 'Mathprog', 'Rhope', 'Delphi and Pascal', 'Epoxy',
'SPARK', 'B4J', 'DIBOL-11', 'JavaFX Script', 'Pixilang', 'BASH (feat. sed & tr)', 'zig', 'Web 68', 'Shiny', 'Egison', 'OS X sha256sum', 'AsciiDots',
'FileMaker', 'Unlambda', 'eC', 'GLBasic', 'JOVIAL', 'haskell', 'Atari BASIC', 'ANTLR', 'Cubescript', 'OoRexx', 'WebAssembly', 'Woma', 'Intercal', 'Malbolge',
'LiveScript', 'Fancy', 'Detailed Description of Programming Task', 'Lean', 'GeneXus', 'CafeOBJ', 'TechBASIC', 'blz', 'MIRC Scripting Language', 'Oxygene',
'zsh', 'Make', 'Whenever', 'Sage', 'L++', 'Tosh', 'LC3 Assembly', 'SETL4', 'Pari/GP', 'OxygenBasic x86 Assembler', 'Pharo', 'Binary Lambda Calculus', 'Bob',
'bootBASIC', 'Turing', 'Ultimate++', 'Gabuzomeu', 'HQ9+', 'INTERCAL', 'Lisp', 'NASM', 'SPWN', 'Turbo Pascal', 'Nickle', 'SPAD', 'Mozart/Oz', 'Batch file',
'SAC', 'C and C++', 'vbscript', 'OPL', 'Wollok', 'Pascal / Delphi / Free Pascal', 'GNU make', 'Recursive', 'C3', 'Picolisp', 'Note 1', 'Note 2', 'Visual Prolog',
'ivy', 'k', 'clojure', 'Unix Shell', 'Basic09', 'S-Basic', 'FreePascal', 'Wolframalpha', 'c_sharp', 'LiveCode Builder', 'Heron', 'SPSS', 'LibreOffice Basic',
'PDP-11 Assembly', 'Solution with recursion', 'Lua/Torch', 'tsql', 'Transact SQL', 'X++', 'Xanadu', 'GDL', 'C_sharp', 'TutorialD', 'Glagol', 'Basic', 'Brace',
'Cixl', 'ELLA', 'Lox', 'Node.js', 'Generic', 'Hope', 'Snap!', 'TSQL', 'MathCortex', 'Mathmap', 'TI-83 BASIC, TI-89 BASIC', 'ZPL', 'LuaTeX', 'AmbientTalk',
'Alternate version to handle 64 and 128 bit integers.', 'Crack', 'Corescript', 'Fortress', 'GB BASIC', 'IWBASIC', 'RPL', 'DMS', 'dodo0', 'MIXAL', 'Occam',
'Morfa', 'Snabel', 'ObjectIcon', 'Panoramic', 'PeopleCode', 'Monicelli', 'gecho', 'Hack', 'JSON', 'Swym', 'ReasonML', 'make', 'TOML', 'WEB', 'SkookumScript',
'Batch', 'TransFORTH', 'Assembly', 'Iterative', 'LC-3', 'Quick Basic/QBASIC/PDS 7.1/VB-DOS', 'Turbo-Basic XL', 'GNU APL', 'OOCalc', 'QUACKASM', 'VB-DOS',
'Typescript', 'x86-64 Assembly', 'FORTRAN', 'Furryscript', 'Gridscript', 'Necromantus', 'HyperTalk', 'Biferno', 'AspectJ', 'SuperTalk', 'Rockstar', 'NMAKE.EXE',
'Opa', 'Algae', 'Anyways', 'Apricot', 'AutoLISP', 'Battlestar', 'Bird', 'Luck', 'Brlcad', 'C++/CLI', 'C2', 'Casio BASIC', 'Cat', 'Cduce', 'Clay', 'Cobra',
'Comefrom0x10', 'Creative Basic', 'Integer BASIC', 'DDNC', 'DeviousYarn', 'DIV Games Studio', 'Wisp', 'AMPL', 'Pare', 'PepsiScript', 'Installing Processing',
'Writing your first program', 'batari Basic', 'Jack', 'elastiC', 'TI-83 Hex Assembly', 'Extended BrainF***', '1C', 'PASM', 'Pict', 'ferite', 'Bori', 'RASEL',
'Echolisp', 'XPath', 'MLite', 'HPPPL', 'Gentee', 'JSE', 'Just Basic', 'Global Script', 'Nyquist', 'HLA', 'Teradata Stored Procedure', 'HTML5', 'Portugol',
'UBASIC', 'NOWUT', 'Inko', 'Jacquard Loom', 'JCL', 'Supernova', 'Small Basic', 'Kabap', 'Kaya', 'Kdf9 Usercode', 'Keg', 'KSI', 'Gecho', 'Gri', 'VBA Excel',
'Luna', 'MACRO-11', 'MINIL', 'Maude', 'MDL', 'Mosaic', 'Purity', 'MUF', 'MyDef', 'MyrtleScript', 'Mythryl', 'Neat', 'ThinBASIC', 'Nit', 'NLP++', 'Odin', 'OpenLisp',
'PDP-1 Assembly', 'Peylang', 'Pikachu', 'NESL', 'PIR', 'Plan', 'Programming Language', 'PROMAL', 'PSQL', 'Quill', 'xEec', 'RED', 'Risc-V', 'RTL/2', 'Sing', 'Sisal',
'SoneKing Assembly', 'SPARC Assembly', 'Swahili', 'Teco', 'Terra', 'TestML', 'Viua VM assembly', 'Whiley', 'Wolfram Language', 'X10', 'Quack', 'K4', 'XL', 'MyHDL',
'JAMES II/Rule-based Cellular Automata', 'APEX', 'QuickBASIC 4.5', 'BrightScript (for Roku)', 'Coconut', 'CSS', 'MapBasic', 'Gleam', 'AdvPL', 'Iptscrae', 'Kamailio Script',
'KL1', 'MEL', 'NATURAL', 'NewtonScript', 'PDP-8 Assembly', 'FRISC Assembly', 'Amstrad CPC Locomotive BASIC', 'Ruby with RSpec', 'php', 'Small', 'Lush', 'Squirrel',
'PL/pgSQL', 'XMIDAS', 'Rebol', 'embedded C for AVR MCU', 'FPr', 'Softbridge BASIC', 'StreamIt', 'jsish', 'JScript.NET', 'MS-DOS', 'Beeswax', 'eSQL', 'QL SuperBASIC',
'Rapira', 'Jq', 'scheme', 'oberon-2', '{{header|Vlang}', 'XUL', 'Soar', 'Befunge 93', 'Bash Shell', 'JacaScript', 'Xfractint', 'JoCaml', 'JotaCode', 'Atari Basic',
'Stretch 1', 'CFScript', 'Stretch 2', 'RPGIV', 'Shell', 'Felix', 'Flex', 'kotlin', 'Deluge', 'ksh', 'OCTAVE', 'vbScript', 'Javascript/NodeJS', 'Coffeescript',
'MS SmallBasic', 'Setl4', 'Overview', '1. Grid structure functions', '2. Calendar data functions', '3. Output configuration', 'WYLBUR', 'Mathematica/ Wolfram Language',
'Commodore Basic', 'Wolfram Language/Mathematica', 'Korn Shell', 'PARIGP', 'Metal', 'VBA (Visual Basic for Application)', 'Lolcode', 'mLite', 'z/Arch Assembler',
"G'MIC", 'C# and Visual Basic .NET', 'Run Basic', 'FP', 'XEmacs Lisp', 'Mathematica//Wolfram Language', 'RPL/2', 'Ya', 'JavaScript + HTML', 'JavaScript + SVG',
'Quick BASIC', 'MatLab', 'Pascal and Object Pascal', 'Apache Ant', 'rust', 'VBA/Visual Basic', 'Go!', 'Lambda Prolog', 'Monkey']
Dataset Structure
Data Instances
First row:
{'task_url': 'http://rosettacode.org/wiki/Ascending_primes',
'task_name': 'Ascending primes',
'task_description': "Generate and show all primes with strictly ascending decimal digits.\n\nAside: Try solving without peeking at existing solutions. I had a weird idea for generating\na prime sieve faster, which needless to say didn't pan out. The solution may be p(r)etty trivial\nbut generating them quickly is at least mildly interesting.\nTip: filtering all 7,027,260 primes below 123,456,789 probably won't kill you, but there is\nat least one significantly better and much faster way, needing a mere 511 odd/prime tests.\n\n\n\nSee also\n OEIS:A052015 - Primes with distinct digits in ascending order\n\n\nRelated\n\nPrimes with digits in nondecreasing order (infinite series allowing duplicate digits, whereas this isn't and doesn't)\nPandigital prime (whereas this is the smallest, with gaps in the used digits being permitted)\n\n",
'language_url': '#ALGOL_68',
'language_name': 'ALGOL 68'}
Code:
BEGIN # find all primes with strictly increasing digits #
PR read "primes.incl.a68" PR # include prime utilities #
PR read "rows.incl.a68" PR # include array utilities #
[ 1 : 512 ]INT primes; # there will be at most 512 (2^9) primes #
INT p count := 0; # number of primes found so far #
FOR d1 FROM 0 TO 1 DO
INT n1 = d1;
FOR d2 FROM 0 TO 1 DO
INT n2 = IF d2 = 1 THEN ( n1 * 10 ) + 2 ELSE n1 FI;
FOR d3 FROM 0 TO 1 DO
INT n3 = IF d3 = 1 THEN ( n2 * 10 ) + 3 ELSE n2 FI;
FOR d4 FROM 0 TO 1 DO
INT n4 = IF d4 = 1 THEN ( n3 * 10 ) + 4 ELSE n3 FI;
FOR d5 FROM 0 TO 1 DO
INT n5 = IF d5 = 1 THEN ( n4 * 10 ) + 5 ELSE n4 FI;
FOR d6 FROM 0 TO 1 DO
INT n6 = IF d6 = 1 THEN ( n5 * 10 ) + 6 ELSE n5 FI;
FOR d7 FROM 0 TO 1 DO
INT n7 = IF d7 = 1 THEN ( n6 * 10 ) + 7 ELSE n6 FI;
FOR d8 FROM 0 TO 1 DO
INT n8 = IF d8 = 1 THEN ( n7 * 10 ) + 8 ELSE n7 FI;
FOR d9 FROM 0 TO 1 DO
INT n9 = IF d9 = 1 THEN ( n8 * 10 ) + 9 ELSE n8 FI;
IF n9 > 0 THEN
IF is probably prime( n9 ) THEN
# have a prime with strictly ascending digits #
primes[ p count +:= 1 ] := n9
FI
FI
OD
OD
OD
OD
OD
OD
OD
OD
OD;
QUICKSORT primes FROMELEMENT 1 TOELEMENT p count; # sort the primes #
FOR i TO p count DO # display the primes #
print( ( " ", whole( primes[ i ], -8 ) ) );
IF i MOD 10 = 0 THEN print( ( newline ) ) FI
OD
END
Data Fields
Dataset({
features: ['task_url', 'task_name', 'task_description', 'language_url', 'language_name', 'code'],
num_rows: 79013
})
Data Splits
The dataset only contains one split, namely the "train" split.
Dataset Creation
Curation Rationale
[More Information Needed]
Source Data
Initial Data Collection and Normalization
[More Information Needed]
Who are the source language producers?
[More Information Needed]
Annotations
Annotation process
[More Information Needed]
Who are the annotators?
[More Information Needed]
Personal and Sensitive Information
[More Information Needed]
Considerations for Using the Data
Social Impact of Dataset
[More Information Needed]
Discussion of Biases
[More Information Needed]
Other Known Limitations
[More Information Needed]
Additional Information
Dataset Curators
[More Information Needed]
Licensing Information
[More Information Needed]
Citation Information
To cite the Rosetta Code webiste you can use the following bibtex entry:
@misc{rosetta-code,
author = "Rosetta Code",
title = "Rosetta Code --- Rosetta Code{,} ",
year = "2022",
url = "https://rosettacode.org/w/index.php?title=Rosetta_Code&oldid=322370",
note = "[Online; accessed 8-December-2022]"
}
Contributions
Thanks to @christopher for adding this dataset.
- Downloads last month
- 165