Combinatorics problem: you're arranging 10 people (A .. J) in a row. A and B must sit next to each other. How many arrangements? How could writing this problem as a program help scaffold the problem-solving process?
-
Show this thread
-
Replying to @wcrichton @hillelogram
I would reframe it as arranging 9 units: (AB) and C .. J. The result is the number of permutations of 9 things × 2 — one set for AB and another for BA. I find a lot of tricky problems get simpler if you can find a non-obvious thing to treat as a first-class entity.
2 replies 0 retweets 13 likes -
Replying to @munificentbob @hillelogram
Agreed! That's the "additive" solution I mention (see down in the thread). My question: what is a general strategy to help people reach this solution from the problem statement?
1 reply 0 retweets 0 likes -
Replying to @wcrichton @munificentbob
I don't think there is one. The problem is that "insight" is fragile: if you instead asked "where A and B are NOT adjacent", I don't think you can use the same constructive solution. You could instead say it's 10! - (9!*2), but that's another leap of insight
1 reply 0 retweets 5 likes -
And if we instead perturbed to "A and B have *exactly one* person between them", I don't see what the constructive solution would be at all
1 reply 0 retweets 0 likes -
Replying to @hillelogram @munificentbob
What about: sum([ permutations([f'A{p}B'] + 'C' .. 'J' - [p]) + permutations([f'B{p}A'] + 'C' .. 'J' - [p]) for p in 'C' .. 'J' ]) Inner loop is 8! * 2, 8 iterations of outer loop, so count is 8 * 8! * 2.
2 replies 0 retweets 0 likes -
I checked my solution this way.pic.twitter.com/p2O23k7VV7
-
-
Replying to @wcrichton @munificentbob
Faster than MiniZinc, which took one minute :Ppic.twitter.com/JmudLxC8Iy
0 replies 0 retweets 2 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
cognitive psychology. PhD