Puzzle must have tiles and a final state.
Example:
SMALL_GAME_FINAL = (
'RB',
'BR'
)
import asyncio | |
import cv2 | |
from aiohttp import web, MultipartWriter | |
async def mjpeg_handler(request): | |
boundary = "boundarydonotcross" | |
response = web.StreamResponse(status=200, reason='OK', headers={ | |
'Content-Type': 'multipart/x-mixed-replace; ' | |
'boundary=--%s' % boundary, |
import java.lang.IndexOutOfBoundsException | |
abstract class Node { | |
var length: Int = 0 | |
abstract fun charAt(index: Int): Char | |
abstract fun subString(start: Int, end: Int): String | |
abstract fun delete(index: Int) | |
} |
from abc import ABC, abstractmethod | |
class Node(ABC): | |
length: int = 0 | |
@abstractmethod | |
def char_at(self, index: int) -> str: | |
raise IndexError() | |
@abstractmethod |
const wait = async (time) => new Promise((resolve) => setTimeout(resolve, time)); | |
const pickAll = async () => { | |
const btns = document.querySelectorAll('button[data-test="pab-item-btn-pick"]'); | |
for (const btn of btns) { | |
btn.click(); | |
await wait(100); | |
} | |
} |
interface Queue<T> { | |
append(item: T); | |
appendLeft(item: T); | |
count(): number; | |
peak(): T; | |
peakLeft(): T; | |
pop(): T; | |
popLeft(): T; | |
clear(); | |
[Symbol.iterator](); |
type InputWithIndex<I> = [I, number]; | |
async function parallelMap<I, O>(inputs: I[], asyncMapper: (...input: I[]) => O, concurrencyLimit: number = 5): Promise<O[]> { | |
concurrencyLimit = Math.max(1, concurrencyLimit); | |
const inputStack: InputWithIndex<I>[] = inputs.map((input: I, index: number): InputWithIndex<I> => [input, index]).reverse(); | |
const results = new Array(inputs.length).fill(undefined); | |
const workers = new Array(concurrencyLimit).fill(undefined); | |
async function work() { | |
if (inputStack.length) { |
def range_sum(tree, left_child, right_child): | |
return tree[left_child] + tree[right_child] | |
def build_segment_tree(arr, tree=None, | |
merge_fn=range_sum, | |
node_index=0, lo=0, hi=None, initial=None): | |
""" | |
Build a segment tree based on arr of leaf node | |
tree will have the size of 4 * len(arr) | |
node_index is tree index |
from typing import * | |
from abc import ABCMeta, abstractmethod | |
from collections import deque | |
class PuzzleSolver(metaclass=ABCMeta): | |
"""Abstract class for solve puzzle that have initial state and end state | |
Simple breath first search | |
from any state -> generate next reachable state and eliminated duplicate state | |
until reach goal or max depth reached |