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
% 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)? |
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
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: |
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 <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; |
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
package michalwa.rpn; | |
import java.util.HashMap; | |
import java.util.Scanner; | |
import java.util.Stack; | |
public class RPNDemo | |
{ | |
@FunctionalInterface | |
private static interface Operator |
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
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 |