-
Notifications
You must be signed in to change notification settings - Fork 1
/
constants_find.rb
66 lines (62 loc) · 2.98 KB
/
constants_find.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# TODO: update the list for specification v2
require_relative "lib/rasel"
require "set"
require "pcbr"
require "timeout"
require "pp"
pcbr = PCBR.new
best = []
seen = []
loop do
puts ""
unseen = (pcbr.table.sort_by(&:last).map(&:first) - seen)
base = unseen.first || ""
p [seen.size, unseen.size, base, pcbr.table.size]
seen.push base
pp( best.sort.group_by(&:first).flat_map do |n, g|
shortest = g.map(&:last).map(&:size).min
g.map{ |n, code| [n, code, [code.size, code.delete("^0-9A-Z").chars.max || "0"]] if code.size == shortest }.
compact.sort_by(&:last)
end )
sorted = pcbr.table.reject do |_|
%w{
0 1 Z 0: 01 10 1: 01- 0Z- 01\\ 1:\\ 1Z- 1Z/ Z1\\ 01-0 01-1 01-: 01\\-
01-01- 01-1\\ 01\\-0 01\\-1 01\\-: 101-- 01-Z- 01-Z/ 0Z-1- 0Z-1\\ 0Z-Z- 1Z-1\\ 1Z-Z- 1Z-Z/ 01Z/- 10Z-/ 1:Z-/ 1Z/Z/
1Z/1- 1Z/1\\ 1Z/Z-
}.include? _.first
end.sort_by{ |_| [_.last, _.first] }
pp sorted[0..9]
pp sorted[-10..-1]
# %w{ 0 1 Z # : $ j ? - / % \\ }.each do |c|
%w{ 0 1 Z : $ ? - / % \\ }.each do |c|
code = base + c
next unless %w{ 0 1 Z }.include? code[0]
# next unless %w{ 0 1 Z # }.include? code[0]
# next if %w{ 0j ## }.include? code[-2,2]
next if code[/[-\/%:01Z]\$\z/]
next if code[/0:*[-?\\\/%]\z/]
next if code[/[01Z](:|[01Z]-)*\?\z/]
next if code[/[01Z](:|[01Z]-)*[1Z]%\z/]
next if code[/[01Z](:|[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Z1\\Z/ Z1\\:? Z1\\:\\ Z1\\1% Z1\\1- Z1\\:/ }.include? code[0,5]
# next if %w{ }.include? code[0,6]
begin
result = Timeout.timeout(0.1){ RASEL("Z-Z-" + code + " 0@") }
rescue Timeout::Error
next
end
next unless result.exitcode.zero?
next unless result.stack.first == -70
pcbr.store code, [(result.stack.size - 2).abs, base.size]
best.push [result.stack[1].to_i, code] if result.stack.size == 2 && result.stack[1] > 0 && result.stack[1].denominator == 1
end
end