This file contains 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
neigh = { | |
'R': (0, 1, 'L'), 'L': (0, -1, 'R'), 'D': (1, 0, 'U'), 'U': (-1, 0, 'D') | |
} | |
# Type of a cell | |
# -1: out of bounds. Otherwise the value of the cell | |
def cell_type(grid: list[list[int]], i: int, j: int) -> int: | |
if 0 <= i < len(grid) and 0 <= j < len(grid[0]): | |
return grid[i][j] |
This file contains 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
""" | |
Given a string s, count the number of triplets i <= j < k such that | |
the substrings s[i:j] and s[j+1:k] have the same set of unique characters. | |
Algorithm: | |
Scan the array, remembering the last time each character appeared | |
Use this information to count the number of times each set of characters | |
appear in substrings ending at each position (max 26 such sets) | |
Repeat for reversed string to count for substrings starting at each position | |
For each j, scan through the sets for substrings ending at j and starting at j+1 | |
If the sets are the same, the product of their counts is the number of |
This file contains 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
// Dynamic connectivity on a graph | |
// Solution method: Offline processing + segment tree + undo on union-find | |
// Details: | |
// First, scan through the input to find ranges in which an edge is active | |
// Then insert these ranges into the nodes of a segment tree | |
// If we merge all the edges in the nodes on a path from root to a leaf, | |
// we get the number of connected components at that point | |
// We find the component count for all leaves efficiently by adding undo | |
// operations to the union-find data structure |
This file contains 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
# Find the expected number of steps to solve snakes and ladders | |
# Author: Raziman T V (github.com/razimantv) | |
import numpy as np | |
N = 100 | |
snakes_ladders = { | |
2: 23, 6: 45, 20: 59, 43: 17, 50: 5, 52: 72, 56: 8, 57: 96, 71: 92, | |
73: 15, 84: 63, 87: 49, 98: 40 | |
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ |
This file contains 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
/** | |
* Two-Player Split Game Solver | |
* | |
* This C++ program solves a two-player game played with two hands | |
* | |
* - Two players take turns, starting with two fingers out on each hand | |
* - Each turn, a player can add the number of fingers on one of their hands to | |
* that of their opponent (addition wraps around after 5) | |
* - If the numbers on a hand become 5, it resets to 0 | |
* - If one hand is empty and the other has an even number, it can be split |
This file contains 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 <chrono> | |
#include <iostream> | |
#include <numeric> | |
#include <ranges> | |
#include <vector> | |
const int N = 10000000; | |
int main() { | |
auto t1 = std::chrono::steady_clock::now(); |
This file contains 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
/****************************************************************************** | |
* File: towers.cpp | |
* | |
* Author: Raziman T V | |
* Created: 04/09/20 | |
* Description: Solving the Towers puzzle | |
*****************************************************************************/ | |
#include <algorithm> | |
#include <cassert> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder