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
| class Stack(list): | |
| def push(self, item): | |
| """Push item on top of stack""" | |
| self.append(item) | |
| def reverse(self, target=None): | |
| """Destructively reverse self onto another stack | |
| To reverse a stack `s` in place, use `s = s.reverse()` | |
| """ |
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 numpy as np | |
| class AdditiveHeterogenousArray(np.lib.mixins.NDArrayOperatorsMixin): | |
| """A numpy array that supports addition of different types""" | |
| def __init__(self, *args, **kwargs): | |
| self.array = np.array(*args, **kwargs) | |
| def __repr__(self): |
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 incremental_max(l: List[int]) -> List[int]: | |
| if not l: | |
| return [] | |
| maxes = [l[0]] | |
| for i in range(1, len(l)): | |
| maxes.append(max(maxes[i-1], l[i])) | |
| return maxes | |
| class Solution: |
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
| DAYS = ["1st", "2nd", "3rd"] + [f"{i}th" for i in range(4, 12+1)] | |
| GIFTS = ["a partridge in a pear tree.", "two turtle doves,", | |
| "three French hens,", "four calling birds,", | |
| "five gold rings,", "six geese a-laying,", | |
| "seven swans a-swimming,", "eight maids a-milking,", | |
| "nine ladies dancing,", "ten lords a-leaping,", | |
| "eleven pipers piping,", "twelve drummers drumming,"] | |
| STANZA_TEMPLATE = "On the {} day of Christmas,\nmy true love gave to me\n{}\n" |
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
| """Hyperoperations implementation (https://en.wikipedia.org/wiki/Hyperoperation)""" | |
| from functools import reduce | |
| zeration = lambda a, b: b+1 | |
| addition = lambda a, b: reduce(lambda x, _: zeration(0, x), [None]*b, a) | |
| multiplication = lambda a, b: reduce(lambda x, _: addition(a, x), [None]*b, 0) | |
| exponentiation = lambda a, b: reduce(lambda x, _: multiplication(a, x), [None]*b, 1) | |
| tetration = lambda a, b: reduce(lambda x, _: exponentiation(a, x), [None]*b, 1) | |
| pentation = lambda a, b: reduce(lambda x, _: tetration(a, x), [None]*b, 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
| class LinkedList: | |
| def __init__(self, collection): | |
| try: | |
| iterator = iter(collection) | |
| head = next(iterator) | |
| self._value = head | |
| tail = LinkedList(iterator) | |
| self._tail = tail | |
| self._len = tail._len + 1 | |
| except StopIteration: |
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
| function extractRespondentAnswers(respondentElem) { | |
| let answers = Array.from(respondentElem.querySelectorAll('.response-text')); | |
| return answers | |
| .map(elem => | |
| elem.parentElement.parentElement.parentElement.parentElement.parentElement | |
| .querySelector('.response-question-title-text').innerText | |
| + (elem.previousElementSibling ? ">" + elem.previousElementSibling.innerText : "") | |
| + '\t' + elem.innerText | |
| ).join('\n'); |
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
| // Go to the Class Profiles page in your desktop browser (doesn't matter which one you use): | |
| // https://sisweb.ucd.ie/usis/W_HU_REPORTING.P_DISPLAY_QUERY?p_code1=B036Y1&p_query=OB200-1 | |
| // Open the developer tools console, every browser has a slightly different way to open it | |
| // Paste the following into it, and then close it. | |
| // From now on, pressing the Spacebar will toggle the visibiltiy of the names on the page. | |
| // This only applies to that particular session, and will be forgotten when you reopen the page. | |
| $(document).keypress(function(event) { | |
| if (event.keyCode == 32) { // Spacebar |
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
| Afghanistan | |
| Albania | |
| Algeria | |
| Angola | |
| Antarctica | |
| Argentina | |
| Armenia | |
| Australia | |
| Austria | |
| Azerbaijan |
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 lru_cache | |
| @lru_cache(maxsize=1000) | |
| def coincount(coinlist, amount): | |
| if not amount: | |
| return 1 | |
| if not coinlist: | |
| return 0 |