aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/deadmarshal/d/ch1.d
blob: 63b96d4b4c95834bb30cf5ac900c5f04ec648748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import std.stdio:writeln;
import std.algorithm:max;

size_t max_positive_negative(int[] arr)
{
  size_t neg = 0, pos = 0;
  foreach(ref e;arr) if(e < 0) neg++; else pos++;
  return max(neg,pos);
}

void main()
{
  int[] arr1 = [-3,1,2,-1,3,-2,4];
  int[] arr2 = [-1,-2,-3,1];
  int[] arr3 = [1,2];
  writeln(max_positive_negative(arr1));
  writeln(max_positive_negative(arr2));
  writeln(max_positive_negative(arr3));
}