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 collections import Counter | |
from math import log | |
def prime_fac(x): | |
"""Returning a map factor -> exponent.""" | |
c = Counter() | |
for i in xrange(2, x + 1): | |
while x % i == 0: | |
c[i] += 1 | |
x //= i |
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
module FunctionEvaluator where | |
import qualified Data.Map.Strict as M | |
evaluateFunction :: Ord a => (a -> Either b ([a], [b] -> b)) -> a -> b | |
evaluateFunction f x = snd $ memoize x M.empty | |
where | |
memoize n m = case M.lookup n m of | |
Just v -> (m, v) | |
Nothing -> |
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
;; LISP TUTORIAL | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; 0. Syntax | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; General form. | |
;; Lisp has two fundamental pieces of syntax: the ATOM and the | |
;; S-expression. Typically, grouped S-expressions are called `forms`. |
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 collections import namedtuple | |
# A reasonable large number to represent infinity. | |
INF = (1 << 31) | |
UNIT_LENGTH = 6 | |
# Struct for edges. | |
Edge = namedtuple('Edge', ['src', 'dest']) | |
def calculate_shortest_distances(node_num, edges, src): |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
var i = 0; | |
var pageNumber = 5; | |
function clearBotFans() { | |
function removeFan(fanHrefElement) { | |
fanHrefElement.click(); | |
const okButtons = document.querySelectorAll('a[action-type="ok"]'); | |
if (okButtons) { | |
okButtons[0].click(); | |
} |
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
func testMaliciousExpressionNFA() { | |
// NFA matching. | |
let re = REAutomata(expr: "(0|00)*1") | |
self.measureBlock { | |
XCTAssertFalse(re.test("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")) | |
} | |
} | |
func testMaliciousExpressionDFA() { | |
// DFA matching. |
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
######### day 1 homework ######### | |
# Bonus problem: If you're feeling the need for a little more, write | |
# a program that picks a random number. Let a player guess the | |
# number, telling the player whether the guess is too low or too high. | |
while (true) | |
random_num = rand(10) | |
input = "" | |
puts "guess a number between 0 and 9" | |
input = gets |
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
class Solution { | |
public: | |
void solve(vector< vector<char> > &board) { | |
height = board.size(); | |
if (height == 0) return; | |
width = board[0].size(); | |
this->board = &board; | |
if (height <= 2 || width <= 2) return; | |
mark = new vector< vector<bool> >(height, vector<bool>(width, false)); | |
// mark 'O' alive |
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
// class UndirectedGraphNode { | |
// int label; | |
// ArrayList<UndirectedGraphNode> neighbors; | |
// UndirectedGraphNode(int x) { | |
// label = x; | |
// neighbors = new ArrayList<UndirectedGraphNode>(); | |
// } | |
// } | |
public class Solution { |
NewerOlder