-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04b.m
More file actions
executable file
·24 lines (24 loc) · 852 Bytes
/
04b.m
File metadata and controls
executable file
·24 lines (24 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/octave -qf
fid=fopen('04.txt', 'r');
draws=dlmread(fid, ',', [0,0,0,99]);
data = fscanf(fid, '%f');
for i=1:100
card{i} = reshape(data((25*(i-1)+1):(25*i)), 5 , 5)';
endfor
cardsleft=ones(1,100);
mask=ones(1,100);
mask(draws(1:4)+1)=0; #not possible to get bingo during first four draws
for i=5:100
mask(draws(i)+1)=0;
for j=1:100
if (cardsleft(j)==1)
reduced = reshape(mask(card{j}(:)+1),5,5);
if (min([sum(reduced(:,1:5),1),sum(reduced(:,1:5),2)'])==0)
score = sum((card{j}.*reduced)(:))*draws(i);
cardsleft(j)=0;
endif
endif
endfor
if (cardsleft==0) break; endif
endfor
printf("The final score on the winning board will be %d\n", score);