aboutsummaryrefslogtreecommitdiff
path: root/challenge-236/deadmarshal/d/ch1.d
blob: 29015b28a2d5b50ff723847d921d0d38fd2e5c2a (plain)
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
28
29
30
import std.stdio:writeln;

int exact_change(int[] arr)
{
  int[int] hash;
  foreach(e;arr)
  {
    if(e == 10) if(!--hash[5]) return false;
    else if(e == 20)
    {
      if(hash[5] && hash[10])
      {
	hash[5]--;
	hash[10]--;
      }
      else if(hash[5] > 2) hash[5] -= 3;
      else return false;
    }
    hash[e]++;
  }
  return true;
}

void main()
{
  writeln(exact_change([5,5,5,10,20]));
  writeln(exact_change([5,5,10,10,20]));
  writeln(exact_change([5,5,5,20]));
}