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
use std::collections::{HashMap, HashSet}; | |
const M: u64 = 1_000_000_007; | |
fn main() { | |
const N: usize = 10; | |
let array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; | |
let mut dp: [[HashSet<u64>; N + 1]; N + 1] = Default::default(); | |
let mut path = HashMap::new(); | |
for l in 1..=N { |
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.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Objects; | |
import java.util.Scanner; | |
public class ReptileSolver { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); |
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 collections | |
import random | |
def is_alphabet(s): | |
return all('a' <= ch <= 'z' for ch in s.strip().lower()) | |
class Problem: | |
def __init__(self, answer=None): |
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
#!/usr/bin/env python3 | |
import math | |
import random | |
import sys | |
import time | |
from common import print_tour, read_input | |
TIME_LIMIT_TWO_OPT = 10 * 60 # 10 min. | |
TIME_LIMIT_THREE_OPT = 10 * 60 # 10 min. |
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 kotlin.math.abs | |
import kotlin.system.measureTimeMillis | |
// This code solves a Sudoku puzzle with some additional constraints by Mitchell Lee | |
// https://www.theverge.com/tldr/2020/5/18/21262771/sudoku-puzzle-cracking-the-cryptic-watch-this-video-simon-anthony | |
// | |
// The constraints are as below: | |
// 1. Any two cells separated by a knight's move or a king's move (in chess) cannot contain the same digit. | |
// 2. Any two orthogonally adjacent cells cannot contain consecutive digits | |
// 3. Normal Sudoku rules apply |
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 'priority_queue' | |
def solve(n, max_discs, l, t, m) | |
dp = Array.new(n + 1) { a = Array.new(n + 1, Float::INFINITY); a[0] = 0; a } | |
cut = Array.new(n + 1) { Array.new(n + 1) } | |
cumulate_ts = t.inject([0]) { |result, tvalue| result << result.last + tvalue } | |
(1..max_discs).each do |i| | |
k = 1 | |
pq = PriorityQueue.new | |
(1..n).each do |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
# This function rounds down the given value to 2 decimal places | |
# **Note!** This implementation looks correct but actually is wrong | |
def floor_2(value) | |
return (value.to_f * 100).floor.to_f / 100 | |
end | |
p floor_2(3.1415) # => 3.14 | |
p floor_2(2.71828) # => 2.71 | |
p floor_2(33.62) # => 33.61 !? |
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
class MyQueue | |
def initialize(size) | |
@size = 0 | |
@min_index = 0 | |
@queues = Array.new(size) { Array.new } | |
end | |
def push(cost, index) | |
if cost < 0 || cost >= @queues.size | |
raise "invalid cost: cost=#{cost}, size=#{@queues.size}" |
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 'benchmark' | |
require 'priority_queue' | |
#require 'profile' | |
M = 64 | |
N = 153600 | |
pq = PriorityQueue.new | |
list = Array.new(N) { |i| i }.shuffle | |
time = Benchmark.realtime do | |
(1..M).each { |
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
class LinkedListNode(var next: LinkedListNode?, val value: String) | |
fun detectLoop(list: LinkedListNode): String { | |
var node1 = list | |
var node2 = list | |
var n = 0 | |
do { | |
node1 = node1.next!! | |
node2 = node2.next!!.next!! | |
n++ |
NewerOlder