Created
February 11, 2011 09:42
-
-
Save matthewrudy/822139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<<-LRUG Hola El Rug, | |
Here's a little teaser for you... | |
I have two sets of photos; we'll call them urban and nature. Both sets contain about 6-9 photos, but not necessarily the same number. | |
I also have about 15-20 pages on a site, spread more or less evenly across three sections. Each page has a title unique to its section (and, if it helps, we can assume unique across all the pages). | |
On each page I want to display one photo from each set. | |
The constraints in descending order are: | |
* The code should change as little as possible when I add or remove a page or photo. | |
* We should use each photo at least once. | |
* A combination of [urban photo, nature photo] should not appear on more than one page. | |
* And we should try to use all the photos roughly uniformly. | |
Your time starts...now! | |
LRUG | |
U = ["a","b","c","d", "e", "f", "g", "h", "i"] | |
N = ["u", "v", "w", "x", "y", "z"] | |
def s(i, u, n) | |
u_index = i%(u.length) | |
n_offset = i/(u.length) | |
n_index = (u_index+n_offset)%(n.length) | |
[u[u_index], n[n_index]] | |
end | |
results = {} | |
0.upto(50) do |i| | |
value = s(i, U, N) | |
puts value.inspect | |
results[value] ||= 0 | |
results[value] += 1 | |
end | |
# every combo happens once | |
puts results.values.uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lovely.