Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. BEGIN{
  2. FS="[-:# ]+";
  3. }
  4. {
  5. if($6=="Guard"){
  6. if($4 > 0){
  7. if(($2==9||$2==4||$2==6||$2==11)&&$3==30){$2++;$3=1;}
  8. else if($2==2&&$3==28){$2++;$3=1;}
  9. else if($3==31){$2++;$3=1;}
  10. else{$3++;}
  11. }
  12. watch[$2+0 "-" $3+0]["guard"]=$7;
  13. next;
  14. }
  15. watch[$2+0 "-" $3+0][$5+0]=($6=="falls")?1:-1;
  16. }
  17. END{
  18. sleep=-1;
  19. for(d in watch){
  20. if(!watch[d]["guard"]) print "missing guard on " d;
  21. for(i=0;i<60;i++){
  22. (watch[d][i]!=0)?
  23. (sleep=watch[d][i]):
  24. (watch[d][i]=sleep);
  25. sins[watch[d]["guard"]]+=(sleep==1);
  26. }
  27. }
  28. sleeper=0;
  29. for(g in sins)
  30. if(sins[g] > sins[sleeper]) sleeper=g;
  31.  
  32. for(d in watch){
  33. if(watch[d]["guard"]!=sleeper) continue;
  34. for(i=0;i<60;i++)
  35. sleeps[i]+=(watch[d][i]==1);
  36. }
  37. smin=0;
  38. for(s in sleeps)
  39. if(sleeps[s] > sleeps[smin]) smin=s;
  40. print (sleeper*smin);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement