I need to create an inverted pyramid, please help me

D

Daniel Pitts

in pseudo code:

(define (-- n) (- n 1))

(define (n-times fun n)
(if (not (zero? n))
(begin
(fun n)
(n-times fun (-- n)))))

(define (display-row biggest-row n port)
(n-times (lambda (n) (display " " port)) (ceiling (/ (- biggest-
row n) 2)))
(n-times (lambda (n) (display "*" port)) n)
(newline))

(define (display-pyramid rows port)
(define (rec-disp-py rows n port)
(cond
((zero? n) (display-row rows 1 port))
((> n 0)
(display-row rows n port)
(rec-disp-py rows (- n 2) port)
)))

(rec-disp-py rows rows port))

(define (pyramid)
(display-pyramid 6 (current-output-port)))
Is that truly pseudo code, or will it run through a lisp interpreter?
 
O

osmium

Daniel Pitts said:
Is that truly pseudo code, or will it run through a lisp interpreter?

It is most certainly NOT pseudocode. Pseudocode is a technique for humans
to communicate with one another. The part starting at:
in pseudo code
is full of stuff that means zilch to an ordinary human being.
 
A

Annie

(e-mail address removed) wrote:
[skip]
main()
{
int i,j,k;
for(i=0;i<5;i++) //loop for number of lines in pyramid
{
for(j=0;j<=i-1;j++) //loop for spaces in each line
cout<<" ";

for(k=1;k<=5-2*i;k++) // number of stars per line
cout<<"*";

cout<<"\n";
}

getch();
}


Look at 5-2*1; At our first iteration this wud be 3*. But the first
line resulted to 5 stars.

During the first iteration, i is 0, not 1. So that the number of
stars per line is 5-2*0.

Another way to look at it: the two following loops are equivalent:

for (i=0; i<5; i++) {
// display a pyramid line
}

And:

i=0;
while (i<5) {
// display a pyramid line
i++;
}

The loop counter is incremented at the end of the loop body.
 
R

rh75691

(e-mail address removed) wrote [18/02/09 16:48]:
Hey guys,
I just need some help here, I kept on redoing this but still no luck.
I need to code an inverted pyramid:
******
 ****
  **
   *

// pyramid
#include <iostream>
int main() {
   unsigned n = 60;
   for(unsigned i = 0; i < n*(n+1)/2; ++i)
     std::cout << (i%(n+1) == n ? '\n' : i%(n+1)-i/(n+1) < n-1-2*i/(n+1)
? '*' : ' ');

}

// nuke!!
#include <iostream>
int main() {
   unsigned n = 60;
   for(unsigned i = 0; i < n*(n+1); ++i)
     std::cout << (i%(n+1) == n ? '\n' : i%(n+1)-i/(n+1) < n-1-2*i/(n+1)
? '*' : ' ');

}

:p

Zeppe

f*** man, that is just tooooooooooooooo sophisticated you robot
 
R

rh75691

(e-mail address removed) wrote [18/02/09 16:48]:
Hey guys,
I just need some help here, I kept on redoing this but still no luck.
I need to code an inverted pyramid:
******
 ****
  **
   *

// pyramid
#include <iostream>
int main() {
   unsigned n = 60;
   for(unsigned i = 0; i < n*(n+1)/2; ++i)
     std::cout << (i%(n+1) == n ? '\n' : i%(n+1)-i/(n+1) < n-1-2*i/(n+1)
? '*' : ' ');

}

// nuke!!
#include <iostream>
int main() {
   unsigned n = 60;
   for(unsigned i = 0; i < n*(n+1); ++i)
     std::cout << (i%(n+1) == n ? '\n' : i%(n+1)-i/(n+1) < n-1-2*i/(n+1)
? '*' : ' ');

}

:p

Zeppe

Zeppe dude,

The first iteration of for's cout is:
1 == 60 ? '\n' : 1 < 59 ? '*' : ' ';

1 == 60 is false right, so the condition will execute 1 < 59. 1 < 59
is true so it will execute '*'

Hmm i get it a bit, I'll print this code and study it carefully.

Wow you're super geek man, how can you figure out those numbers!! it
amazes me
 
R

rh75691

(e-mail address removed) wrote [18/02/09 16:48]:
Hey guys,
I just need some help here, I kept on redoing this but still no luck.
I need to code an inverted pyramid:
******
 ****
  **
   *

// pyramid
#include <iostream>
int main() {
   unsigned n = 60;
   for(unsigned i = 0; i < n*(n+1)/2; ++i)
     std::cout << (i%(n+1) == n ? '\n' : i%(n+1)-i/(n+1) < n-1-2*i/(n+1)
? '*' : ' ');

}

// nuke!!
#include <iostream>
int main() {
   unsigned n = 60;
   for(unsigned i = 0; i < n*(n+1); ++i)
     std::cout << (i%(n+1) == n ? '\n' : i%(n+1)-i/(n+1) < n-1-2*i/(n+1)
? '*' : ' ');

}

:p

Zeppe

I tried to run a simulation of your code, it runs so beautifully:

1 < 1830
1 == 60 ? '\n' : 1 < 59 ? '*' : ' ';

2 < 1830
2 == 60 ? '\n' : 2 < 59 ? '*' : ' ';

3 < 1830
3 == 60 ? '\n' : 3 < 59 ? '*' : ' ';

4 < 1830
4 == 60 ? '\n' : 4 < 59 ? '*' : ' ';

5 < 1830
5 == 60 ? '\n' : 5 < 58 ? '*' : ' ';

6 < 1830
6 == 60 ? '\n' : 6 < 58 ? '*' : ' ';

7 < 1830
7 == 60 ? '\n' : 7 < 58 ? '*' : ' ';

60 < 1830
60 == 60 ? '\n' : 59 < 57 ? '*' : ' ';

70 < 1830
9 == 60 ? '\n' : 7.85245902 < 56.704918 ? '*' : ' ';

DAMN. How did you manage to figure out those numbers man?? I'm
affectionally amazed!!
 
E

eminhanif

****!!!!!
30 adults arguing over how to print a FUCKING up the fucking side down
P_Y_R_A_M_I_D!!!!!!!!!!!!!!!!

oh... oh my...oh never minds its hopeless....
 
J

Juha Nieminen

****!!!!!
30 adults arguing over how to print a FUCKING up the fucking side down
P_Y_R_A_M_I_D!!!!!!!!!!!!!!!!

oh... oh my...oh never minds its hopeless....

Arguing? Where?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,172
Latest member
NFTPRrAgenncy
Top