Jump to content

Minimum numbers of three lists: Difference between revisions

m
syntax highlighting fixup automation
No edit summary
m (syntax highlighting fixup automation)
Line 17:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V numbers1 = [5, 45, 23, 21, 67]
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)</langsyntaxhighlight>
 
{{out}}
Line 31:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io; use Ada.Text_Io;
 
procedure Minimum_Three_Lists is
Line 58:
end loop;
New_Line;
end Minimum_Three_Lists;</langsyntaxhighlight>
{{out}}
<pre> 5 22 12 21 38</pre>
Line 65:
Generallising a little...
{{libheader|ALGOL 68-rows}}
<langsyntaxhighlight lang="algol68">BEGIN # construct a list of the minimum values of some other lists #
# 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</langsyntaxhighlight>
{{out}}
<pre>
Line 104:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin % show the minimum elements of three lists %
integer array numbers1, numbers2, numbers3 ( 1 :: 5 );
integer pos;
Line 117:
writeon( i_w := 1, s_w := 0, " ", m )
end for_i;
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 124:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Numbers1 := [5,45,23,21,67]
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, ", ") . "]"</langsyntaxhighlight>
{{out}}
<pre>[5, 22, 12, 21, 38]</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MINIMUM_NUMBERS_OF_THREE_LISTS.AWK
BEGIN {
Line 161:
}
function min(x,y) { return((x < y) ? x : y) }
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 168:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int min(int a, int b) {
Line 187:
printf("\n");
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 195:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// 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>
</lang>
{{out}}
<pre>
Line 207:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang="factor">USING: math.order sequences prettyprint ;
 
{ 5 45 23 21 67 } { 43 22 78 46 38 } { 9 98 12 98 53 }
[ min min ] 3map .</langsyntaxhighlight>
{{out}}
<pre>
Line 217:
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">[numbers1] := [(5,45,23,21,67)];
[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;</langsyntaxhighlight>
 
{{out}}<pre>
Line 237:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#define min(a, b) Iif(a<b,a,b)
 
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</langsyntaxhighlight>
 
{{out}}<pre>
Line 256:
=={{header|Go}}==
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 272:
}
fmt.Println(numbers)
}</langsyntaxhighlight>
 
{{out}}
Line 280:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List (transpose)
 
numbers1, numbers2, numbers3 :: [Integer]
Line 292:
minimum
<$> transpose
[numbers1, numbers2, numbers3]</langsyntaxhighlight>
{{Out}}
<pre>[5,22,12,21,38]</pre>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">(() => {
"use strict";
 
Line 342:
// MAIN ---
return JSON.stringify(main());
})();</langsyntaxhighlight>
{{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:<langsyntaxhighlight lang="jq">def numbers1: [ 5, 45, 23, 21, 67];
def numbers2: [43, 22, 78, 46, 38];
def numbers3: [ 9, 98, 12, 98, 53];</langsyntaxhighlight>
'''Mirroring the requirements'''
<langsyntaxhighlight lang="jq">[range(0;5)
| [numbers1[.], numbers2[.], numbers3[.]] | min]</langsyntaxhighlight>
'''Functional solution'''
<langsyntaxhighlight lang="jq">[numbers1, numbers2, numbers3]
| transpose
| map(min)</langsyntaxhighlight>
{{out}}
<pre>
Line 366:
=={{header|Julia}}==
Computed in the REPL, using matrix functions.
<langsyntaxhighlight lang="julia">
julia> Numbers1 = [5,45,23,21,67]
5-element Vector{Int64}:
Line 406:
21
38
</syntaxhighlight>
</lang>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Min /@ Transpose@{{5, 45, 23, 21, 67}, {43, 22, 78, 46, 38}, {9, 98,
12, 98, 53}}</langsyntaxhighlight>
 
{{out}}<pre>
Line 416:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">const
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</langsyntaxhighlight>
 
{{out}}
Line 432:
 
=={{header|ooRexx}}==
<langsyntaxhighlight lang="oorexx">/* REXX */
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)</langsyntaxhighlight>
{{out}}
<pre>[5 22 12 21 38]</pre>
Line 446:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use List::Util 'min';
Line 454:
for my $i (0 .. $#{ $lists[0] }) {
print ' ' . min map { $lists[$_][$i] } 0..$#lists;
}</langsyntaxhighlight>
{{out}}
<pre> 5 22 12 21 38</pre>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 472:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
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.</langsyntaxhighlight>
{{out}}
<pre>
Line 542:
 
=={{header|Python}}==
<langsyntaxhighlight Pythonlang="python">numbers1 = [5,45,23,21,67]
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)</langsyntaxhighlight>
{{Output}}
<pre>[5, 22, 12, 21, 38]</pre>
Line 554:
 
Or, in terms of zip:
<langsyntaxhighlight lang="python">'''Minimum value in each column'''
 
numbers1 = [5, 45, 23, 21, 67]
Line 563:
min(x) for x
in zip(*[numbers1, numbers2, numbers3])
])</langsyntaxhighlight>
{{Out}}
<pre>[5, 22, 12, 21, 38]</pre>
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>say [Zmin] (5,45,23,21,67), (43,22,78,46,38), (9,98,12,98,53);</langsyntaxhighlight>
{{out}}
<pre>(5 22 12 21 38)</pre>
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">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</langsyntaxhighlight>
{{out}}
<pre>
Line 593:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/* 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)</langsyntaxhighlight>
{{out}}
<pre>5 22 12 21 38</pre>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">see "? "working..."
 
Num1 = [ 5,45,23,21,67]
Line 627:
rv = ar[1]
for n = 2 to len(ar) rv += "," + ar[n] next
return "[" + rv + "]"</langsyntaxhighlight>
{{out}}
<pre>
Line 636:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">numbers1 = [ 5, 45, 23, 21, 67]
numbers2 = [43, 22, 78, 46, 38]
numbers3 = [ 9, 98, 12, 98, 53]
p [numbers1, numbers2, numbers3].transpose.map(&:min)</langsyntaxhighlight>
{{out}}
<pre>[5, 22, 12, 21, 38]
Line 646:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var lists = [
[ 5, 45, 23, 21, 67],
[43, 22, 78, 46, 38],
Line 652:
]
 
say lists.zip.map{.min}</langsyntaxhighlight>
 
{{out}}
Line 660:
 
=={{header|Vlang}}==
<langsyntaxhighlight lang="vlang">import math
fn main() {
numbers1 := [5, 45, 23, 21, 67]!
Line 670:
}
println(numbers)
}</langsyntaxhighlight>
{{out}}
<pre>[5, 22, 12, 21, 38]</pre>
 
=={{header|Wren}}==
<langsyntaxhighlight lang="ecmascript">var numbers1 = [ 5, 45, 23, 21, 67]
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)</langsyntaxhighlight>
 
{{out}}
Line 688:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func Min(A, B);
int A, B;
return if A<B then A else B;
Line 700:
ChOut(0, ^ );
];
]</langsyntaxhighlight>
 
{{out}}
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.