simple Posted December 5, 2015 Posted December 5, 2015 2015 has been a very active year for volcanoes. It's a very active year for ascii art volcanos too \/\/\//<---------------- Peak of Eruption \ / \_/<------------------ Base of Eruption / \<------------------ Peak of volcano / \ / \ / \ /_________\<-------------- Base of Volcano CHALLENGE: Create a code (via function, stdin, etc) that accepts 2 inputs Input1 = Distance in lines between base and peak of volcano Input2 = Distance in lines between base and peak of eruption Based on these inputs, program should output to the console (stdout) the ASCII depiction of a volcano eruption SAMPLES: DrawEruption(Arg1 = VolcanoHeight, Arg2 = EruptionHeight) INPUT: DrawEruption(9, 4) OUTPUT: \/\/\/\// \ / \ / \_/ / \ / \ / \ / \ / \ / \ / \ / \ /_________________\ INPUT: DrawEruption(3, 14) OUTPUT: \/\/\/\/\/\/\/\/\/\/\/\/\/\// \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \_/ / \ / \ /_____\ INPUT: DrawEruption(1, 4) OUTPUT: \/\/\/\// \ / \ / \_/ /_\ How to post solution? Language Name, Size of Program in Bytes - C#, 500 bytes, source code How to size of program? Compiled Languages - U can either count the size in bytes from the EP of the binary to the last instruction or the byte size of the ASCII code - whichever is shorter. C# can use byte size of ASCII code (as in .cs file) or the ASCII byte size of compiled ilasm instructions. Interpreted Languages - Count the size in ASCII bytes of the source. print 'hello world' would be 19 bytes Golfing Languages - CJam, Brainf$ck, golfscript, APL, Pyth, ><>, etc. will take a 250 byte penalty, so that other languages can have a chance. These rules are designed so that all languages have an equal chance of winning & no certain language has any advantage. Who wins? The shortest code! Bonus for drawing console animated eruptions or adding other ASCII effects!
kao Posted December 5, 2015 Posted December 5, 2015 To set some baseline to compete against: C#, 0x103 bytes of IL code (VS2010, compiled in release mode). static void DrawEruption(int volcanoHeight, int eruptionHeight) { string onespace = @" "; string twospace = @" "; string forwardslash = @"/"; // print eruption for (int eruption = 0; eruption < eruptionHeight; eruption++) { string s = twospace; string ss = onespace; if (eruption == 0) { s = @"/\"; ss = forwardslash; } if (eruption == eruptionHeight-1) ss = "_"; // print spacing for (int i = 0; i < Math.Max(0, volcanoHeight - eruptionHeight) + eruption; i++) Console.Write(onespace); // start of eruption Console.Write(@"\"); // eruption itself for (int i = 0; i < eruptionHeight-eruption-1; i++) { Console.Write(s); } // end of eruption Console.Write(ss); Console.WriteLine(forwardslash); } // print base for (int volcanobase = 0; volcanobase < volcanoHeight; volcanobase++) { string s = onespace; if (volcanobase == volcanoHeight - 1) s = @"_"; // print spacing for (int i = 0; i < Math.Max(0, eruptionHeight-volcanoHeight) + volcanoHeight - volcanobase - 1; i++) Console.Write(onespace); // volcano start Console.Write(forwardslash); // volcano itself for (int i = 0; i < 2*volcanobase +1; i++) Console.Write(s); // end of volcano Console.WriteLine(@"\"); } } @simple : I'm not sure I understood correctly how to count "ASCII byte size of compiled ilasm instructions." Please correct me if I'm wrong - sample exe attached. volcano.zip 1
simple Posted December 5, 2015 Author Posted December 5, 2015 (edited) Quote I'm not sure I understood correctly how to count "ASCII byte size of compiled ilasm instructions." Please correct me if I'm wrong - sample exe attached. I'll change that, after looking at how you sized it's a better way. Small code u wrote there kao! Edited December 5, 2015 by simple clarity
Redouane Posted December 13, 2015 Posted December 13, 2015 (edited) Ruby,305 Bytes def drawEruption n,m g=(n-m).abs puts ((1..m-1).map{|x|(n>m ?' '*g :'')+' '*(m-x)+?\\+' '*(2*x-1)+?/}<<(((n>m ?' '*g :'')+'\/'*m+?/))).reverse*"\n\n"+?\n+' '*([n,m].max)+?-+?\n+((1..n).map{|x|(n<m ?' '*g :'')+' '*(x-1)+?/+' '*(2*(n-x)+1)+?\\}.reverse)*"\n\n"+?\n+(n<m ?' '*(g+1):' ')+'-'*(2*n-1) end Messy,I know. Usage : drawEruption(volcanoHeight,eruptionHeight) or drawEruption volcanoHeight,EruptionHeight Small 32bit executable,just to test it,packaged with Ocra. Volcano.exe Volcano.zip Edited December 13, 2015 by Redouane
kao Posted December 13, 2015 Posted December 13, 2015 (edited) Spoiler @Redouane: what am I missing here? Quote F:\>Volcano.exe Enter volcanoHeight and eruptionHeight,two integers separated by any separator Enter e to exit 9,4 C:/Temp/ocrF276.tmp/src/Volcano.rb:3:in `drawEruption': undefined method `-' for nil:NilClass (NoMethodError) from C:/Temp/ocrF276.tmp/src/Volcano.rb:13:in `block in <main>' from C:/Temp/ocrF276.tmp/src/Volcano.rb:8:in `loop' from C:/Temp/ocrF276.tmp/src/Volcano.rb:8:in `<main>' EDIT: nevermind, figured out how to use it. First press Enter, then enter 2 integers.. Edited December 13, 2015 by kao
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now