Last active
December 6, 2024 13:10
-
-
Save manthanabc/077fe10e1862318860a0eed5f04a72d4 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
t=document.getElementsByTagName("pre")[0].innerHTML.split('\n') | |
t.pop() | |
let ans =0; | |
t.forEach((e) => { | |
ar=e.split(' ').map((o) => parseInt(o)) | |
ans+= ((ar.reduce((arr, a) => { | |
if(arr[0] == -1) { return arr } | |
if(Math.abs(a-arr[0]) == 0 || Math.abs(a-arr[0]) >=4) { | |
return [-1, 0] | |
} | |
if(a-arr[0] > 0 && arr[1]==1) { | |
return [a, 1] | |
} else if(a-arr[0] < 0 && arr[1] == -1){ | |
return [a, -1] | |
} else { | |
return [-1, 0] | |
} | |
}, [ar[0]-((ar[1]-ar[0])>0?1:-1), (ar[1]-ar[0])>0?1:-1])[0]) != -1)?1:0 | |
}) | |
// Day 2 lazy approch cuz im bowred | |
let ans2=0 | |
t.forEach((e) => { | |
ao=e.split(' ').map((o) => parseInt(o)) | |
let isPossable=0; | |
for(let i=0; i<ao.length; i++) { | |
ar = ao.toSpliced(i, 1) | |
isPossable+= (((ar.reduce((arr, a) => { | |
if(arr[0] == -1) { return arr } | |
if(Math.abs(a-arr[0]) == 0 || Math.abs(a-arr[0]) >=4) { | |
return [-1, 0] | |
} | |
if(a-arr[0] > 0 && arr[1]==1) { | |
return [a, 1] | |
} else if(a-arr[0] < 0 && arr[1] == -1){ | |
return [a, -1] | |
} else { | |
return [-1, 0] | |
} | |
}, [ar[0]-((ar[1]-ar[0])>0?1:-1), (ar[1]-ar[0])>0?1:-1])[0]) != -1)?1:0); | |
} | |
console.log(isPossable) | |
ans2+= (isPossable>0)?1:0; | |
}) | |
console.log(`Part1: ${ans}, Part2: ${ans2}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment