Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| """An executor that runs tasks on the main thread. | |
| This can come in handy for debugging. For example, enables you to inspect and | |
| set breakpoints on the underlying task, which is not easily done when using | |
| separate threads. | |
| Usually one would use this executor when the user provided `--n-jobs=0`. | |
| """ | |
| import logging |
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
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import sys | |
| import random | |
| import logging | |
| from pathlib import Path | |
| from datetime import datetime | |
| from argparse import ArgumentParser |
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
| """Utils for caching results. | |
| """ | |
| import json | |
| import pickle | |
| import logging | |
| from pathlib import Path | |
| from hashlib import sha256 | |
| import cloudpickle |
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
| """ | |
| Given a number of steps _n_, and a list of possible _jumps_, | |
| what's the number of different ways to climb the staircase ? | |
| """ | |
| def num_ways(n, jumps): | |
| if n <= 1: | |
| return 1 | |
| return sum([num_ways(n-j, jumps) for j in jumps if n-j >= 0]) |
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
| #!/bin/python3 | |
| """ | |
| Given two strings, s1 and s2, calculate the minimum number of deletions needed to make s1 == s2 | |
| For example: for the strings (AABAAB, ABAB) you need to delete two 'A's from the left string. | |
| This is a variation of the longest subsequence problem. | |
| """ | |
| import os | |
| import sys |
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
| local obj = {} | |
| obj.__index = obj | |
| obj.menuBarItem = nil | |
| function obj:start() | |
| self.menuBarItem = hs.menubar.new() | |
| self.menuBarItem:setClickCallback(self.clicked) | |
| self.setDisplay(hs.caffeinate.get("displayIdle")) |
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
| local obj = {} | |
| obj.__index = obj | |
| obj.menuBarItem = nil | |
| function obj:start() | |
| self.menuBarItem = hs.menubar.new() | |
| self.menuBarItem:setClickCallback(self.clicked) | |
| self.setDisplay(hs.caffeinate.get("displayIdle")) |
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
| %% Code from http://www.emse.fr/~picard/cours/ai/minimax/#sec-3 | |
| % minimax(Pos, BestNextPos, Val) | |
| % Pos is a position, Val is its minimax value. | |
| % Best move from Pos leads to position BestNextPos. | |
| minimax(Pos, BestNextPos, Val) :- % Pos has successors | |
| bagof(NextPos, move(Pos, NextPos), NextPosList), | |
| best(NextPosList, BestNextPos, Val), !. | |
| minimax(Pos, _, Val) :- % Pos has no successors |
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
| # Solving Magic Squares using Google's ortools | |
| # https://github.com/google/or-tools | |
| from ortools.constraint_solver import pywrapcp | |
| import sys | |
| def main(n=4): | |
| # Create the solver. | |
| solver = pywrapcp.Solver('Magic square') | |
| # declare variables |
NewerOlder