Minimum numbers of three lists: Difference between revisions
m
syntax highlighting fixup automation
No edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 17:
{{trans|Python}}
<
V numbers2 = [43, 22, 78, 46, 38]
V numbers3 = [9, 98, 12, 98, 53]
Line 23:
V numbers = (0 .< numbers1.len).map(i -> min(:numbers1[i], :numbers2[i], :numbers3[i]))
print(numbers)</
{{out}}
Line 31:
=={{header|Ada}}==
<
procedure Minimum_Three_Lists is
Line 58:
end loop;
New_Line;
end Minimum_Three_Lists;</
{{out}}
<pre> 5 22 12 21 38</pre>
Line 65:
Generallising a little...
{{libheader|ALGOL 68-rows}}
<
# lists are represented by arrays in this sample #
PR read "rows.incl.a68" PR # row-related utilities #
Line 97:
# display the minimum values for each element in the lists #
SHOW min( ( numbers1, numbers2, numbers3 ) )
END</
{{out}}
<pre>
Line 104:
=={{header|ALGOL W}}==
<
integer array numbers1, numbers2, numbers3 ( 1 :: 5 );
integer pos;
Line 117:
writeon( i_w := 1, s_w := 0, " ", m )
end for_i;
end.</
{{out}}
<pre>
Line 124:
=={{header|AutoHotkey}}==
<
Numbers2 := [43,22,78,46,38]
Numbers3 := [9,98,12,98,53]
Line 138:
for i, v in Numbers
result .= v ", "
MsgBox % result := "[" . Trim(result, ", ") . "]"</
{{out}}
<pre>[5, 22, 12, 21, 38]</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f MINIMUM_NUMBERS_OF_THREE_LISTS.AWK
BEGIN {
Line 161:
}
function min(x,y) { return((x < y) ? x : y) }
</syntaxhighlight>
{{out}}
<pre>
Line 168:
=={{header|C}}==
<
int min(int a, int b) {
Line 187:
printf("\n");
return 0;
}</
{{out}}
Line 195:
=={{header|F_Sharp|F#}}==
<
// Minimum numbers of three lists. Nigel Galloway: October 26th., 2021
let N1,N2,N3=[5;45;23;21;67],[43;22;78;46;38],[9;98;12;98;53]
printfn "%A" (List.zip3 N1 N2 N3|>List.map(fun(n,g,l)->min (min n g) l))
</syntaxhighlight>
{{out}}
<pre>
Line 207:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
{ 5 45 23 21 67 } { 43 22 78 46 38 } { 9 98 12 98 53 }
[ min min ] 3map .</
{{out}}
<pre>
Line 217:
=={{header|Fermat}}==
<
[numbers2] := [(43,22,78,46,38)];
[numbers3] := [(9,98,12,98,53)];
Line 226:
Return(c[n]).;
for i = 1 to 5 do !!Minby( [numbers1], [numbers2], [numbers3], i ) od;</
{{out}}<pre>
Line 237:
=={{header|FreeBASIC}}==
<
dim as integer numbers(1 to 3, 1 to 5) = _
Line 244:
for i as uinteger = 1 to 5
print min( numbers(1, i), min(numbers(2,i), numbers(3, i) ) )
next i</
{{out}}<pre>
Line 256:
=={{header|Go}}==
{{libheader|Go-rcu}}
<
import (
Line 272:
}
fmt.Println(numbers)
}</
{{out}}
Line 280:
=={{header|Haskell}}==
<
numbers1, numbers2, numbers3 :: [Integer]
Line 292:
minimum
<$> transpose
[numbers1, numbers2, numbers3]</
{{Out}}
<pre>[5,22,12,21,38]</pre>
=={{header|JavaScript}}==
<
"use strict";
Line 342:
// MAIN ---
return JSON.stringify(main());
})();</
{{Out}}
<pre>[5,22,12,21,38]</pre>
Line 349:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
Two solutions are presented - an iterative one that mirrors the problem description, and one that is functional:<
def numbers2: [43, 22, 78, 46, 38];
def numbers3: [ 9, 98, 12, 98, 53];</
'''Mirroring the requirements'''
<
| [numbers1[.], numbers2[.], numbers3[.]] | min]</
'''Functional solution'''
<
| transpose
| map(min)</
{{out}}
<pre>
Line 366:
=={{header|Julia}}==
Computed in the REPL, using matrix functions.
<
julia> Numbers1 = [5,45,23,21,67]
5-element Vector{Int64}:
Line 406:
21
38
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
12, 98, 53}}</
{{out}}<pre>
Line 416:
=={{header|Nim}}==
<
Numbers1 = [ 5, 45, 23, 21, 67]
Numbers2 = [43, 22, 78, 46, 38]
Line 426:
numbers[i] = min(min(Numbers1[i], Numbers2[i]), Numbers3[i])
echo numbers</
{{out}}
Line 432:
=={{header|ooRexx}}==
<
l.1=.array~of( 5, 45, 23, 21, 67)
l.2=.array~of(43, 22, 78, 46, 38)
Line 440:
o=o min(l.1[i],l.2[i],l.3[i])
End
Say strip(o)</
{{out}}
<pre>[5 22 12 21 38]</pre>
Line 446:
=={{header|Perl}}==
<
use warnings;
use List::Util 'min';
Line 454:
for my $i (0 .. $#{ $lists[0] }) {
print ' ' . min map { $lists[$_][$i] } 0..$#lists;
}</
{{out}}
<pre> 5 22 12 21 38</pre>
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">N123</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">45</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">23</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">21</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">67</span><span style="color: #0000FF;">},</span>
Line 465:
<span style="color: #0000FF;">{</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">98</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">98</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">53</span><span style="color: #0000FF;">}}</span>
<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\n"</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: #000000;">N123</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)}),</span><span style="color: #7060A8;">minsq</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
<pre>
Line 472:
=={{header|Plain English}}==
<
Start up.
Create a first list and a second list and a third list.
Line 535:
If the entry's next is not nil, write ", " on the console without advancing.
Put the entry's next into the entry.
Repeat.</
{{out}}
<pre>
Line 542:
=={{header|Python}}==
<
numbers2 = [43,22,78,46,38]
numbers3 = [9,98,12,98,53]
Line 548:
numbers = [min(numbers1[i],numbers2[i],numbers3[i]) for i in range(0,len(numbers1))]
print(numbers)</
{{Output}}
<pre>[5, 22, 12, 21, 38]</pre>
Line 554:
Or, in terms of zip:
<
numbers1 = [5, 45, 23, 21, 67]
Line 563:
min(x) for x
in zip(*[numbers1, numbers2, numbers3])
])</
{{Out}}
<pre>[5, 22, 12, 21, 38]</pre>
=={{header|Raku}}==
<syntaxhighlight lang="raku"
{{out}}
<pre>(5 22 12 21 38)</pre>
=={{header|Red}}==
<
Red-version: 0.6.4
Description: "Find the element-wise minimum of three lists"
Line 586:
result/:i: min min numbers1/:i numbers2/:i numbers3/:i
]
print result</
{{out}}
<pre>
Line 593:
=={{header|REXX}}==
<
w= 5 45 23 21 67 43 22 78 46 38 9 98 12 98 53
Do i=1 To 3
Line 604:
o=o min(l.1.j,l.2.j,l.3.j)
End
Say strip(o)</
{{out}}
<pre>5 22 12 21 38</pre>
=={{header|Ring}}==
<
Num1 = [ 5,45,23,21,67]
Line 627:
rv = ar[1]
for n = 2 to len(ar) rv += "," + ar[n] next
return "[" + rv + "]"</
{{out}}
<pre>
Line 636:
=={{header|Ruby}}==
<
numbers2 = [43, 22, 78, 46, 38]
numbers3 = [ 9, 98, 12, 98, 53]
p [numbers1, numbers2, numbers3].transpose.map(&:min)</
{{out}}
<pre>[5, 22, 12, 21, 38]
Line 646:
=={{header|Sidef}}==
<
[ 5, 45, 23, 21, 67],
[43, 22, 78, 46, 38],
Line 652:
]
say lists.zip.map{.min}</
{{out}}
Line 660:
=={{header|Vlang}}==
<
fn main() {
numbers1 := [5, 45, 23, 21, 67]!
Line 670:
}
println(numbers)
}</
{{out}}
<pre>[5, 22, 12, 21, 38]</pre>
=={{header|Wren}}==
<
var numbers2 = [43, 22, 78, 46, 38]
var numbers3 = [ 9, 98, 12, 98, 53]
var numbers = List.filled(5, 0)
for (n in 0..4) numbers[n] = numbers1[n].min(numbers2[n]).min(numbers3[n])
System.print(numbers)</
{{out}}
Line 688:
=={{header|XPL0}}==
<
int A, B;
return if A<B then A else B;
Line 700:
ChOut(0, ^ );
];
]</
{{out}}
|