I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

# Append numbers at same position in strings

Append numbers at same position in strings is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Let given three list:
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]
Append numbers at same position in strings.
The result should be:
list = [11019,21120,31221,41322,51423,61524,71625,81726,91827]

## 11l

`V list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]V list2 = [10, 11, 12, 13, 14, 15, 16, 17, 18]V list3 = [19, 20, 21, 22, 23, 24, 25, 26, 27] print(zip(list1, list2, list3).map((n1, n2, n3) -> String(n1)‘’n2‘’n3))`
Output:
```[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
```

`with Ada.Text_Io;with Ada.Strings.Fixed; procedure Append_Numbers is    use Ada.Text_Io, Ada.Strings;    type List_Type is array (Positive range <>) of Natural;    procedure Put (List : List_Type) is   begin      Put ("[");      for E of List loop         Put (Natural'Image (E));      end loop;      Put ("]");   end Put;    List_1 : constant List_Type := ( 1,  2,  3,  4,  5,  6,  7,  8,  9);   List_2 : constant List_Type := (10, 11, 12, 13, 14, 15, 16, 17, 18);   List_3 : constant List_Type := (19, 20, 21, 22, 23, 24, 25, 26, 27);   List   : List_Type (List_1'Range);begin   for A in List'Range loop      List (A) := Natural'Value        (Fixed.Trim (Natural'Image (List_1 (A)), Left) &         Fixed.Trim (Natural'Image (List_2 (A)), Left) &         Fixed.Trim (Natural'Image (List_3 (A)), Left));   end loop;    Put (List);  New_Line;end Append_Numbers;`
Output:
```[ 11019 21120 31221 41322 51423 61524 71625 81726 91827]
```

## ALGOL 68

`BEGIN # form a list of strings by concatenating numbers from 3 lists #    []INT 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 )        ;    [ LWB list1 : UPB list1 ]STRING result;    FOR i FROM LWB list1 TO UPB list1 DO        result[ i ] := whole( list1[ i ], 0 ) + whole( list2[ i ], 0 ) + whole( list3[ i ], 0 )    OD;    STRING prefix := "[ ";    FOR i FROM LWB result TO UPB result DO        print( ( prefix, result[ i ] ) );        prefix := ", "    OD;    print( ( " ]", newline ) )END`
Output:
```[ 11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827 ]
```

## AutoHotkey

`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]list4 := [] for i, v in list1    list4.Push(v . list2[i] . list3[i])for i, v in list4    result .= v ", "MsgBox % "[" trim(result, ", ") "]"`
Output:
`[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]`

## AWK

` # syntax: GAWK -f APPEND_NUMBERS_AT_SAME_POSITION_IN_STRINGS.AWKBEGIN {    n1 = split("1,2,3,4,5,6,7,8,9",list1,",")    n2 = split("10,11,12,13,14,15,16,17,18",list2,",")    n3 = split("19,20,21,22,23,24,25,26,27",list3,",")    if (n1 != n2 || n1 != n3) {      print("error: arrays must be same length")      exit(1)    }    for (i=1; i<=n1; i++) {      list[i] = list1[i] list2[i] list3[i]      printf("%s ",list[i])    }    printf("\n")    exit(0)} `
Output:
```11019 21120 31221 41322 51423 61524 71625 81726 91827
```

## 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;}`
Output:
`11019  21120  31221  41322  51423  61524  71625  81726  91827`

## F#

` // Append numbers at same position in strings. Nigel Galloway: December 29th., 2021let rec fG n g l=seq{match n,g,l with (n::x,g::y,l::z)->yield int((string n)+(string g)+(string l)); yield! fG x y z |_->()}fG [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] |> Seq.iter(printf "%d "); printfn ""  `
Output:
```11019 21120 31221 41322 51423 61524 71625 81726 91827
```

## Factor

Works with: Factor version 0.99 2021-06-02
`USING: kernel math.parser math.ranges present prettyprintsequences ; 27 [1,b] 9 cut 9 cut [ [ present ] [email protected] 3append dec> ] 3map .`
Output:
```{ 11019 21120 31221 41322 51423 61524 71625 81726 91827 }
```

## FreeBASIC

`dim as integer list1(1 to 9) = {1,2,3,4,5,6,7,8,9}dim as integer list2(1 to 9) = {10,11,12,13,14,15,16,17,18}dim as integer list3(1 to 9) = {19,20,21,22,23,24,25,26,27}dim as integer catlist(1 to 9)dim as string temp for i as uinteger = 1 to 9    temp = str(list1(i)) + str(list2(i)) + str(list3(i))    catlist(i) = val(temp)    print catlist(i);" ";next i`
Output:
`11019  21120  31221  41322  51423  61524  71625  81726  91827`

## Go

`package main import "fmt" func main() {    list1 := [9]int{1, 2, 3, 4, 5, 6, 7, 8, 9}    list2 := [9]int{10, 11, 12, 13, 14, 15, 16, 17, 18}    list3 := [9]int{19, 20, 21, 22, 23, 24, 25, 26, 27}    var list [9]int    for i := 0; i < 9; i++ {        list[i] = list1[i]*1e4 + list2[i]*1e2 + list3[i]    }    fmt.Println(list)}`
Output:
```[11019 21120 31221 41322 51423 61524 71625 81726 91827]
```

## jq

Works with: jq

Works with gojq, the Go implementation of jq

`def list1 : [ range(1;10) ];def list2 : [ range(10; 19)];def list3 : [ range(19; 28) ]; [list1, list2, list3]| transpose| map( map(tostring) | add | tonumber)`
Output:
```[11019,21120,31221,41322,51423,61524,71625,81726,91827]
```

## Julia

`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] println([prod(string(n) for n in z) for z in zip(list1, list2, list3)]) # ["11019", "21120", "31221", "41322", "51423", "61524", "71625", "81726", "91827"] `

## Mathematica / Wolfram Language

`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};MapThread[ [email protected][IntegerDigits /@ {##}] &, {list1, list2, list3}]`
Output:
```
{11019,21120,31221,41322,51423,61524,71625,81726,91827}

```

## Perl

`use strict;use warnings; my @a = < 1  2  3  4  5  6  7  8  9>;my @b = <10 11 12 13 14 15 16 17 18>;my @c = <19 20 21 22 23 24 25 26 27>;my @d = <1  2  2  2  2  2  2  2  2 >;my @e = < 9  0  1  2  3  4  5  6  7>;my @f = (\@a, \@b, \@d, \@e); # for just the three given listsprint \$a[\$_] . \$b[\$_] . \$c[\$_] . ' ' for 0..\$#a; print "\n"; # for arbitrary number of listsfor my \$i (0 .. \$#{\$f[0]}) {    map {print \$f[\$_][\$i] } 0 .. \$#f and print ' '}print "\n";`
Output:
```11019 21120 31221 41322 51423 61524 71625 81726 91827
11019 21120 31221 41322 51423 61524 71625 81726 91827```

## Phix

```printf(1,"%V%V\n",repeat(apply(apply(true,vslice,{{sq_mul({tagset(9),tagset(18,10),tagset(27,19)},{1e4,1e2,1})},tagset(9)}),sum),2))
```
Output:
```{11019,21120,31221,41322,51423,61524,71625,81726,91827}{11019,21120,31221,41322,51423,61524,71625,81726,91827}
```

## Python

`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] print([    ''.join(str(n) for n in z) for z    in zip(list1, list2, list3)])`
Output:
`['11019', '21120', '31221', '41322', '51423', '61524', '71625', '81726', '91827']`

## Raku

Not really seeing why we need to show the result twice but that's what the requirement is... ¯\_(ツ)_/¯ (I find myself making that gesture often in response to Calmosofts tasks.)

`say [[Z~] [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]] xx 2;`
Output:
`([11019 21120 31221 41322 51423 61524 71625 81726 91827] [11019 21120 31221 41322 51423 61524 71625 81726 91827])`

## Ring

` load "stdlib.ring"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]list = [] for n = 1 to len(list1)    str1 = string(list1[n])    str2 = string(list2[n])    str3 = string(list3[n])    str = str1 + str2 + str3    add(list,str)next showArray(list) func showArray(array)     txt = ""     see "["     for n = 1 to len(array)         txt = txt + array[n] + ","     next     txt = left(txt,len(txt)-1)     txt = txt + "]"     see txt `
Output:
```list = [11019,21120,31221,41322,51423,61524,71625,81726,91827][11019,21120,31221,41322,51423,61524,71625,81726,91827]
```

## Ruby

`list1 = (1..9)  .to_alist2 = (10..18).to_alist3 = (19..27).to_a p list = [list1, list2, list3].transpose.map{|trio| trio.join.to_i }`
Output:
```[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
```

## Sidef

`var lists = [    [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],] say lists.zip.map_2d {|*a| a.join.to_i }`
Output:
```[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
```

## Vlang

Translation of: go
`fn main() {    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]!    mut list := [9]int{}    for i in 0..9 {        list[i] = list1[i]*int(1e4) + list2[i]*int(1e2) + list3[i]    }    println(list)}`
Output:
`[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]`

## Wren

`var list1 = (1..9).toListvar list2 = (10..18).toListvar list3 = (19..27).toListvar list  = (0..8).map { |i| 1e4*list1[i] + 100*list2[i] + list3[i] }.toListSystem.print(list)`
Output:
```[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
```

## XPL0

`intI;forI:=1to9do[IntOut(0,I*10000+(I+9)*100+I+18);ChOut(0,^ )]`
Output:
```11019 21120 31221 41322 51423 61524 71625 81726 91827
```