Jump to content
MakeWebGames

Recommended Posts

Posted

Hey all. Need some help.

I have a grid of 64 squares numbered 1 through 64.

I do an array shuffle of the numbers 1 through 64 and then choose the first 10.

Say the numbers are 1, 9, 13, 20, 33, 42, 47, 50, 51, and 60.

What I'm trying to do is then have those numbers removed from the grid, leaving the remaining numbers on display.

Here's where I need the help, I can't figure out how to do this without having to do a crap ton of elseif's. 

Any ideas or suggestions would be greatly appreciated.

Thanks!

Posted
3 hours ago, newttster said:

Hey all. Need some help.

I have a grid of 64 squares numbered 1 through 64.

I do an array shuffle of the numbers 1 through 64 and then choose the first 10.

Say the numbers are 1, 9, 13, 20, 33, 42, 47, 50, 51, and 60.

What I'm trying to do is then have those numbers removed from the grid, leaving the remaining numbers on display.

Here's where I need the help, I can't figure out how to do this without having to do a crap ton of elseif's. 

Any ideas or suggestions would be greatly appreciated.

Thanks!

Spotted this on Stackoverflow

$ar = range(1,60);
shuffle($ar);
echo implode('<br>', array_slice($ar,0,10)) . '<br>';

it may help unsure not tested

 

Posted

Suggested Solution:

  1. Create an array with numbers from 1 to 64.
  2. Shuffle and select the first 10 numbers.
  3. Remove these numbers using array_diff().
  4. Display the remaining numbers.

     
    <?php
    // Grid with numbers from 1 to 64
    $grid = range(1, 64);
    
    // Shuffle the numbers
    shuffle($grid);
    
    // Select the first 10 numbers
    $numbersToRemove = array_slice($grid, 0, 10);
    
    echo "Removed numbers: " . implode(", ", $numbersToRemove) . "<br>";
    
    // Remove the selected numbers from the grid
    $remainingGrid = array_values(array_diff($grid, $numbersToRemove));
    
    echo "Remaining numbers in the grid: " . implode(", ", $remainingGrid);
    ?>


     

    Explanation:

  5. range(1, 64): Creates the grid of numbers.
  6. shuffle($grid): Shuffles the numbers.
  7. array_slice($grid, 0, 10): Gets the first 10 numbers.
  8. array_diff(): Removes the unwanted numbers.
  9. array_values(): Reindexes the array to avoid display issues.
Posted (edited)

Thank you, both of you.

I've done all of those things. I think I didn't make myself very clear.

Once I have the remaining numbers, I need them visibly removed from the grid.

The closest I can get for a visual is a sudoku board. Visualize the grid numbered 1 - 64. First row 1 - 8, second row 9 - 16, and so on.

I can easily get the remaining numbers, what I can't get is the grid itself to show just the remaining numbers.

The numbers removed are 1, 9, 13, 20, 33, 42, 47, 50, 51, and 60.

The first row would then display 2, 3, 4, 5, 6, 7, 8

The second row would then display 10, 11, 12, 14, 15, 16.

And so on. I hope this makes it clearer what I'm trying to achieve. 

Thank you!!!

Edit: Or maybe a way to enter the numbers that are remaining after the initial 10 are removed and put them into a table in the database.

Edited by newttster
Posted (edited)

That's the idea. I know what I want for the layout, I just need the step that goes from the numbers being eliminated to the grid (like yours) that would basically show a blank square for the number that has been removed.

Edited by newttster

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.   Paste as plain text instead

  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...