Append numbers at same position in strings: Difference between revisions

Added C3
(add OCaml)
(Added C3)
 
(17 intermediate revisions by 12 users not shown)
Line 2:
 
;Task:
<br>Let givenGiven three listlists:
<br>list1 = [1,2,3,4,5,6,7,8,9]
<br>list2 = [10,11,12,13,14,15,16,17,18]
<br>list3 = [19,20,21,22,23,24,25,26,27]
<br>AppendTurn the numbers atthem sameinto positionstrings inand stringsconcatenate them.
<br>The result should be:
<br>list = [11019,21120,31221,41322,51423,61524,71625,81726,91827]
Line 90:
append list1 list2 list3</syntaxhighlight>
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">list1: [1,2,3,4,5,6,7,8,9]
list2: [10,11,12,13,14,15,16,17,18]
list3: [19,20,21,22,23,24,25,26,27]
 
0..dec size list1 | map'i -> join @[list1\[i] list2\[i] list3\[i]]
| print</syntaxhighlight>
 
{{out}}
 
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
Line 129 ⟶ 142:
11019 21120 31221 41322 51423 61524 71625 81726 91827
</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">#include<stdio.h>
#include<stdlib.h>
 
int main(void) {
int list[3][9], i;
for(i=0;i<27;i++) list[i/9][i%9]=1+i;
for(i=0;i<9;i++) printf( "%d%d%d ", list[0][i], list[1][i], list[2][i] );
return 0;
}</syntaxhighlight>
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
 
=={{header|BASIC}}==
Line 219:
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">#include<stdio.h>
#include<stdlib.h>
 
int main(void) {
int list[3][9], i;
for(i=0;i<27;i++) list[i/9][i%9]=1+i;
for(i=0;i<9;i++) printf( "%d%d%d ", list[0][i], list[1][i], list[2][i] );
return 0;
}</syntaxhighlight>
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
=={{header|C3}}==
<syntaxhighlight lang="c3">import std::io;
import std::collections::list;
 
fn void main()
{
int[9] list1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[9] list2 = { 10, 11, 12, 13, 14, 15, 16, 17, 18 };
int[9] list3 = { 19, 20, 21, 22, 23, 24, 25, 26, 27 };
List(<String>) list;
list.temp_init();
for (int i = 0; i < 9; i++)
{
list.push(string::tformat("%d%d%d", list1[i], list2[i], list3[i]));
}
io::printn(list);
}</syntaxhighlight>
{{out}}<pre>[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]</pre>
 
=={{header|CLU}}==
Line 247 ⟶ 277:
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils}}
 
<syntaxhighlight lang="Delphi">
const List1: array [0..8] of integer = (1, 2, 3, 4, 5, 6, 7, 8, 9);
const list2: array [0..8] of integer = (10, 11, 12, 13, 14, 15, 16, 17, 18);
const list3: array [0..8] of integer = (19, 20, 21, 22, 23, 24, 25, 26, 27);
 
function GetAppendNumbers: string;
var I: integer;
begin
Result:='List = [';
for I:=0 to High(List1) do
begin
Result:=Result+IntToStr(List1[I])+IntToStr(List2[I])+IntToStr(List3[I]);
if I=High(List1) then Result:=Result+']'
else Result:=Result+',';
end;
end;
</syntaxhighlight>
 
{{out}}
 
<pre>
List = [11019,21120,31221,41322,51423,61524,71625,81726,91827]
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
list1[] = [ 1 2 3 4 5 6 7 8 9 ]
list2[] = [ 10 11 12 13 14 15 16 17 18 ]
list3[] = [ 19 20 21 22 23 24 25 26 27 ]
#
for i to len list1[]
s$ = list1[i] & list2[i] & list3[i]
r[] &= number s$
.
print r[]
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 283 ⟶ 354:
next i</syntaxhighlight>
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
NSUInteger i
CFArrayRef list1, list2, list3
 
list1 = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"]
list2 = @[@"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18"]
list3 = @[@"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27"]
 
printf @"[\b"
for i = 0 to 8
CFStringRef format : if i < 8 then format = @"%@%@%@, \b" else format = @"%@%@%@]"
printf format, list1[i], list2[i], list3[i]
next
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
</pre>
 
 
=={{header|Go}}==
Line 304 ⟶ 399:
[11019 21120 31221 41322 51423 61524 71625 81726 91827]
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">main :: IO ()
main =
mapM_ putStrLn $
zipWith3
(\ x y z -> [x, y, z] >>= show)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[10, 11, 12, 13, 14, 15, 16, 17, 18]
[19, 20, 21, 22, 23, 24, 25, 26, 27]</syntaxhighlight>
 
or more flexibly (allowing for an arbitrary number of zipped lists) in terms of ZipList:
<syntaxhighlight lang="haskell">import Control.Applicative
 
main :: IO ()
main =
mapM_ putStrLn $
getZipList $
(\x y z -> [x, y, z] >>= show) <$>
ZipList [1, 2, 3, 4, 5, 6, 7, 8, 9] <*>
ZipList [10, 11, 12, 13, 14, 15, 16, 17, 18] <*>
ZipList [19, 20, 21, 22, 23, 24, 25, 26, 27]</syntaxhighlight>
 
{{Out}}
<pre>11019
21120
31221
41322
51423
61524
71625
81726
91827</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j">list1=. 1 2 3 4 5 6 7 8 9
list2=. 10 11 12 13 14 15 16 17 18
list3=. 19 20 21 22 23 24 25 26 27
-.&' '@":"1 list1 ,. list2 ,. list3</syntaxhighlight>
{{out}}
<pre>11019
21120
31221
41322
51423
61524
71625
81726
91827</pre>
 
=={{header|jq}}==
Line 361 ⟶ 506:
-> 11019 21120 31221 41322 51423 61524 71625 81726 91827
</syntaxhighlight>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">
do -- form a list of strings by concatenating numbers from 3 lists
local list1, list2, list3 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
, { 10, 11, 12, 13, 14, 15, 16, 17, 18 }
, { 19, 20, 21, 22, 23, 24, 25, 26, 27 }
local result = {}
for i = 1, #list1 do
result[ i ] = list1[ i ]..list2[ i ]..list3[ i ]
end
print( "[ "..table.concat( result, " " ).." ]" )
end
</syntaxhighlight>
{{out}}
<pre>
[ 11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827 ]
</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Line 371 ⟶ 534:
{{out}}<pre>
{11019,21120,31221,41322,51423,61524,71625,81726,91827}
</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
list1:makelist(i,i,9)$
list2:makelist(i,i,10,18)$
list3:makelist(i,i,19,27)$
block(makelist(sconcat(list1[i],list2[i],list3[i]),i,1,length(list1)),map(eval_string,%%));
</syntaxhighlight>
{{out}}<pre>
[11019,21120,31221,41322,51423,61524,71625,81726,91827]
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/strutils
 
const
List1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
List2 = [10, 11, 12, 13, 14, 15, 16, 17, 18]
List3 = [19, 20, 21, 22, 23, 24, 25, 26, 27]
 
var list: array[List1.len, int]
for i in 0..list.high:
list[i] = parseInt($List1[i] & $List2[i] & $List3[i])
 
echo "list = ", list
</syntaxhighlight>
 
{{out}}
<pre>list = [11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
</pre>
 
Line 514 ⟶ 707:
<pre>
{11019,21120,31221,41322,51423,61524,71625,81726,91827}{11019,21120,31221,41322,51423,61524,71625,81726,91827}
</pre>
 
=={{header|PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<syntaxhighlight lang="plm">
100H: /* FORM A LIST OF STRINGS BY CONCATENATING NUMBERS FROM 3 LISTS */
 
/* CP/M BDOS SYSTEM CALLS AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$STRING( .( 0DH, 0AH, '$' ) ); END;
 
TO$STRING: PROCEDURE( N, S ); /* CONVERTS N TO A STRING AT S */
DECLARE ( N, S ) ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
DECLARE S$POS BYTE, S$STR BASED S ( 6 )BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
S$POS = 0;
DO W = W TO LAST( N$STR );
S$STR( S$POS ) = N$STR( W );
S$POS = S$POS + 1;
END;
END TO$STRING;
STR$LENGTH: PROCEDURE( S )ADDRESS; /* RETURNS THE LENGTH OF S */
DECLARE S ADDRESS;
DECLARE LEN ADDRESS, S$PTR ADDRESS, S$CH BASED S$PTR BYTE;
S$PTR = S;
LEN = 0;
DO WHILE S$CH <> '$';
LEN = LEN + 1;
S$PTR = S$PTR + 1;
END;
RETURN LEN;
END STR$LENGTH;
 
DECLARE LIST1 DATA( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) /* THREE LISTS */
, LIST2 DATA( 10, 11, 12, 13, 14, 15, 16, 17, 18 ) /* OF BYTE */
, LIST3 DATA( 19, 20, 21, 22, 23, 24, 25, 26, 27 ) /* VALUES */
;
 
DECLARE RESULT ( 11 )ADDRESS; /* WILL HOLD THE CONCATENATED STRINGS */
 
DECLARE TEXT$BUFFER ( 256 )BYTE; /* WILL HOLD THE TEXT OF THE STRINGS */
DECLARE TEXT$PTR ADDRESS;
TEXT$PTR = .TEXT$BUFFER;
 
DECLARE I BYTE;
DO I = 0 TO LAST( LIST1 );
RESULT( I ) = TEXT$PTR;
CALL TO$STRING( LIST1( I ), TEXT$PTR );
TEXT$PTR = TEXT$PTR + STR$LENGTH( TEXT$PTR );
CALL TO$STRING( LIST2( I ), TEXT$PTR );
TEXT$PTR = TEXT$PTR + STR$LENGTH( TEXT$PTR );
CALL TO$STRING( LIST3( I ), TEXT$PTR );
TEXT$PTR = TEXT$PTR + STR$LENGTH( TEXT$PTR ) + 1; /* KEEP THE FINAL $ */
END;
CALL PR$CHAR( '(' );
DO I = 0 TO LAST( LIST1 );
CALL PR$CHAR( ' ' );
CALL PR$STRING( RESULT( I ) );
END;
CALL PR$STRING( .' )$' );
CALL PR$NL;
 
EOF
 
</syntaxhighlight>
{{out}}
<pre>
( 11019 21120 31221 41322 51423 61524 71625 81726 91827 )
</pre>
 
Line 602 ⟶ 872:
<pre>
list = [11019,21120,31221,41322,51423,61524,71625,81726,91827][11019,21120,31221,41322,51423,61524,71625,81726,91827]
</pre>
 
=={{header|RPL}}==
Using the basic instruction set:
≪ 3 →LIST → lists
≪ { } 1 lists 1 GET SIZE '''FOR''' j
"" 1 3 '''FOR''' k lists k GET j GET →STR + '''NEXT''' STR→ + '''NEXT'''
≫ ≫ '<span style="color:blue">TASK</span>' STO
Using the extended instruction set introduced in 2003:
{{works with|HP|49}}
≪ 3 ≪ →STR + + STR→ ≫ DOLIST
≫ '<span style="color:blue">TASK</span>' STO
'''Input:'''
{ 1 2 3 4 5 6 7 8 9 } { 10 11 12 13 14 15 16 17 18 } { 19 20 21 22 23 24 25 26 27 } <span style="color:blue">TASK</span>
{{out}}
<pre>
1: { 11019 21120 31221 41322 51423 61524 71625 81726 91827 }
</pre>
 
Line 644 ⟶ 931:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var list1 = (1..9).toList
var list2 = (10..18).toList
var list3 = (19..27).toList
38

edits