Minimal numbers of three lists at same position: Difference between revisions
Content added Content deleted
(Blanked the page) |
|||
Line 1: | Line 1: | ||
{{Draft task}} |
|||
;Task: |
|||
<br>Let gine three lists: |
|||
<br>list1 = [9,18,27,2,65,43,78,11,2] |
|||
<br>list2 = [2,27,36,1,14,89,25,9,15] |
|||
<br>list3 = [1,45,78,5,11,95,14,25,9] |
|||
<br>Let create minList which contain minimal number of three lists at same position. |
|||
=={{header|Perl}}== |
|||
<lang perl>#!/usr/bin/perl |
|||
use strict; |
|||
use warnings; |
|||
use List::Util qw( min ); |
|||
my $list1 = [9,18,27,2,65,43,78,11,2]; |
|||
my $list2 = [2,27,36,1,14,89,25,9,15]; |
|||
my $list3 = [1,45,78,5,11,95,14,25,9]; |
|||
my @minlist = map min($list1->[$_], $list2->[$_], $list3->[$_]), 0 .. $#$list1; |
|||
use Data::Dump 'dd'; dd \@minlist;</lang> |
|||
{{out}} |
|||
<pre> |
|||
[1, 18, 27, 1, 11, 43, 14, 9, 2] |
|||
</pre> |
|||
=={{header|Phix}}== |
|||
Duplicate of [[Minimum_numbers_of_three_lists#Phix]] (except for different constants and 9 numbers in each list instead of 5) |
|||
=={{header|Ring}}== |
|||
<lang ring> |
|||
see "working..." + nl |
|||
list1 = [9,18,27,2,65,43,78,11,2] |
|||
list2 = [2,27,36,1,14,89,25,9,15] |
|||
list3 = [1,45,78,5,11,95,14,25,9] |
|||
list = [] |
|||
minList = [] |
|||
len = len(list1) |
|||
for n = 1 to len |
|||
add(minList,list1[n]) |
|||
add(minList,list2[n]) |
|||
add(minList,list3[n]) |
|||
minList = sort(minList) |
|||
min = minList[1] |
|||
add(list,min) |
|||
minList = [] |
|||
next |
|||
showArray(list) |
|||
see nl + "done..." + nl |
|||
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> |
|||
{{out}} |
|||
<pre> |
|||
working... |
|||
[1,18,27,1,11,43,14,9,2] |
|||
done... |
|||
</pre> |