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 AllOne | |
| def initialize() | |
| @sorted = [] | |
| @positions = {} | |
| @leftmost = {} | |
| @count = {} | |
| end | |
| def inc(key) | |
| if (pos = @positions[key]) |
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
| # http://www.mountainvistasoft.com/chaocipher/ActualChaocipher/Chaocipher-Revealed-Algorithm.pdf | |
| # suggested improvements (IV) | |
| # https://pthree.org/2015/07/09/the-chaocipher-with-playing-cards/ | |
| # reasonable allegation that one alphabet is irrelevant, so strength is only 26! | |
| # https://prgomez.com/scrabble-cipher/ | |
| def permute_left(left, idx) | |
| rotated = left.chars.rotate(idx) | |
| rotated[1..13] = rotated[2..13] << rotated[1] | |
| rotated.join |
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 ops(nums, result, sign = 1) | |
| case nums.size | |
| when 0, 1 | |
| result == (nums[0] || 0) * sign ? [[nums[0]].compact] : [] | |
| else | |
| n1, n2 = nums.first(2) | |
| plus = ops(nums.drop(1), result - n1 * sign, 1).map { |r| [n1, :+] + r } | |
| minus = ops(nums.drop(1), result - n1 * sign, -1).map { |r| [n1, :-] + r } | |
| concat = ops([n1 * 10 + n2] + nums.drop(2), result, sign) | |
| plus + minus + concat |
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
| require 'json' | |
| require 'time' | |
| # Create a personal access token at https://github.com/settings/tokens | |
| # It needs NO scopes. | |
| # In fact, you could just not use a token, but then you get rate-limited to 60 an hour instead of 5000 an hour. | |
| TOKEN_FILE = 'secrets/token.txt'.freeze | |
| SLEEP_TIME = 2 | |
| CACHE = 'cache'.freeze |
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 ParseError < StandardError; end | |
| def object(s, i) | |
| o = {} | |
| state = :key | |
| key = nil | |
| j = i + 1 | |
| while (c = s[j]) | |
| case state |
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 ruby | |
| if ARGV.empty? | |
| puts "usage: #{$PROGRAM_NAME} dir" | |
| Kernel.exit(1) | |
| end | |
| track = File.basename(File.dirname(File.realpath(ARGV[0]))) | |
| def glob(*components, except: []) |
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
| require 'json' | |
| require 'set' | |
| # Create a personal access token at https://github.com/settings/tokens | |
| # It needs only one scope: read:org ("Read org and team membership"). | |
| TOKEN_FILE = 'secrets/token.txt'.freeze | |
| SLEEP_TIME = 2 | |
| global_name = 'track-maintainers'.freeze |
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
| if ARGV.empty? | |
| puts "usage: #{$PROGRAM_NAME} offset [file] (or stdin)" | |
| exit 1 | |
| end | |
| offset = ARGV.shift.to_i | |
| ARGF.each_line { |l| | |
| unless l.include?('-->') | |
| puts l |
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
| require 'set' | |
| def heuristic(start, goal) | |
| { | |
| start: 5, # Not given in the diagram but probably not important. | |
| a: 4, | |
| b: 2, | |
| c: 4, | |
| d: 4.5, | |
| e: 2, |
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
| # http://norvig.com/ipython/xkcd1313.ipynb | |
| # http://nbviewer.jupyter.org/url/norvig.com/ipython/xkcd1313.ipynb | |
| # | |
| # http://norvig.com/ipython/xkcd1313-part2.ipynb | |
| # http://nbviewer.jupyter.org/url/norvig.com/ipython/xkcd1313-part2.ipynb | |
| # | |
| # Only implemented the 'covers' optimisation in part 2 | |
| # no branch and bound. | |
| # no repetition characters or pairs |