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 functools import lru_cache | |
coins= 10,20,50,100,200,500,1000,2000,5000,10000 | |
@lru_cache(None) | |
def count(amount, idx=len(coins)-1): | |
if amount < 0 or idx < 0: return 0 | |
if amount == 0: return 1 | |
return count(amount - coins[idx], idx) + count(amount, idx-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
# http://ilker.de/code-kata-pickakin | |
def dsq(product_code): | |
return product_code[0] | |
def partition(common_dsq, orig_list): | |
new_list = set() | |
akin_list = set() | |
for x in orig_list: | |
if dsq(x) in common_dsq: |
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 Tkinter import * | |
from math import hypot | |
class CircleDrawing: | |
def __init__(self, canvas): | |
self.canvas = canvas | |
def click(self, e, color): | |
self.color = color | |
self.center = e.x, e.y | |
self.obj_id = self.canvas.create_oval(e.x, e.y, e.x, e.y, outline=color) |
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
(define H 500) | |
(define r (/ H 2)) | |
(define (ypos x) | |
(if (<= x 1) | |
(/ (sqrt (- 1 (sqr (- (* 2 x) 1)))) 2) | |
(/ (sqrt (- 1 (sqr (- (* 2 x) 3)))) -2))) | |
(define (ypos-as-posn x) | |
(make-posn (* x r) | |
(* (+ 1 (ypos x)) r))) |
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
(define H 300) | |
(define r (/ H 2)) | |
(define (ypos x) | |
(if (<= x 1) | |
(/ (sqrt (- 1 (sqr (- (* 2 x) 1)))) 2) | |
(/ (sqrt (- 1 (sqr (- (* 2 x) 3)))) -2))) | |
(define (ypos-as-posn x) | |
(make-posn (* x r) | |
(* (+ 1 (ypos x)) r))) |
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 Tkinter import * | |
from math import hypot | |
class CircleDrawing: | |
def __init__(self, canvas): | |
self.canvas = canvas | |
def click(self, e, color): | |
self.color = color | |
self.center = e.x, e.y | |
self.obj_id = self.canvas.create_oval(e.x, e.y, e.x, e.y, outline=color) |
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 <assert.h> | |
int frame_score(int *rolls) | |
{ | |
int total = 0; | |
for (int frames = 10; frames--; rolls += 1 + (*rolls < 10)) { | |
int score = rolls[0] + rolls[1]; | |
if (score >= 10) | |
score += rolls[2]; |
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 Tkinter import * | |
class LineFactory: | |
def __init__(self): | |
self.line = None | |
def text(self, p): | |
canvas.create_text(p.x, p.y-10, | |
text='{0.x}, {0.y}'.format(p)) | |
def arrow(self, e): | |
return canvas.create_line(self.start.x, self.start.y, |
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 win32api | |
import win32con | |
from time import sleep | |
import Image | |
import pywinauto | |
app = pywinauto.Application.start('mspaint') | |
win = app.top_window_() | |
win.MoveWindow(0,0) |
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 random | |
def simul1(): | |
rooms = [0, 0, 1] | |
random.shuffle(rooms) | |
i = random.randrange(3) # initial | |
while True: | |
j = random.randrange(3) # goat | |
if j != i and rooms[j] == 0: |