Created
December 20, 2013 02:56
-
-
Save madgen/8049814 to your computer and use it in GitHub Desktop.
Biquine between Ruby and Java in less than 100 lines of Ruby with use of ASCII table.
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
# PRELUDE: | |
# This is my first biquine. It is between Ruby and Java. | |
# It uses ASCII table to handle issues involving fixed point. | |
# It should work with all versions of Ruby but it definitely works in 2.0 | |
# It should work with all versions of Java and definitely works with 7. | |
# It is not super DRY so it can be refactored to be shorter but 96 lines | |
# is not so bad I guess (I know it is pretty terrible). | |
# Also it is fun to write so if you haven't tried, I highly reccommend it. | |
# USAGE: | |
# To get Ruby code with Ruby | |
# ruby ruby_to_java_biquine.rb | |
# To get Java code with Ruby | |
# ruby ruby_to_java_biquine.rb bro | |
# Save Java code to a file named brother.java | |
# then compile it. | |
# To get Java code with Java | |
# java brother | |
# To get Ruby code with Java | |
# java brother bro | |
# BEGIN QUINE: | |
rb_data = [ | |
"rb_data = [", | |
"]", | |
"", | |
"java_data = [", | |
"]", | |
"", | |
"if ARGV[0] == %q|bro|", | |
" puts java_data[0...3]", | |
" java_data.each do |l|", | |
" puts 32.chr * 2 + 34.chr + l + 34.chr + 44.chr", | |
" end", | |
" puts java_data[3...6]", | |
" rb_data.each do |l|", | |
" puts 32.chr * 2 + 34.chr + l + 34.chr + 44.chr", | |
" end", | |
" puts java_data[6..-1]", | |
"else", | |
" puts rb_data[0]", | |
" rb_data.each do |l|", | |
" puts 32.chr * 2 + 34.chr + l + 34.chr + 44.chr", | |
" end", | |
" puts rb_data[1...4]", | |
" java_data.each do |l|", | |
" puts 32.chr * 2 + 34.chr + l + 34.chr + 44.chr", | |
" end", | |
" puts rb_data[4..-1]", | |
"end", | |
] | |
java_data = [ | |
"public class brother {", | |
" public static void main(String[] args) {", | |
" String[] javaData = {", | |
" };", | |
"", | |
" String[] rbData = {", | |
" };", | |
"", | |
" if (args.length == 1 && args[0].equals(", | |
" new String() + (char) 98 + (char) 114 + (char) 111)) {", | |
" p(rbData[0]);", | |
" dataLoop(rbData, 2);", | |
" for(int i = 1; i < 4; i++)", | |
" p(rbData[i]);", | |
" dataLoop(javaData, 2);", | |
" for(int i = 4; i < rbData.length; i++)", | |
" p(rbData[i]);", | |
" } else {", | |
" for(int i = 0; i < 3; i++)", | |
" p(javaData[i]);", | |
" dataLoop(javaData, 6);", | |
" for(int i = 3; i < 6; i++)", | |
" p(javaData[i]);", | |
" dataLoop(rbData, 6);", | |
" for(int i = 6; i < javaData.length; i++)", | |
" p(javaData[i]);", | |
" }", | |
" }", | |
"", | |
" public static void p(String s) {", | |
" System.out.println(s);", | |
" }", | |
"", | |
" public static void dataLoop(String[] data, int spaces) {", | |
" for(int i = 0; i < data.length; i++) {", | |
" for(int j = 0; j < spaces; j++)", | |
" System.out.print((char) 32);", | |
" System.out.print((char) 34);", | |
" p(data[i] + (char) 34 + (char) 44);", | |
" }", | |
" }", | |
"}", | |
] | |
if ARGV[0] == %q|bro| | |
puts java_data[0...3] | |
java_data.each do |l| | |
puts 32.chr * 6 + 34.chr + l + 34.chr + 44.chr | |
end | |
puts java_data[3...6] | |
rb_data.each do |l| | |
puts 32.chr * 6 + 34.chr + l + 34.chr + 44.chr | |
end | |
puts java_data[6..-1] | |
else | |
puts rb_data[0] | |
rb_data.each do |l| | |
puts 32.chr * 2 + 34.chr + l + 34.chr + 44.chr | |
end | |
puts rb_data[1...4] | |
java_data.each do |l| | |
puts 32.chr * 2 + 34.chr + l + 34.chr + 44.chr | |
end | |
puts rb_data[4..-1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment