title: Drawing Bowling Pins (pyramid) with Recursion in Ada
body: <p>I know this is pushing the good will of the community by presenting my least elaborate work expecting someone to come and save me but I simply have no choice with nothing to lose. I've gone through packets, files, types, flags and boxes the last few weeks but I haven't covered much of recursion. Especially not drawing with recursion. My exam is in roughly one week and I hope this is ample time to repeat and learn simple recursion tricks like that of drawing bowling pins or other patterns: </p>
  
  <pre><code>I I I I I
   I I I I
    I I I
     I I
      I
  n = 5
  </code></pre>
  
  <p>The problem I have with recursion is that I don't quite get it. How are you supposed to approach a problem like drawing pins like this using recursion?</p>
  
  <p>The closest I've come is</p>
  
  <pre><code>I I I
  I I
  I
  n = 3
  </code></pre>
  
  <p>and that's using </p>
  
  <p><strong>THIS CODE NOW WORKS</strong></p>
  
  <pre><code>with Ada.Text_IO; use Ada.Text_IO;
  with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
  
  procedure pyramidchaser is
  
     subtype X_Type is Integer range 0..30;
     X: X_Type;
     Indent : Integer := 0;
  
     procedure Numbergrabber (X : out Integer) is
     begin
  
        Put("Enter a number: ");
        Get(X);
        Skip_Line;
     end Numbergrabber;
  
  
     procedure PrintSpaces(I : in Integer) is
     begin 
        if I in X_Type then
        Put(" ");
        else
       return;
        end if;
  
        PrintSpaces(I - 1);
     end Printspaces;
  
  
  
  
     procedure PrintPins(i, n: in Integer) is
     begin
        if i &gt;= n then 
       return;
        end if;
  
      Put('I');
      Put(' '); 
  
      PrintPins(i + 1, n);
      end Printpins;
  
  
  
  
     function Pins (X, Indent: in Integer) return Integer is
  
        Printed : Integer;
  
     begin
  
        Printed:= 0;
        if X &gt; 0 then
       PrintSpaces(Indent);
       PrintPins(0, X);
       New_Line; 
  
       Printed := X + Pins(X - 1, Indent + 1);
        end if;
        return Printed;
  
     end Pins;
  
     Bowlingpins : Integer;
  
  begin
  
     Numbergrabber(X);
     Bowlingpins:= Pins(X, Indent);
  
  end pyramidchaser;
  
  
  
  
  </code></pre>
  
  <p>but with that I throw in a sum I dont really need just to kick off the recursive part which I dont really know why I do except it seems to be needed to be there. I experimented with code from a completely different assignment, thats why it looks the way it does. I know mod 2 will grant me too many new lines but at least it was an approach to finding heights to the pyramid. I understand the real approach is something similar to N+1 as with each step of the growing pyramid a new line is needed, but I dont know how to implement it.</p>
  
  <p>I don't expect anyone to present a complete code but I hope somebody can clue me in on <em>how to think</em> on the way towards finding a solution.</p>
  
  <p>I can still pass the exam without knowing recursion as its typically 2 assignments where one is and one isnt recursion and you need to pass one or the other, but given that I have some time I thought Id give it a chance.</p>
  
  <p>As always, immensely thankful for anyone fighting the good fight!</p>
  
  <p><em>Seeing this post gathered some attention</em> Id like to expand the pyramid to one a little more complex: </p>
  
  <p><strong>THE PYRAMID PROBLEM 2</strong></p>
  
  <p>hope someone looks at it. I didnt expect so many good answers, I thought why not throw all I have out there.</p>
  
  <pre><code>Level 1
  |=|
  
  Level 2
  |===|
  ||=||
  |===|
  
  Level 3
  
  |=====|
  ||===||
  |||=|||
  ||===||
  |=====|
  
  it needs to be figured out recursively. so some way it has to build both upwards and downwards from the center. 
  </code></pre>
  
  <p>To clarify Im studying for an exam and surely so are many others whom would be thankful for code to sink their teeth in. Maybe theres an easy way to apply what Tama built in terms of bowling pin lines in pyramid walls?  </p>