Append numbers at same position in strings: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added Wren)
(add FreeBASIC)
Line 20: Line 20:
{ 11019 21120 31221 41322 51423 61524 71625 81726 91827 }
{ 11019 21120 31221 41322 51423 61524 71625 81726 91827 }
</pre>
</pre>

=={{header|FreeBASIC}}==
I'm assuming the requirement to show the list twice is a typo, so I show it only once.
<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}
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</lang>
{{out}}<pre>11019 21120 31221 41322 51423 61524 71625 81726 91827</pre>


=={{header|Raku}}==
=={{header|Raku}}==

Revision as of 09:50, 10 November 2021

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.
Task


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][11019,21120,31221,41322,51423,61524,71625,81726,91827]

Factor

Works with: Factor version 0.99 2021-06-02

<lang factor>USING: kernel math.parser math.ranges present prettyprint sequences ;

27 [1,b] 9 cut 9 cut [ [ present ] tri@ 3append dec> ] 3map .</lang>

Output:
{ 11019 21120 31221 41322 51423 61524 71625 81726 91827 }

FreeBASIC

I'm assuming the requirement to show the list twice is a typo, so I show it only once. <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} 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</lang>

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.)

<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;</lang>

Output:
([11019 21120 31221 41322 51423 61524 71625 81726 91827] [11019 21120 31221 41322 51423 61524 71625 81726 91827])

Ring

<lang 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

</lang>

Output:
list = [11019,21120,31221,41322,51423,61524,71625,81726,91827][11019,21120,31221,41322,51423,61524,71625,81726,91827]

Wren

<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)%(list)")</lang>

Output:
[11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827][11019, 21120, 31221, 41322, 51423, 61524, 71625, 81726, 91827]