-
-
Save caub/fb912ea665c4da74dfa67bf43b38e923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var formatDate = d=>`${d.getFullYear()}-${`${d.getMonth()+1}`.padStart(2,0)}-${`${d.getDate()}`.padStart(2,0)}` | |
var es=document.body.textContent.trim().split('\n').map(l => {let [,d,s]=l.split(/\[|\] /g); return {d: new Date(d), s}}).sort((a,b)=>a.d-b.d) | |
var xs=es.map(({d,s}) => { let m=d.getMinutes(); if (d.getHours()===23){d.setDate(d.getDate()+1);m=0;} return {date: formatDate(d), m,d,s}} ) | |
var days=xs.reduce((o,{date,m,s})=>{const slots=o[date]&&o[date].slots||Array.from({length:60},()=>0); let g=s.match(/#\d+/); if (s.startsWith('falls')){for(let i=m;i<slots.length;i++)slots[i]=1} if (s.startsWith('wakes')){for(let i=m;i<slots.length;i++)slots[i]=0} return {...o,[date]:{...o[date],slots,...g&&{guard:g[0]}}} }, {}) | |
var guards=Object.values(days).reduce((o, {slots,guard}) => {let name=guard.slice(1); const sleeptime=o[name]||0; return {...o,[name]:sleeptime+slots.reduce((a,b)=>a+b)};}, {}) | |
var ds = Object.entries(days).filter(([date, o]) => o.guard==='#2593').map(([date, {slots}]) => slots) | |
Math.max(...ds.reduce((acc, slots) => acc.map((x,i)=>x+slots[i]), Array.from({length:60},()=>0))) | |
ds.reduce((acc, slots) => acc.map((x,i)=>x+slots[i]), Array.from({length:60},()=>0)).indexOf(14) | |
2593*40 | |
var gs=Object.values(days).reduce((o, {slots,guard}) => {let name=guard.slice(1); const sl=o[name]||Array.from({length:60},()=>0); return {...o,[name]:sl.map((x,i)=>x+slots[i])};}, {}) | |
Object.entries(gs).map(([id, vs]) => [id, Math.max(...vs)]) | |
Object.entries(gs).map(([id, vs]) => [id, vs.indexOf(Math.max(...vs))]) | |
3361*33 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment