Skip to content

Instantly share code, notes, and snippets.

@tompng
Last active January 5, 2021 11:58
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 tompng/020007c9025ada2c8a3eca9640b06442 to your computer and use it in GitHub Desktop.
Save tompng/020007c9025ada2c8a3eca9640b06442 to your computer and use it in GitHub Desktop.
丑年2021 Quine
;" s=
s.s pli
t(f= 35.c
hr)[0 ]+f;z
='gIa ".tap{$s=_1};s=$s+"AgI CAg4C
";c='s=s.split*""';s<<%"AgPCAgICAnICAh
8CAgIC ";p=->{eval(eval(c))};s<<"D4ICAvoCAgIC+g ICB+P/
";at_exit(&p);s<<"//8fggICP//////6Ah/H///////j+/////////////
//////////P//////////CB////////gICP+J///I/4gID/nP//zr/AgIP55
//88/iAgJ/g///wv8CAgf///////ICAj///////4ICAv//////8gICD/
//////ggICP//////yAgID//////+CAgIP//////ICA
gJ/4//j/ 4ICAgP/H/8f8gICAg /6//P/Ag
ICAh/// //C AgICAh///8ICAgI CAg ICAgICA
h/iB/o C/w J6B/+C//I/+g/CO h4P B4PC4h
4CA+JyO gIfAuICegeDwgfCDw IfAjoeA
vICcgf/g//iP/of4n/6B/oH/8L/A'.unpack1(?m)
.bytes.map{|c|['%b'%c[6]*(c&63),('%b'%c)[
1..]][c[7]]}*'';include(Math);$><<?%+w=
32.chr;trap(:INT){puts;exit};32.times{|
t|x=[[/[!-$]./,';'+a=34.chr]]+[a+'.ta
p{$s=_1};s=$s+'+a,a+%(;c='s=s.split*)
+a+a+%(';s<<%)+a,a+';p=->{eval(eval
(c))};s<< '+a,a+';at_ exit(&p);
s<<'+a]. map{[f*_1.s ize,_1]}
;o=(0..3 5).map{|y|l =(0..59)
.map{|x|(0..9).sum{|u|sin(E
**u+((x-t+(2*y-t).i)
*2**u.i ).imag/ 9*1.2** u)}-
(t-16)**2* (2*z[60*y.t o_i+x].to_ i-1)/
30. 0<1 ?f: w}* ''; (p, q=x
[0]) &&l [p] &&x. shi
ft&& l[p ]=q ;l}* $/;
o[o. rin dex (f)] =a;
i=-1;puts' %c[H%c[J'%[ 27,27]+(o. gsub(f)
{s[(i+=1)%s .size]} <<0);sleep( 0.05)}"
parse = ->{_1.bytes.map{|c|['%b'%c[6]*(c&63),('%b'%c)[1..]][c[7]]}*''}
def encode(s)
chars = s.delete("\n").chars.map{ _1.match?(/[ 0._-]/) ? '0' : '1' }
data = []
until chars.empty?
if chars[0,7].uniq.size == 7
c = chars.first
n = [chars.take_while{ _1 == c }.size, 63].min
chars.shift n
data << (c.to_i * (1<<6)) | n
else
data << ((1<<7) | (chars.shift(7).join + '000000')[0, 7].to_i(2))
end
end
data.map(&:chr).join
end
data = <<DATA
## ##
### ###
#### ####
##### #####
##### ###################### #####
######################################
###### ######################################## ######
############################################################
############################################################
########################################################
###########################################
######## ################# ########
####### ### ############### ### #######
###### ### ############### ### ######
####### ################# #######
#########################################
#########################################
#######################################
#######################################
#####################################
#####################################
###################################
######### ########### #########
######## ########### ########
######## ########### ########
###########################
####################
####### ####### ####### ####
########## ########### ########## #####
### ### ### ### ### ### ###
#### ### ### #### ###
#### ### ### #### ###
#### ### ### #### ###
########## ########### ########## #######
########### ####### ########### #######
DATA
data = data.lines.map{(_1.rstrip+' '*100)[0,data.lines.map(&:strip).map(&:size).max]}.join
b64 = [encode(data)].pack('m').delete("\n")
s = File.read(__FILE__).split(/\n# CODE\n/)[1].split(/__END__/)[0].gsub('DATA', "'#{b64}'").split.join
def puts_error(*a)
$> << "\e[1m"
puts(*a)
$> << "\e[m"
end
if ARGV[0] == 'test'
require 'open3'
code = ARGV[1] ? File.read(ARGV[1]) : s
nosleep = 'def sleep(n);end;'
output, = Open3.capture3 'ruby', stdin_data: "s=#{s.inspect};" + nosleep + code
output2, = Open3.capture3 'ruby', stdin_data: nosleep + output
puts :not_quine unless output === output2
frames = output.split(/\0\n/).map{_1.gsub(/.+\e\[J/,'')}
frames.each_with_index do |frame, i|
framecode, = Open3.capture3 'ruby', stdin_data: frame.gsub('";p=->{eval(eval(c))};s<<"', '";p=->{$><<(eval(c))};s<<"')
if framecode.split('#').first == code
puts "frame #{i}: #{framecode.size - code.size}"
else
puts_error "error: frame #{i} #{code.size - framecode.size}"
binding.irb
end
end
unless frames.first == frames.last
puts_error "first-last frame mismatch"
binding.irb
end
File.write '2021.rb', frames.first + "\n"
exit
end
eval s;exit
# CODE
s=s.split(f=35.chr)[0]+f;
z=DATA.unpack1(?m).bytes.map{|c|['%b'%c[6]*(c&63),('%b'%c)[1..]][c[7]]}*'';
include(Math);
$> << ?%+w=32.chr;
trap(:INT){puts;exit};
32.times{|t|
x = [[/[!-$]./,';'+a=34.chr]]+[a+'.tap{$s=_1};s=$s+'+a,a+%(;c='s=s.split*)+a+a+%(';s<<%)+a,a+';p=->{eval(eval(c))};s<<'+a,a+';at_exit(&p);s<<'+a].map{[f*_1.size,_1]};
o=(0..35).map { |y|
l = (0..59).map{|x|
(0..9).sum{|u|sin(E**u+((x-t+(2*y-t).i)*2**u.i).imag/9*1.2**u)}
-(t-16)**2*(2*z[60*y.to_i+x].to_i-1)/30.0<1 ? f : w
}*'';
(p,q = x[0])&&l[p]&&x.shift&&l[p]=q;
l
}*$/;
o[o.rindex(f)]=a;
i=-1;
puts'%c[H%c[J'%[27,27]+(o.gsub(f){s[(i+=1) % s.size]}<<0);
sleep(0.05)
}
__END__
;"
put
".tap{$s=_1};s=$s+"
s
";c='s=s.split*""';s<<"
'he
";p=->{eval(eval(c))};s<<"
l l
";at_exit(&p);s<<"
o'
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment