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 os | |
| import glob | |
| import time | |
| import subprocess | |
| import tempfile | |
| import numpy as np | |
| import cv2 | |
| from scipy.optimize import linear_sum_assignment | |
| # === CONFIG === |
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
| f_lines = File.read("input.txt").lines.map(&:chomp) | |
| result_lines = f_lines.map do |line| | |
| # Extract all angle brackets, and sort them. | |
| # We use this as a "stack" of angle brackets that we can pull from | |
| # when we need an angle bracket in the final result | |
| angle_brackets = line.scan(/[<>]/).sort | |
| line_chars = line.chars.map do |c| | |
| c == " " ? " " : angle_brackets.shift | |
| end |
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
| # Brute force | |
| # Times out | |
| # O(n^2) time, O(1) space | |
| def max_area(heights) | |
| max = 0 | |
| current_left_index = nil | |
| current_right_index = nil | |
| heights.each_with_index do |num1, index1| | |
| next if num1 == 0 |
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
| # @param {Integer[][]} image | |
| # @param {Integer} sr | |
| # @param {Integer} sc | |
| # @param {Integer} new_color | |
| # @return {Integer[][]} | |
| def flood_fill(image, sr, sc, new_color) | |
| x_max = image.length - 1 | |
| y_max = image[0].length - 1 | |
| stack = [[sr, sc]] |
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
| require "json" | |
| require "byebug" | |
| mapping = {} | |
| list = File.read("9_input.txt").lines.map(&:chomp) | |
| list.each do |l| | |
| a, _, b, _, number = l.split(" ") | |
| mapping[[a, b]] = number.to_i |
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 = File.read("7_input.txt").gsub("OR", "|").gsub("AND", "&").gsub("LSHIFT", "<<").gsub("RSHIFT", ">>").gsub("NOT", "~").lines.map(&:chomp) | |
| @map = {} | |
| input.each do |expression| | |
| left_side, right_side = expression.split("->") | |
| @map[right_side.strip] = left_side | |
| end | |
| @memo = {} | |
| def evaluate(label) |
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
| # Strategy: | |
| # 1. Find location of each number | |
| # 2. For each combination of 2 numbers, find the distance between them in the graph. Use BFS because I'm lazy | |
| # 3. Brute force the shortest path that goes through each of the 7 numbers. | |
| # - For each permutation of 7 numbers that begins with 0, sum up the distances for each hop. | |
| # - E.g. [0, 2, 5, ...] == distance(0, 2) + distance(2, 5) + ... | |
| # - Find min distance among all permutations | |
| require "byebug" | |
| input = File.read("input.txt").lines.map(&:strip).map(&:chars) |
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
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEditor; | |
| using UnityEngine; | |
| public static class TakeScreenshot | |
| { | |
| // See http://docs.unity3d.com/ScriptReference/MenuItem.html for docs on [MenuItem] hotkeys | |
| [MenuItem("Helpers/Screenshot _g")] | |
| public static void Screenshot() |
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 static class RenderQueueSorter | |
| { | |
| private static int nextRenderQueue = 5; // Don't go over 2500! Or we leak into transparent queues | |
| private static Dictionary<Mesh, Material> _meshToMatMap = new Dictionary<Mesh, Material>(); | |
| public static Material SortedMaterialFromMesh(Mesh mesh, Material sharedMaterial) | |
| { | |
| if (_meshToMatMap.ContainsKey(mesh)) return _meshToMatMap[mesh]; | |
| return GenerateMaterialForMesh(mesh, sharedMaterial); |
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
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class ExceptionManager : MonoBehaviour | |
| { | |
| private const int ExceptionsPerCooldown = 5; | |
| private const float CooldownTime = 5f; | |
| private int _exceptionsLeftBeforeTimeout = ExceptionsPerCooldown; |
NewerOlder