Skip to content

Instantly share code, notes, and snippets.

@shinh
Created May 6, 2020 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinh/fac3952336776d8dc34433a94474bdad to your computer and use it in GitHub Desktop.
Save shinh/fac3952336776d8dc34433a94474bdad to your computer and use it in GitHub Desktop.
esolang golf #6 in cyclic bf
# size base 1pad 2pad step pad code loop mod tbl total
# mod4 27 0 0 (2) 2 29 3
# mod6 27 4 1 (3) 0 32 3 1 17 53+
# mod8 27 0 2 (4) 6 35 3 3 17 58
# mod9 27 1 5 0 2 35 3 1 17 56
# mod10 27 2 3 (5) 2 34 3 3 17 57
# mod12 27 4 4 (6) 6 41
mapping = '<[>]+,-.Z'
#mapping = '[]+-.<>,'
$mapping = mapping
#code = '8,[>>,>,[-<-<+>>],,<4[><>]8<.,,,,+><]'
#code = '8,[>>,>,[-<-<+>>],,<[><><><>]<.,,,,+<><><>]'
#code = '8,[>>,>,[-<-<+>>],,<4[><>]8<.,,,,+<><><>]'
#code = '8,[>>,>,[-<-<+>>],,>>,,,,+<<<4[><>]8<.>>]'
#code = '8,[>>,>,[-<-<+>>],,<4[><>]8<.,,,,+<><><>]'
# OK
#code = '9,[>>,>,[-<-<+>>Z],,<[<><><>>Z]<.,,,,+]'
code = '[>>9,>,[-<-<+>>Z],,<[<><><>>Z]<.,,,,+]'
def shuffle(c, idx, s)
(c + idx - 33) % s + 33
end
def map_op(c)
c - 33 < 8 ? $mapping[c - 33].ord : c
end
ops = '+-<>[].,'
8.times{|i|ops << (i + 33)}
mod = 61
out = []
idx = 0
code.each_char do |c|
if c =~ /\h/
mod = c.hex
if c.hex == 4
idx += 4
end
out << (-c.to_i & 255)
else
tgt = mapping.index(c)
if tgt
tgt = (tgt - idx) % mod
else
tgt = -1
end
if idx <= 2
tgt += 9
if idx == 2
tgt += 9
end
end
tgt = tgt + 33
out << tgt
idx += 1
end
end
out << "\n".ord
mapping[0, 8].each_byte.with_index do |c, i|
out << (i + 33)
out << c
end
File.open('ut5.cbf', 'w') do |of|
of.print out.pack("C*")
end
STDERR.puts "size=#{File.size('ut5.cbf')}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment