diff --git a/.gitignore b/.gitignore index 0f78477..073a941 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build frames .DS_Store .vscode -.replit \ No newline at end of file +.replit +main.sh \ No newline at end of file diff --git a/2020/10/part1.js b/2020/10/part1.js index 7936ab5..e98dc1b 100644 --- a/2020/10/part1.js +++ b/2020/10/part1.js @@ -1,5 +1,5 @@ const fs = require('fs'); -const data = fs.readFileSync('input.txt', 'utf-8'); +const data = fs.readFileSync('./input.txt', 'utf-8'); const lines = data.split('\n').map(num => parseInt(num)).sort((a,b)=>(a-b)); lines.unshift(0); // add the outlet with joltage 0 lines.push(lines[lines.length-1]+3); // your device has a joltage 3 above the highest diff --git a/2020/12/input.txt b/2020/12/input.txt new file mode 100644 index 0000000..18b698e --- /dev/null +++ b/2020/12/input.txt @@ -0,0 +1,788 @@ +N1 +R90 +S5 +R180 +N3 +W1 +L180 +F92 +R270 +E4 +F4 +W4 +W4 +L180 +S2 +W2 +F90 +E1 +S5 +W3 +F78 +S5 +R180 +F100 +N1 +W3 +L90 +L90 +N1 +F94 +W2 +R90 +F49 +W2 +F26 +R180 +W1 +S5 +R180 +W4 +S3 +R90 +W3 +S4 +E5 +S1 +F13 +N5 +R270 +E2 +R270 +S5 +F3 +E3 +F4 +S3 +R270 +S1 +W4 +R90 +S4 +L180 +N4 +F81 +W2 +R90 +F61 +R90 +F13 +N3 +R180 +W1 +F98 +S5 +F50 +W5 +S3 +W5 +R90 +F17 +S5 +F70 +F7 +E2 +F87 +E1 +L270 +F59 +E2 +R180 +N5 +F59 +L90 +N5 +W5 +F10 +N3 +E1 +R90 +W1 +S2 +R90 +N5 +F25 +R90 +E2 +F57 +R180 +E1 +N3 +W2 +F85 +L90 +F50 +W2 +R90 +S3 +R90 +F27 +E1 +S1 +L90 +F32 +L90 +W3 +R90 +E1 +F39 +S5 +E4 +F50 +W4 +L90 +F63 +N2 +F67 +W3 +R90 +F4 +N2 +R90 +F90 +N5 +L180 +F24 +E5 +N3 +L180 +F67 +E3 +L90 +S3 +F49 +R90 +E5 +F89 +W5 +F62 +F39 +F33 +W1 +R90 +F18 +S3 +R90 +N4 +F47 +N5 +N3 +W2 +S5 +L90 +E4 +L90 +W2 +R90 +W5 +L90 +W5 +N4 +F64 +R90 +S2 +W4 +R90 +N3 +F18 +L90 +S4 +L90 +F31 +S4 +L90 +F79 +R90 +F69 +N3 +E4 +F64 +N2 +E4 +R90 +F20 +R180 +E1 +F85 +W1 +S5 +S2 +F21 +R90 +F43 +N1 +F18 +S5 +R180 +F52 +L180 +W4 +F5 +L90 +F70 +S4 +N3 +R180 +F64 +R90 +F17 +R90 +E5 +F85 +N1 +F74 +E5 +F21 +N1 +F35 +N1 +F65 +W2 +F67 +N1 +E5 +F79 +S4 +R90 +F20 +R180 +W5 +L180 +S4 +F56 +S4 +L90 +E5 +F13 +S5 +F38 +W1 +S2 +L90 +N4 +E3 +R180 +W3 +N1 +R90 +F52 +N5 +F23 +E5 +F82 +E5 +S2 +E3 +N3 +S2 +L90 +N1 +R90 +S5 +F60 +W1 +N2 +W1 +N3 +E4 +F2 +E2 +L90 +S1 +L90 +E4 +N1 +R180 +E2 +R180 +F93 +F94 +L90 +S4 +E5 +R90 +F5 +S2 +E2 +S3 +E4 +R180 +F56 +E2 +N2 +F3 +R90 +W2 +F94 +W5 +F47 +L180 +F68 +E5 +F63 +S3 +E4 +F93 +L90 +S5 +L180 +W5 +S5 +W3 +L180 +F34 +R90 +F87 +W4 +S1 +W3 +R270 +S1 +E1 +F78 +E4 +R90 +F91 +W4 +S3 +W1 +F41 +N4 +E1 +F66 +S1 +W5 +F62 +N2 +W2 +L90 +W1 +F23 +L270 +N2 +W2 +S3 +F9 +R90 +F2 +E4 +F61 +L90 +W5 +N4 +F97 +L90 +F93 +N5 +L270 +R90 +W1 +R90 +R90 +N4 +E1 +F72 +N4 +R270 +F24 +W1 +F79 +S1 +E3 +N4 +E3 +L90 +W2 +S1 +R270 +W5 +F24 +E5 +S4 +F22 +L180 +F57 +S5 +R90 +N4 +W3 +F18 +N2 +R90 +E3 +F55 +N2 +R90 +S5 +F4 +W3 +L90 +N2 +W3 +L270 +E4 +R90 +F46 +S5 +N1 +F16 +N1 +R90 +F8 +L180 +N2 +W3 +N4 +E1 +S3 +L90 +F4 +E5 +N5 +E3 +R90 +F35 +N2 +F68 +F33 +E5 +F38 +E4 +F27 +R180 +S5 +F47 +R90 +F43 +R90 +S1 +F84 +L180 +F47 +R90 +N4 +E4 +F77 +R180 +N1 +E2 +S4 +F45 +S1 +L90 +E5 +F40 +L90 +W5 +F25 +W4 +R90 +F80 +N5 +E2 +F74 +W3 +N3 +E4 +F48 +N3 +R90 +N2 +W1 +L90 +S2 +F35 +L90 +E5 +R180 +W5 +N2 +E1 +L90 +N2 +F78 +S5 +R270 +S5 +R90 +N5 +E3 +L90 +S5 +F13 +S5 +F52 +L90 +N2 +R180 +E1 +F41 +S1 +F20 +N4 +F34 +N2 +F45 +E5 +L90 +W3 +L270 +N5 +F52 +R90 +N5 +E5 +N2 +W2 +W5 +R270 +W5 +F10 +N3 +F63 +N4 +F53 +L90 +E5 +L270 +F17 +N1 +L90 +F26 +F93 +R90 +S5 +R270 +S5 +R180 +N4 +F58 +L180 +F40 +S2 +F54 +N5 +F70 +W1 +N4 +W1 +L90 +W5 +R90 +N2 +R90 +S5 +F95 +W4 +L180 +E3 +F68 +S1 +F56 +R90 +W1 +L180 +F66 +R90 +S2 +F57 +L90 +E1 +F42 +S4 +F44 +L90 +F42 +E4 +R90 +S4 +W5 +R90 +E4 +S4 +E5 +F27 +R90 +N1 +R90 +E5 +R90 +W4 +S1 +F81 +N5 +R180 +S4 +E4 +F68 +S3 +L90 +E4 +E4 +L180 +E3 +F8 +W2 +L90 +S4 +L180 +N2 +L180 +E1 +R90 +W5 +N4 +W4 +R90 +F1 +S5 +E2 +L90 +F49 +N4 +W3 +R90 +E5 +F33 +R180 +S4 +E5 +S2 +F79 +W4 +F38 +R90 +F1 +L90 +F56 +L270 +N2 +L90 +E2 +L90 +F25 +W1 +S4 +L270 +W3 +R90 +N2 +F68 +E1 +R180 +W3 +R90 +W3 +R90 +S3 +F4 +W3 +N3 +R90 +W3 +N1 +F54 +W2 +S5 +E4 +F76 +F47 +N1 +F32 +L180 +L90 +F19 +N2 +E5 +L90 +E1 +L90 +E3 +R90 +F48 +R270 +S3 +R180 +S4 +F53 +R90 +F90 +E4 +F100 +L90 +F49 +N1 +W1 +F56 +E2 +N5 +L90 +F39 +R90 +W2 +F26 +E4 +N4 +L90 +F9 +L90 +F41 +W5 +N4 +S1 +W4 +N3 +R90 +N5 +L270 +F82 +L90 +F75 +S5 +F25 +S4 +F67 +N4 +F57 +E4 +N4 +F73 +W5 +L90 +E2 +R180 +N5 +L270 +W3 +F95 +W2 +S4 +E1 +R180 +N3 +W2 +N1 +F28 +N2 +R90 +E3 +S1 +F41 +E4 +N1 +R90 +F12 +L90 +N2 +S2 +E3 +F31 +W1 +L90 +E5 +S1 +F12 +R180 +W5 +R90 +F26 \ No newline at end of file diff --git a/2020/12/part1.js b/2020/12/part1.js new file mode 100644 index 0000000..2330231 --- /dev/null +++ b/2020/12/part1.js @@ -0,0 +1,38 @@ +// cool today's puzzle is basically a turtle +const fs = require('fs'); +const instructions = fs.readFileSync('input.txt', 'utf-8').split('\n'); +// position and direcion start at 0 +let x = y = d = 0; +instructions.forEach((instruction, i) => { + console.log(x,y,d) + action = instruction[0]; + arg = Number(instruction.slice(1)); + switch (action) { + case 'N': + y+=arg; + break; + case 'S': + y-=arg; + break; + case 'E': + x+=arg; + break; + case 'W': + x-=arg; + break; + case 'L': + d-=arg; + break; + case 'R': + d+=arg; + break; + case 'F': + y -= Math.round(arg * Math.sin(d*Math.PI/180)); + x += Math.round(arg * Math.cos(d*Math.PI/180)); + break; + default: + console.log('instruction no', i+1, action,'invald') + } +}) +console.log(x,y,d) +console.log(Math.abs(x)+ Math.abs(y)) \ No newline at end of file diff --git a/2020/12/part2/index.html b/2020/12/part2/index.html new file mode 100644 index 0000000..b185b3e --- /dev/null +++ b/2020/12/part2/index.html @@ -0,0 +1,27 @@ + + + + + + day 12 visualisation + + + + +
+ + + + + + + +
+ + + + \ No newline at end of file diff --git a/2020/12/part2/script.js b/2020/12/part2/script.js new file mode 100644 index 0000000..b0c40b0 --- /dev/null +++ b/2020/12/part2/script.js @@ -0,0 +1,149 @@ +const canvas = document.getElementById('can') +const c = canvas.getContext('2d'); +const out = document.getElementById('output') +let instructions=document.getElementById('input').value.split('\n'); + +let wpx = 10; +let wpy = -1; +let shipX = 0; +let shipY = 0; +let i = 0 + +function reset () { + instructions = document.getElementById('input').value.split('\n'); + wpx = 10; + wpy = -1; + shipX = 0; + shipY = 0; + i = 0 + print('reset') +} +function stop() { + document.getElementById('loop').checked = false + clearInterval(loopInterval); + reset() +} +function iterate(i) { + instruction = instructions[i] + if (!instruction) {print('oops there is no instruction no '+ i); return} + action = instruction[0].toUpperCase(); + arg = Number(instruction.slice(1)); + if (isNaN(arg)){ + print('instruction no '+(i+1)+': "'+instruction.slice(1)+'" is not a number') + stop(); + return + } + switch (action) { + case 'N': + wpy-=arg; + break; + case 'S': + wpy+=arg; + break; + case 'E': + wpx+=arg; + break; + case 'W': + wpx-=arg; + break; + case 'L': + switch (arg) { + case 90: + bx = wpx + by = wpy + wpx = by + wpy = -bx + break; + case 180: + wpx *= -1; + wpy *= -1; + break; + case 270: + bx = wpx + by = wpy + wpx = -by + wpy = bx + break; + case 0: + break; + default: + print('tried to rotate '+ arg+ ' degrees. can only rotate in right angles'); + stop() + return + } + break; + case 'R': + switch (arg) { + case 90: + bx = wpx + by = wpy + wpx = -by + wpy = bx + break; + case 180: + wpx *= -1; + wpy *= -1; + break; + case 270: + bx = wpx + by = wpy + wpx = by + wpy = -bx + break; + case 0: + break; + default: + print('tried to rotate '+ arg+ ' degrees. can only rotate in right angles'); + stop() + return + } + break; + case 'F': + shipX += wpx*arg; + shipY -= wpy*arg; + break; + default: + print('instruction no '+ (i+1) + ': "' + action+'" invald') + stop() + return + } + + print('instruction no '+ (i+1) + ': "'+instruction+'" ship at ('+shipX+', '+shipY+') pointing ('+wpx+', '+-wpy+')') +} + +function clear() { + out.innerHTML = "" +} +document.getElementById('clearbutton').onclick = clear; + +setInterval(()=>{ + scale = Math.pow(100, document.getElementById('scale').value) + c.clearRect(0,0,canvas.width,canvas.height); + c.fillStyle = 'green' + c.fillRect(canvas.width/2+(shipX)/scale-5, canvas.height/2-(shipY)/scale-5, 10,10); + c.fillStyle = 'yellow' + c.fillRect(canvas.width/2+(shipX+wpx)/scale-2, canvas.height/2-(shipY-wpy)/scale-2,4,4); +}, 30) + +let loopInterval = setInterval(loop, 1000) + +function loop () { + if (i'+out.innerHTML +} \ No newline at end of file diff --git a/2020/12/part2/style.css b/2020/12/part2/style.css new file mode 100644 index 0000000..3784fdd --- /dev/null +++ b/2020/12/part2/style.css @@ -0,0 +1,27 @@ +#output { + display: block; + overflow-y: scroll; + height: 100px; +} + +#input { + position: absolute; + top: 8px; + left: 516px; + height: 500px; +} + +input { + direction: rtl; +} + +canvas, #output { + background-color: #10101a; + border: 1px solid #333340; +} + +body { + background-color: #0f0f23; + color: #cccccc; + font-family: "Source Code Pro", monospace; +} \ No newline at end of file diff --git a/README.md b/README.md index 80eefad..0dc85b5 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ if (advent) { 9. [:star: :star:](https://adventofcode.com/2020/day/9 "see puzzle") 10. [:star: :star:](https://adventofcode.com/2020/day/10 "see puzzle") 11. [:star: :star:](https://adventofcode.com/2020/day/11 "see puzzle") +12. [:star: :star:](https://adventofcode.com/2020/day/12 "see puzzle") ## Languages Used * Python @@ -59,4 +60,8 @@ if (advent) { * Node JS - js * Java (Processing) - - pde \ No newline at end of file + - pde +* HTML, CSS, JavaScript + - html + - css + - js \ No newline at end of file