Skip to content

Instantly share code, notes, and snippets.

@basp1
basp1 / D_Graph.cs
Created September 18, 2017 10:31
Яндекс.Блиц. D
// https://contest.yandex.ru/hiring/contest/5048/problems/D/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace yandex.blitz
{
@basp1
basp1 / C_Tournament.cs
Last active September 18, 2017 10:48
Яндекс.Блиц. C
// https://contest.yandex.ru/hiring/contest/5048/problems/C/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace yandex.blitz
{
@basp1
basp1 / A_Game.cs
Created September 18, 2017 10:29
Яндекс.Блиц. A
// https://contest.yandex.ru/hiring/contest/5048/problems/A/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace yandex.blitz
{
@basp1
basp1 / Intlist.cs
Last active August 15, 2017 06:03
Intlist class
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Matlib
{
public class Intlist
{
readonly static int NIL = -1;
readonly static int EMPTY = -2;
@basp1
basp1 / SparseMatrix.cs
Last active August 15, 2017 06:03
Simple sparse matrix class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
namespace Matlib
{
public class SparseMatrix<T>
{
public enum SparseMatrixType
@basp1
basp1 / ensure.h
Created February 28, 2017 09:12
ensure macro
#pragma once
#include <exception>
#define DEBUG_STRINGIFY(x) #x
#define DEBUG_TO_STRING(x) DEBUG_STRINGIFY(x)
#define DEBUG_LOCATION "file: " __FILE__ ". line: " DEBUG_TO_STRING(__LINE__)
#define THROW_EXCEPTION(MESSAGE) throw std::exception(MESSAGE)
@basp1
basp1 / FindAllPaths.cs
Last active November 3, 2020 01:41
Find all paths between 2 graph nodes (iterative depth first search)
using System;
using System.Collections.Generic;
namespace CircuitSelector
{
public static class Graph
{
// use LinkedHashSet from http://stackoverflow.com/a/31419199/1312837 with some additions
public static List<List<int>> FindAllPaths(AdjacentMatrix adj, int begin, int end)
{
import java.nio.ByteBuffer
object LEB128 {
def write(buffer: ByteBuffer, offset: Int, longValue: Long): Int = {
var writtenBytes: Int = 0
var value = longValue
if (value.abs <= 63) {
if (value < 0) {
value = value.abs
(defun last-set-bit (value)
(if (zerop value)
-1
(let ((shifted-value (ash value -32)))
(if (not (zerop shifted-value))
(+ 32 (last-set-bit shifted-value))
(flet ((stepf (x b)
(if (>= value (ash 1 x))
(progn
(setf value (ash value (- x)))
@basp1
basp1 / cas-stack.lisp
Last active November 20, 2022 16:15
lock-free stack in common lisp
(defpackage :cas-stack
(:use :common-lisp)
(:export
:make-stack
:stack-push
:stack-pop))
(in-package :cas-stack)
;; https://github.com/zerth/cl-cas-queue/blob/master/cas-queue.lisp