Skip to content

Instantly share code, notes, and snippets.

@kevinhowbrook
Last active June 2, 2018 14:01
Show Gist options
  • Save kevinhowbrook/a9e7b8115582c0e2a14d9dffaca470fd to your computer and use it in GitHub Desktop.
Save kevinhowbrook/a9e7b8115582c0e2a14d9dffaca470fd to your computer and use it in GitHub Desktop.
#onmedium
def calculate_m():
# get a list of possible squared numbers, this give us the number of
# rows and columns to use for the canvas, eg 4 = 2 x 2, 6 = 3 x 3...
# Return: [] of squared numbers up to 10000 (hopefully we don't get that high!)
m = []
for i in range(1,10000):
m.append(i*i)
return(m)
def grid(n,m):
# given the amount of words, work out what grid or M we will need
# 5 words should use 9 (m = 9) a 3 x 3 grid
# Parameters:
# n: a list of elements
# m: a list of squared numbers
word_count = len(n)
for i,m in enumerate(m):
if m - word_count > 0 or m - word_count == 0:
# loop stops when the amount of words can fit in a grid
# eg ((m = 9) - (word_count = 5) = greater than 0 so use 9 (3x3)
return float(m)
break
m = grid(convert(), calculate_m())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment