Last active
December 23, 2015 09:59
-
-
Save tompng/6618652 to your computer and use it in GitHub Desktop.
HelloWorlds
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
#!ruby | |
def method_missing name, *args | |
n, a = name.to_s.chars.first, *args | |
return n + a.to_s if n.downcase == n || n.respond_to?(n) | |
String.class_eval{define_method(n){a.size - n.size}} | |
print n + a + (a.reverse.ord - n.ord - a.hex / n.send(n) - n.send(n)).chr | |
end | |
H H eeee l l oo | |
H H e l l o o | |
HHHH eeee l l o o | |
H H e l l o o | |
H H eeee llll llll oo | |
W W oo rrr l ddd | |
W W o o r r l d d | |
W W W o o rrr l d d | |
WW WW o o r r l d d | |
W W oo r r llll ddd |
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
#!ruby | |
def ARGV.method_missing name | |
name.to_s.instance_eval{unpack reverse} | |
end | |
print *ARGV.SGVsbG8gV29ybGQKm |
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
#!ruby | |
class BrainF_ck | |
def initialize *p | |
@code=[] | |
if p.empty? | |
@@index=[@@arr=[]].size | |
else | |
@parent=p.first | |
end | |
end | |
def + | |
@code<<->{@@arr[@@index]=-~@@arr[@@index].to_i} | |
self | |
end | |
def - | |
@code<<->{@@arr[@@index]= ~-@@arr[@@index].to_i} | |
self | |
end | |
def > | |
@code<<->{@@index=-~@@index} | |
self | |
end | |
def < | |
@code<<->{@@index= ~-@@index} | |
self | |
end | |
def L | |
child=BrainF_ck.new self | |
@code<<child | |
child | |
end | |
def J | |
@parent | |
end | |
def ! | |
@code<<->{print @@arr[@@index].to_i.chr} | |
self | |
end | |
def self.do | |
BrainF_ck.new | |
end | |
def end | |
to_proc.call | |
end | |
def to_proc | |
->{@code.each{|c|c.call}} | |
end | |
def call | |
to_proc.call until @@arr[@@index].to_i.zero? | |
end | |
end | |
BrainF_ck.do. | |
+. +. +.+.L.-. >. +. +.+. | |
<. J. >. L. -. >. +. | |
+. +. <. J. >. L. -. | |
>.+.>.+. +.<.<.J. >. >. !. +. | |
+. +. L. -. >. +. >. | |
+. <. <. J. <. L. -. | |
>. +. >.+.<.<. J.>.>.-. -.-.-.-. -.-. | |
-. -. -.!. +.+.+. +. +.+.+. !. | |
!. +. +. +. !. <. -. -. -. -. | |
!. L. -. -. >. >. +. <. <. J. >. | |
>. -. -. -. -. !.<.!. +. +. +. !. | |
-. -. -. -. -. -. !. <. <. +. | |
+. +. +. +. +. +. +. L. -. | |
>. +. >.-. <. <. J.>.>.!. <.+.+. !. | |
end |
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
#!ruby | |
$><<[$/[$....$.]<<[~[~$./~$.>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.>>~$.][$.]<<~[~[~[~$.>>~$.>>~$.][$.]>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.][$.]/~$.<<[~[~[~$.>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.][$.]>>~$.>>~$.][$.]<<[~[~[~$.>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.][$.]>>~$.>>~$.][$.]<<~[~[~$.>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.>>~$.>>~$.][$.]<<[~$./~$.>>~$.>>~$.>>~$.>>~$.>>~$.][$.]<<~[~[~[~$./~$.>>~$.>>~$.][$.]/~$.>>~$.][$.]>>~$.>>~$.>>~$.][$.]<<~[~[~$.>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.>>~$.>>~$.][$.]<<[~[~[~$.>>~$.>>~$.>>~$.][$.]>>~$.>>~$.>>~$.][$.]/~$.>>~$.][$.]<<[~[~[~$.>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.][$.]>>~$.>>~$.][$.]<<[~[~[~$.>>~$.>>~$.][$.]>>~$.>>~$.>>~$.][$.]/~$.>>~$.>>~$.][$.]<<[~[~$./~$.>>~$.>>~$.][$.]/~$.>>~$.][$.]][$.] | |
__END__ | |
#[]<>$.~/ generator(very slow) | |
def gen arr | |
"$><<[$/[$....$.]<<"+ | |
"Hello World\n".chars.map{|c| | |
begin | |
next arr[c.ord] if c==eval("''<<#{arr[c.ord]}") | |
rescue | |
end | |
"[#{arr[c.ord]}][$.]" | |
}.join("<<")+"][$.]" | |
end | |
arr={0=>'$.'} | |
$.=0 | |
ops=[ | |
->(a,b){"#{a}/#{b}"}, | |
->(a,b){"#{a}<<#{b}"}, | |
->(a,b){"#{a}>>#{b}"} | |
] | |
nyoro=->(a){"~#{a}"} | |
updates=[0] | |
MAX=128 | |
while true | |
keys=arr.keys | |
prevupdates=updates.uniq | |
updates=[] | |
add=->exp{ | |
return unless exp | |
begin | |
n=eval(exp) | |
rescue | |
return | |
end | |
if n.abs<=MAX && (arr[n].nil? || exp.size < arr[n].size) | |
arr[n]=exp | |
updates << n | |
end | |
} | |
abfind = ->a,b{ | |
aa=arr[a] | |
bb=arr[b] | |
aaa="[#{aa}][$.]" | |
bbb="[#{bb}][$.]" | |
ops.each do |op| | |
add[op.(aa,bb)] | |
add[op.(aaa,bb)] | |
add[op.(aa,bbb)] | |
add[op.(aaa,bbb)] | |
end | |
} | |
prevupdates.each{|a| | |
add[nyoro.(arr[a])] | |
add[nyoro.("[#{arr[a]}][$.]")] | |
} | |
prevupdates.each{|b,|keys.each{|a,| | |
abfind.(a,b) | |
abfind.(b,a) | |
}} | |
break if updates.size==0 | |
p [updates.size,(0..127).count{|i|arr[i]},arr.count] | |
if "Hello World\n".chars.all?{|c|arr[c.ord]} | |
code=gen arr | |
puts code.size | |
puts code | |
eval code | |
end | |
end | |
code=gen arr | |
puts code.size | |
puts code | |
eval code |
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
#!ruby | |
=-~$. | |
def | |
$><< .chr | |
end | |
def | |
+ | |
end | |
def | |
-~ | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment