This file contains hidden or 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
| # The longest palindromic primes of n-digits | |
| # reproducing the first part of an integer | |
| # sequence seen in a mural at Oslo Gardermoen | |
| # airport | |
| from urllib.request import urlopen | |
| def main(): | |
| with urlopen('https://oeis.org/A002385/b002385.txt') as response: |
This file contains hidden or 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
| int NUM_SLIDES = 50; | |
| // Pin 2 has a slide projector connected | |
| int PROJECTOR_ADVANCE_PIN = 2; | |
| int CAMERA_FOCUS_PIN = 3; | |
| int CAMERA_SHUTTER_PIN = 4; | |
| int ARDUINO_LED_PIN = 13; | |
| // the setup routine runs once when you press reset: |
This file contains hidden or 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 functools | |
| def invariant(predicate): | |
| """Create a class decorator which checks a class invariant. | |
| Args: | |
| predicate: A callable to which, after every method invocation, | |
| the object on which the method was called will be passed. | |
| The predicate should evaluate to True if the class invariant |
This file contains hidden or 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
| @classmethod | |
| def bisecting_planes(cls, p, q): | |
| """Determine the bisector of two planes. | |
| Args: | |
| p, q: The two planes to be bisected. | |
| Returns: | |
| The plane bisecting planes p and q. | |
This file contains hidden or 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
| PRINTABLE_ASCII_RANGE = (32, 127) | |
| def multiline_ascii_encodable_text(min_num_lines, max_num_lines): | |
| """A Hypothesis strategy to produce a multiline Unicode string. | |
| Args: | |
| min_num_lines: The minimum number of lines in the produced strings. | |
| max_num_lines: The maximum number of lines in the produced strings. |
This file contains hidden or 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 singledispatch | |
| from collections import Sequence, MutableSequence | |
| @singledispatch | |
| def conj(sequence, item): | |
| raise TypeError("conj() not supported for type '{}'".format(type(sequence))) | |
| @conj.register(MutableSequence) | |
| def _(sequence, item): | |
| sequence.append(item) |
This file contains hidden or 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
| def d(t):s=ord(t)-65;h=lambda i:'-'*(s-i)+chr(i+65)+'-'*i;m=[h(i)+h(i)[-2::-1] for i in range(s+1)];return'\n'.join(m+m[-2::-1]) |
This file contains hidden or 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
| def pop_count_until(stack, predicate): | |
| """Count the number of items which need to be popped off a stack | |
| for the top item to satisfy a predicate. | |
| The stack argument is modified by this call. If the return value is | |
| non-negative the top item on the stack will satisfy the predicate | |
| on return. | |
| Args: | |
| stack: Any object supporting: |
This file contains hidden or 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
| """Transducers in Python | |
| http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming | |
| """ | |
| from abc import abstractmethod, ABCMeta | |
| from collections import deque | |
| from functools import reduce | |
This file contains hidden or 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
| """Transducers in Python | |
| http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming | |
| """ | |
| from functools import reduce | |
| def compose(*fs): | |
| """Compose functions right to left. |