Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6544303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:26:58+00:00 2026-05-25T11:26:58+00:00

I have a 500 x 400px square with a 100px grid inside it. Now

  • 0

I have a 500 x 400px square with a 100px grid inside it. Now I want to fill that square with smaller random sized square that snap to the grid. This means that the smaller squares can be either 100, 200, 300 or 400 pixels in size. Their size and position needs to be random, so the output will look different every time it runs.

This image shows the large square, its grid, and a possible output with the smaller squares that I’m trying to create.

Image Test

I’m generating this in Ruby / Sinatra with DIV’s, but I guess the question is more general towards the actual algorithm to use.

Any suggestions on how to do this with the least amount of code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:26:59+00:00Added an answer on May 25, 2026 at 11:26 am

    This method would take a lot of code, but I think what I would do is using Donald Knuth’s Dancing Links algorithm (DLX) (or some other algorithm) to find all possible arrangements of squares. You can compute the arrangements ahead of time, then you can quickly/randomly pick one later when you need them.

    You can read his paper about the algorithm and its application to pentominoes (which is very similar to your problem) here:

    http://www-cs-faculty.stanford.edu/~uno/papers/dancing-color.ps.gz

    http://en.wikipedia.org/wiki/Dancing_Links

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 500 li 's but I only want to show 5 at first,
I have this table: id feed_id ... Let's say that I have 500 rows
I have about 500 cd's that need backing up, they contain old sessions. I
I have about 100k Outlook mail items that have about 500-600 chars per Body.
I have a cluster of 500 linux boxes which now need to use the
I have a short css-based animation that I want to play out before a
considering that each shipment takes two minutes and I have 500 users to send,
I have a series of p tags that I want to have toggle in
I have a table that will have 500,000+ records. Each record has a LineNumber
I have a table called r, inside that table I store id, ip, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.