Append numbers at same position in strings: Difference between revisions

m
syntax highlighting fixup automation
(add lambdatalk)
m (syntax highlighting fixup automation)
Line 11:
 
=={{header|11l}}==
<langsyntaxhighlight lang=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))</langsyntaxhighlight>
 
{{out}}
Line 23:
 
=={{header|Ada}}==
<langsyntaxhighlight lang=Ada>with Ada.Text_Io;
with Ada.Strings.Fixed;
 
Line 54:
 
Put (List); New_Line;
end Append_Numbers;</langsyntaxhighlight>
{{out}}
<pre>
Line 61:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang=algol68>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 )
Line 76:
OD;
print( ( " ]", newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 84:
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight lang=apl>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←⍎¨∘(,/)∘(⍕¨)∘(⍉↑)
append list1 list2 list3</langsyntaxhighlight>
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang=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]
Line 102:
for i, v in list4
result .= v ", "
MsgBox % "[" trim(result, ", ") "]"</langsyntaxhighlight>
{{out}}
<pre>[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]</pre>
 
=={{header|AWK}}==
<langsyntaxhighlight lang=AWK>
# syntax: GAWK -f APPEND_NUMBERS_AT_SAME_POSITION_IN_STRINGS.AWK
BEGIN {
Line 124:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 131:
 
=={{header|C}}==
<langsyntaxhighlight lang=c>#include<stdio.h>
#include<stdlib.h>
 
Line 139:
for(i=0;i<9;i++) printf( "%d%d%d ", list[0][i], list[1][i], list[2][i] );
return 0;
}</langsyntaxhighlight>
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
=={{header|CLU}}==
<langsyntaxhighlight lang=clu>append = proc (lists: sequence[sequence[int]]) returns (sequence[int])
n_lists: int := sequence[sequence[int]]$size(lists)
n_items: int := sequence[int]$size(lists[1])
Line 166:
stream$puts(po, int$unparse(n) || " ")
end
end start_up</langsyntaxhighlight>
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang=fsharp>
// Append numbers at same position in strings. Nigel Galloway: December 29th., 2021
let 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 ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 183:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang=factor>USING: kernel math.parser math.ranges present prettyprint
sequences ;
 
27 [1,b] 9 cut 9 cut [ [ present ] tri@ 3append dec> ] 3map .</langsyntaxhighlight>
{{out}}
<pre>
Line 193:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang=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}
Line 203:
catlist(i) = val(temp)
print catlist(i);" ";
next i</langsyntaxhighlight>
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang=go>package main
 
import "fmt"
Line 220:
}
fmt.Println(list)
}</langsyntaxhighlight>
 
{{out}}
Line 230:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<langsyntaxhighlight lang=jq>def list1 : [ range(1;10) ];
def list2 : [ range(10; 19)];
def list3 : [ range(19; 28) ];
Line 236:
[list1, list2, list3]
| transpose
| map( map(tostring) | add | tonumber)</langsyntaxhighlight>
{{out}}
<pre>
Line 243:
 
=={{header|Julia}}==
<langsyntaxhighlight lang=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"]
</syntaxhighlight>
</lang>
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang=Scheme>
Using a function returning an array
 
Line 282:
} {S.serie 0 8}}
-> 11019 21120 31221 41322 51423 61524 71625 81726 91827
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>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[
FromDigits@Flatten[IntegerDigits /@ {##}] &, {list1, list2, list3}]</langsyntaxhighlight>
 
{{out}}<pre>
Line 297:
=={{header|Pascal}}==
The following <tt>program</tt> requires (at least) an ISO 7185-compliant processor supporting features at level&nbsp;1 (specifically “conformant array parameters” are being used).
<langsyntaxhighlight lang=pascal>program appendNumbersAtSamePositionInStrings(output);
 
type
Line 379:
writeLn(list0[i])
end
end.</langsyntaxhighlight>
{{out}}
11019
Line 392:
 
=={{header|Perl}}==
<langsyntaxhighlight lang=perl>use strict;
use warnings;
 
Line 409:
map {print $f[$_][$i] } 0 .. $#f and print ' '
}
print "\n";</langsyntaxhighlight>
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827
Line 415:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%V%V\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">vslice</span><span style="color: #0000FF;">,{{</span><span style="color: #7060A8;">sq_mul</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">9</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">18</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">27</span><span style="color: #0000FF;">,</span><span style="color: #000000;">19</span><span style="color: #0000FF;">)},{</span><span style="color: #000000;">1e4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1e2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">})},</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)}),</span><span style="color: #7060A8;">sum</span><span style="color: #0000FF;">),</span><span style="color: #000000;">2</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 424:
 
=={{header|Python}}==
<langsyntaxhighlight lang=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]
Line 431:
''.join(str(n) for n in z) for z
in zip(list1, list2, list3)
])</langsyntaxhighlight>
 
 
which is also expressible as a map:
<langsyntaxhighlight lang=python>print(list(map(
lambda x, y, z: f'{x}{y}{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]
)))</langsyntaxhighlight>
{{out}}
<pre>['11019', '21120', '31221', '41322', '51423', '61524', '71625', '81726', '91827']</pre>
Line 447:
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.)
 
<langsyntaxhighlight lang=perl6>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;</langsyntaxhighlight>
{{out}}
<pre>([11019 21120 31221 41322 51423 61524 71625 81726 91827] [11019 21120 31221 41322 51423 61524 71625 81726 91827])</pre>
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
load "stdlib.ring"
list1 = [1,2,3,4,5,6,7,8,9]
Line 478:
txt = txt + "]"
see txt
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 485:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang=ruby>list1 = (1..9) .to_a
list2 = (10..18).to_a
list3 = (19..27).to_a
 
p list = [list1, list2, list3].transpose.map{|trio| trio.join.to_i }</langsyntaxhighlight>
{{out}}
<pre>[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
Line 495:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang=ruby>var lists = [
[1,2,3,4,5,6,7,8,9],
[10,11,12,13,14,15,16,17,18],
Line 501:
]
 
say lists.zip.map_2d {|*a| a.join.to_i }</langsyntaxhighlight>
 
{{out}}
Line 510:
=={{header|Vlang}}==
{{trans|go}}
<langsyntaxhighlight lang=vlang>fn main() {
list1 := [1, 2, 3, 4, 5, 6, 7, 8, 9]!
list2 := [10, 11, 12, 13, 14, 15, 16, 17, 18]!
Line 519:
}
println(list)
}</langsyntaxhighlight>
{{out}}
<pre>[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]</pre>
 
=={{header|Wren}}==
<langsyntaxhighlight lang=ecmascript>var list1 = (1..9).toList
var list2 = (10..18).toList
var list3 = (19..27).toList
var list = (0..8).map { |i| 1e4*list1[i] + 100*list2[i] + list3[i] }.toList
System.print(list)</langsyntaxhighlight>
 
{{out}}
Line 536:
 
=={{header|XPL0}}==
<langsyntaxhighlight lang=XPL0>intI;forI:=1to9do[IntOut(0,I*10000+(I+9)*100+I+18);ChOut(0,^ )]</langsyntaxhighlight>
{{out}}
<pre>
10,339

edits