Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRectArrangements returns poor results for some square numbers #12

Open
kylemcdonald opened this issue Dec 24, 2018 · 0 comments
Open

Comments

@kylemcdonald
Copy link

import rasterfairy
for side in range(4, 100):
    n = side*side
    best = rasterfairy.getRectArrangements(n)[0]
    if side != best[0]:
        print(side, best)

i would expect this to print nothing, because getRectArrangements should quickly find that there is a square available. instead, it prints:

not enough memory for amount of possible permutations, creating grouped set
not enough memory for amount of possible permutations, creating grouped set
48 (36, 64)
not enough memory for amount of possible permutations, creating grouped set
not enough memory for amount of possible permutations, creating grouped set
72 (64, 81)
not enough memory for amount of possible permutations, creating grouped set
80 (64, 100)
not enough memory for amount of possible permutations, creating grouped set
96 (72, 128)

this makes me skeptical that it's generally finding the best solution.

here is an alternative implementation that i use, it finds the rectangle that is closest to a square:

import math
def find_rectangle(n): 
    max_side = int(math.sqrt(n))
    for h in range(2, max_side+1)[::-1]:
        w = n // h
        if (h * w) == n:
            return (h, w)
    return (n, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant