Jump to content

How to calculate how many layers i can make from the available blocks to build a pyramide ?


Recommended Posts

Hey guys,

I'm still a beginner in php and need some help from you with my coding. I need to calculate how many layers i can make with the available blocks.

see example below. For example, if  i have 6 blocks, the pyramide will be 3 layers high, with 10 blocks 4 layers high ect.

 

Thank you in advance.

image.png.82a211992982588db77d51912ed0b622.png

 

<?php

$blocks = readline("enter how many blocks are available for a pyramid?") . PHP_EOL;
$h = 1;

while ($h <= $blocks) {
    $layers = $h++;
}
echo $layers;

?>

Is there any solution for this?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.