Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc,clear
- raw=importdata('raw6');
- a=char(raw.textdata);
- b=a(301:600,:);
- a=a(1:300,:);
- %y2
- y2=raw.data+1;
- %Off = 0, On = 1, toggle = -1
- %Variable list: action, x1,y1,x2,y2
- grid=zeros(1000);
- %Part 2
- for i=1:300
- %action from a
- if a(i,2)=='u' %turn
- if a(i,7)=='n' %on
- action=1;
- else %off
- action=0;
- end
- else %toggle
- action=-1;
- end
- %x1 from a
- if a(i,2)=='u' %turn
- x1=str2num(a(i,9:12));
- else
- x1=str2num(a(i,8:10));
- end
- %y1 from b
- if b(i,2)==' '
- y1=str2num(b(i,1));
- else
- y1=str2num(b(i,1:3));
- end
- %x2 from b
- if b(i,2)==' '
- x2=str2num(b(i,11:13));
- else
- x2=str2num(b(i,12:15));
- end
- %0-999 -> 1-1000
- x1=x1+1;
- x2=x2+1;
- y1=y1+1;
- %Now go
- for j=x1:x2
- for k=y1:y2(i)
- switch action
- case 0 %off
- if grid(j,k) %not 0
- grid(j,k)=grid(j,k)-1;
- end
- case 1 %on
- grid(j,k)=grid(j,k)+1;
- otherwise %toggle
- grid(j,k)=grid(j,k)+2;
- end
- end
- end
- end
- sum(sum(grid))
Add Comment
Please, Sign In to add comment