Skip to content

Instantly share code, notes, and snippets.

View michalwa's full-sized avatar

Michał Wawrzynowicz michalwa

View GitHub Profile
@michalwa
michalwa / nalesniki.pl
Last active March 8, 2022 23:01
PG Alicja i Bogdan
% Alice and Bogdan take turns eating naleśniki from two stacks - M, N.
% There is an initial condition given: that M > 2N.
%
% Given two stacks M and N, such that M >= N, one eats K naleśników from the M stack
% where K mod N = 0 and K >= N.
% The first person to eat the last naleśnik from either stack dies.
%
% Alice takes the first turn. How many naleśniki should she eat on each turn
% in order to win (for Bogdan to die)?
from random import choice
from itertools import chain
def is_tuple(value, shape=None):
""" Checks if the given value is a tuple and optionally checks its shape
specified by the `shape` parameter """
if type(value) == tuple:
if shape is None:
@michalwa
michalwa / nawiasy.c
Last active February 16, 2020 19:49
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
char *gets(char *str);
int main() {
size_t n, i;
if (!scanf("%zd\n", &n)) return 1;
@michalwa
michalwa / RPNDemo.java
Last active August 24, 2018 19:37
RPN Evaluator
package michalwa.rpn;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Stack;
public class RPNDemo
{
@FunctionalInterface
private static interface Operator
@michalwa
michalwa / RPN.java
Last active June 2, 2018 19:11
RPN Variable Problem
import java.util.HashMap;
import java.util.Scanner;
import java.util.Stack;
/** Parsuje i oblicza wartosci wyrazenia ONP.
* (RPN - ang. Reverse Polish Notation) */
public class RPN
{
/** Reprezentuje operator w wyrazeniu ONP */
public static interface Operator