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
| public struct AngleRange { | |
| const float HalfPi = MathF.PI * 0.5f; | |
| public float Min, Max; | |
| public AngleRange(int run, int rise) { | |
| Min = MathF.Atan2(rise - 1, run + 1).Clamp(0, HalfPi); | |
| Max = MathF.Atan2(rise + 1, run - 1).Clamp(0, HalfPi); | |
| } | |
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
| const input = Object.fromEntries(document.querySelector('pre').innerText.trim().split('\n').map(L => [L.substring(0, 3), L.substring(5).split(' ')])) | |
| function traverse( | |
| path = ['you'], | |
| count = {}, | |
| last = path[path.length - 1], | |
| dac = path.indexOf('dac') >= 0, | |
| fft = path.indexOf('fft') >= 0, | |
| key = last + dac + fft | |
| ) { |
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
| input = document.querySelector('pre').innerText.trim().split('\n').map(line => line.substring(1,line.length-1).split(/\] \(|\) \{/g)).map(([a,b,c]) => [a.split('').map(c=>c=='#'), b.split(') (').map(b => b.split(',').map(x=>parseInt(x))), c.split(',').map(x=>parseInt(x))]) | |
| const sumOfValues = o => Object.values(o).reduce((a,b)=>a+b,0) | |
| const matrix = (buttons, joltage) => | |
| joltage.map((r, i) => [...buttons.map(btn => btn.indexOf(i) >= 0 ? 1 : 0), r]) | |
| // Gaussian elimination | |
| // https://en.wikipedia.org/wiki/Gaussian_elimination | |
| function gaussian( | |
| M, | |
| EPS = 1e-8, |
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
| Object.getOwnPropertyNames(Math).map(k => window[k] = Math[k]) | |
| const input = document.querySelector('pre').innerText.trim().split(`\n`).map(l => l.split(',').map(x => parseInt(x))) | |
| const maxArea = (filter = () => true) => | |
| input.reduce((acc, [x1,y1], i) => max(acc, input.slice(i+1).reduce((acc, [x2,y2]) => | |
| max(acc, filter(x1,y1,x2,y2) ? (abs(x2-x1)+1) * (abs(y1-y2)+1) : 0), 0) | |
| ), 0) | |
| const xs = input.reduce((arr, [x,y]) => arr.indexOf(x) >= 0 ? arr : [...arr, x], []).sort((a,b)=>a-b) | |
| const ys = input.reduce((arr, [x,y]) => arr.indexOf(y) >= 0 ? arr : [...arr, y], []).sort((a,b)=>a-b) |
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
| import java.io.File | |
| import java.util.SortedSet | |
| fun main() { | |
| val FIRST_SAMPLES_COUNT = 1000 | |
| val input = File("input.txt").readLines() | |
| .map { it.split(',').map(String::toLong) } | |
| val circuits = input.withIndex().mapTo(ArrayList()) | |
| { (idx, _) -> hashSetOf(idx) } |
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
| package main | |
| import ( | |
| "bytes" | |
| "fmt" | |
| "os" | |
| ) | |
| type Beam struct { | |
| X int |
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
| #include <iostream> | |
| #include <fstream> | |
| #include <sstream> | |
| int main() { | |
| std::ifstream file("input.txt"); | |
| std::string A, B, C, D, O; | |
| std::getline(file, A); | |
| std::getline(file, B); | |
| std::getline(file, C); |
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
| input = document.querySelector('pre').innerText; | |
| [ranges, ids] = input.split('\n\n').map(x => x.split('\n')); | |
| ranges = ranges.map(r => r.split('-').map(x => parseInt(x))); | |
| console.log(ids.filter(id => ranges.some(r => id >= r[0] && id <= r[1])).length) | |
| function mergeRanges() { | |
| const N = ranges.length | |
| for (let i = 0; i < N; ++i) | |
| for (let j = 0; j < N; ++j) { |
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
| string[] lines = File.ReadAllLines("input.txt"); | |
| int W = lines[0].Length, H = lines.Length; | |
| char[][] map = lines | |
| .Select(l => $".{l}.") | |
| .Prepend(new string('.', 2 + W)) | |
| .Append(new string('.', 2 + W)) | |
| .Select(l => l.ToCharArray()) | |
| .ToArray(); | |
| (int dx, int dy)[] NeighbourOffsets = { |
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
| function joltage(line, n) | |
| local index = 1 | |
| local result = 0 | |
| for a = 1, n do | |
| local maxDigit = line:byte(index) | |
| for i = index, #line - (n - a) do | |
| if line:byte(i) > maxDigit then | |
| maxDigit = line:byte(i) | |
| index = i | |
| end |
NewerOlder