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
-
It seems like there are two styles of programming, which I call "subtractive" and "additive" (like 3D printing). permutations('A' .. 'J').filter(λ p: 'AB' in p or 'BA' in p) ^ subtractive means enumerate all possibilities, then remove constraint violations.
1 reply 0 retweets 4 likesShow this thread -
But subtractive is hard to reason about analytically -- how to compute len(..)? Then we rewrite additively: permutations(['AB'] + 'C' .. 'J') + permutations(['BA'] + 'C' .. 'J') Now we can easily derive the formula permutations(9) * 2.
2 replies 0 retweets 2 likesShow this thread -
Maybe this is actually a compiler problem: how can you rewrite the subtractive program (which naturally falls out of the problem statement) into an additive one (which is easily countable)? i.e. how do you remove all conditional expressions?
3 replies 0 retweets 6 likesShow this thread -
Replying to @wcrichton
I could imagine a nice set of rewrite rules that captures most of the reasoning, and one could teach these rules to students. This sketch connects the subtractive and additive versions. The two equalities allow you to simplify perm . keep in different ways.pic.twitter.com/I16CP0w1eJ
1 reply 0 retweets 1 like -
Replying to @joshmpollock @wcrichton
In many domains, rewrites reify insight. In my experience, they make some tricks more tangible, generalizable, and easier to prove and reason about.
1 reply 0 retweets 1 like
Yes! This sketch is very much what I imagined as a formal representation of the problem solving process. The last remaining issue is how to systematically deduce perm(A..J) -> keep AB = perm(AB, C..J). Seems too specific about to be a general rewrite rule.
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