These notes references 睿国丨肥头’s Walkthrough. 这些笔记参考睿国丨肥头的攻略。 🙏
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
VAMPIRES = ARGV.each_with_index.filter_map do|input, idx| | |
number = Integer input | |
length = input.length | |
next if length.odd? | |
fangs = input.chars.permutation(length).filter_map do|digits| | |
digits2 = digits.pop(length/2) | |
next if digits.last == '0' and digits2.last == '0' # This isn’t counted | |
a = Integer digits .join, 10 | |
b = Integer digits2.join, 10 |
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
# ### 问:大五码系列和GB系列的字节长度“兼容”吗? | |
# 大五码系列用一或两个字节编码一个字符,而最新的 GB 18030 用一、二或四个。 | |
# * 大五和GB的单字节范围都是 `00`–`7F`;大于这个范围的字节才表示多节的编码。 | |
# * GB 18030 特有的驷节编码通过 `30`–`39` 范围的第二节辨识;这个范围小于大五*和GB*的双节编码的第二节范围。 | |
# 排除上面后,大五码系列除了错误之外的双字节均对应GB系列的双字节————虽然有些大五范围超出了GB范围。 | |
puts ARGV.map { _1 | |
.encode(Encoding::Big5_HKSCS) # 大五码・香港增补字符集 | |
.force_encoding(Encoding::GB18030) # 信息技术 中文编码字符集(码位最多) | |
}.join(' ').encode(Encoding.default_external) |
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
# frozen_string_literal: true | |
# Goldberg–Tarjan Push–Relabel Algorithm | |
# with FIFO active set and BFS pre-labeling | |
# * https://www.adrian-haarbach.de/idp-graph-algorithms/implementation/maxflow-push-relabel/index_en.html | |
# * https://en.wikipedia.org/wiki/Push%E2%80%93relabel_maximum_flow_algorithm?oldid=1230043247 | |
# variable names are in dummies’ terminologies | |
class PushRelabel | |
class Node |
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
def int2bytestr(int, bytesize = int.size) | |
[ | |
# Format to hex, left-pad with `0` (big-endian) for `bytesize * 2` nibbles | |
sprintf('%0*X', bytesize * 2, int) | |
].pack 'H*' # Pack string of hex chars to string of raw bytes | |
end | |
# Demo | |
print "actual\t" | |
p int2bytestr(0x4_20_69_de_ad_be_ef_13_37, 10) |
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
# Marker module for “my library” | |
module MyError end | |
# Built-in exception class example | |
ZeroDivisionError.include MyError | |
puts begin | |
1 / 0 | |
rescue MyError => e | |
e | |
end #=> divided by 0 |
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
# frozen_string_literal: true | |
class CellularAutomaton | |
def initialize(grid) | |
@grid = grid | |
# Back Buffer | |
@grid2 = grid.map(&:dup) | |
@rules = yield self | |
end | |
def self.load(file, ...) = new(file.each_line(chomp: true).map(&:chars), ...) |
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
def answer1(n) = n.succ | |
def answer2(str) = str.upcase | |
def answer3(n) = (0..n).to_a | |
def answer4 = yield + 42 | |
def answer5(a, b = 1) = a + b | |
def answer6(n) = n.positive? ? (n - 1) % 9 + 1 : n | |
def answer7(x) = x.succ | |
def answer8(n) = n.digits(2).sum | |
def answer9(s) = s.gsub 'u-g0t-me', 'yikes' | |
def answer10(x = false) = @data10 = x ? 0 : @data10 ? @data10 + 1 : 1 |
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
$* << [//=~'', /$/=~'$'] << () << ->() { | |
$*[~(/$$/=~'$$')][ | |
( $*[~(/$/=~'$')] += (/$/=~'$') ) - (/$/=~'$') | |
] ||= ( | |
$*[~(/$/=~'$')] -= (/$$/=~'$$') | |
$*[~(//=~'')][] + $*[ ~(/$$/=~'$$') ][ $*[~(/$/=~'$')] - (/$$/=~'$$') ] | |
) | |
} | |
# Test |
NewerOlder