Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

273779BD00000578-3022885-Lightning_strik

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!

 

 

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

  • Author
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 by simple
clarity

  • 2 weeks later...

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 by Redouane

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 by kao

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.