Append numbers at same position in strings: Difference between revisions
Append numbers at same position in strings (view source)
Revision as of 01:02, 26 August 2022
, 1 year agosyntax highlighting fixup automation
(add lambdatalk) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 11:
=={{header|11l}}==
<
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))</
{{out}}
Line 23:
=={{header|Ada}}==
<
with Ada.Strings.Fixed;
Line 54:
Put (List); New_Line;
end Append_Numbers;</
{{out}}
<pre>
Line 61:
=={{header|ALGOL 68}}==
<
[]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</
{{out}}
<pre>
Line 84:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
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</
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
=={{header|AutoHotkey}}==
<
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, ", ") "]"</
{{out}}
<pre>[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]</pre>
=={{header|AWK}}==
<
# syntax: GAWK -f APPEND_NUMBERS_AT_SAME_POSITION_IN_STRINGS.AWK
BEGIN {
Line 124:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 131:
=={{header|C}}==
<
#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;
}</
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
=={{header|CLU}}==
<
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</
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
=={{header|F_Sharp|F#}}==
<
// 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>
{{out}}
<pre>
Line 183:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
sequences ;
27 [1,b] 9 cut 9 cut [ [ present ] tri@ 3append dec> ] 3map .</
{{out}}
<pre>
Line 193:
=={{header|FreeBASIC}}==
<
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</
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>
=={{header|Go}}==
<
import "fmt"
Line 220:
}
fmt.Println(list)
}</
{{out}}
Line 230:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<
def list2 : [ range(10; 19)];
def list3 : [ range(19; 28) ];
Line 236:
[list1, list2, list3]
| transpose
| map( map(tostring) | add | tonumber)</
{{out}}
<pre>
Line 243:
=={{header|Julia}}==
<
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>
=={{header|Lambdatalk}}==
<
Using a function returning an array
Line 282:
} {S.serie 0 8}}
-> 11019 21120 31221 41322 51423 61524 71625 81726 91827
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
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}]</
{{out}}<pre>
Line 297:
=={{header|Pascal}}==
The following <tt>program</tt> requires (at least) an ISO 7185-compliant processor supporting features at level 1 (specifically “conformant array parameters” are being used).
<
type
Line 379:
writeLn(list0[i])
end
end.</
{{out}}
11019
Line 392:
=={{header|Perl}}==
<
use warnings;
Line 409:
map {print $f[$_][$i] } 0 .. $#f and print ' '
}
print "\n";</
{{out}}
<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827
Line 415:
=={{header|Phix}}==
<!--<
<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>
<!--</
{{out}}
<pre>
Line 424:
=={{header|Python}}==
<
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)
])</
which is also expressible as a 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]
)))</
{{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.)
<
{{out}}
<pre>([11019 21120 31221 41322 51423 61524 71625 81726 91827] [11019 21120 31221 41322 51423 61524 71625 81726 91827])</pre>
=={{header|Ring}}==
<
load "stdlib.ring"
list1 = [1,2,3,4,5,6,7,8,9]
Line 478:
txt = txt + "]"
see txt
</syntaxhighlight>
{{out}}
<pre>
Line 485:
=={{header|Ruby}}==
<
list2 = (10..18).to_a
list3 = (19..27).to_a
p list = [list1, list2, list3].transpose.map{|trio| trio.join.to_i }</
{{out}}
<pre>[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]
Line 495:
=={{header|Sidef}}==
<
[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 }</
{{out}}
Line 510:
=={{header|Vlang}}==
{{trans|go}}
<
list1 := [1, 2, 3, 4, 5, 6, 7, 8, 9]!
list2 := [10, 11, 12, 13, 14, 15, 16, 17, 18]!
Line 519:
}
println(list)
}</
{{out}}
<pre>[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]</pre>
=={{header|Wren}}==
<
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)</
{{out}}
Line 536:
=={{header|XPL0}}==
<
{{out}}
<pre>
|