| about | help | code help+videos | done | prefs |
perfect_square_dance
This is CarTalk Puzzler #201028: RAY: This was from my ballroom dancing series and it was sent in by Dennis Vogel. Sally invited 17 guests to a dance party at her estate in the Hamptons. She assigned each guest a number from 2 to 18, keeping 1 for herself. At one point in the evening when everyone was dancing, Sally noticed the sum of each couple's numbers was a perfect square. Everyone was wearing their numbers on their clothing. The question is, what was the number of Sally's partner? Here's a reminder: a perfect square is attained by squaring, or multiplying by itself, an integer. So four is a perfect square of two. Nine is a perfect square of three. Sixteen is a perfect square of four. So these numbers are adding up to either 4, 9, 16, 25, etc. And the question is, with the information you have available to you, what's the number of her partner? Write the function perfect_square_dance(n), which takes the number of dancers n as input. As output, it should return not just Sally's partner, but a list of pairs of partner numbers, sorted by lowest numbers first (both withn a pair and across all pairs). Return None if it can't be done. perfect_square_dance(18) → [[1, 15], [2, 14], [3, 13], [4, 12], [5, 11], [6, 10], [7, 18], [8, 17], [9, 16]] perfect_square_dance(8) → [[1, 8], [2, 7], [3, 6], [4, 5]] perfect_square_dance(10) → None ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 324 Post-solution available
Copyright Nick Parlante 2017 - privacy