7 ms·
Split the States (2021)
- anonymous_they 5y agoNot sure if it's just me, but I'm getting really weird rendering bugs when I visit this link. Maybe GitHub's rendering of ipynb files?
- jayspell 5y agoIs this just an exercise?
- hirundo 5y agoIt's a puzzle: "Welcome to The Riddler. Every week, I offer up problems related to the things we hold dear around here: math, logic and probability."
- serverlessmom 5y agowow nice solution, saw this on 538 and couldn't think of any clever solution.
- harperlee 5y agoI quite like the chirurgical, strategic feel of the exposition. Denotes clear thinking, and/or multiple revisions. When I work in some code I often spend too much time on reviewing and enhancing code in this way, but mine being a side project all that work (I’m not the best programmer by far) is either for future me or for no one, and often I end up feeling that I lost time for nothing. But I like to spend time in making this kind of clean code {shrug}.
- adolph 5y agochirurgical [ kī-rûr′jĭ-kəl ] adj. Surgical. No longer in technical use.
- harperlee 5y agoYeah, sorry, still used in spanish, my mother tongue. My bad!
- jwkane 5y agodon't apologize for using a great word. :)
- adolph 5y agoTotally agreed, my comment was just to add meaning in case others also wondered , not a criticism. Gotta love trans-language words. My friends used to say “go hands” whenever it was time to vamanos.
- thaumasiotes 5y agoBut hands, manos, does not even appear in vámonos.
- throwamon 5y agoI was about to say the same, but I just googled to be sure. Apparently "vamanos" is a common (mis)spelling?
- thaumasiotes 5y agoI always thought it was vaminos. Spanish speakers are unlikely to make that mistake, though, because the ending -monos is regular for first-person plural reflexive imperatives. https://es.wiktionary.org/wiki/mirarse#Conjugaci%C3%B3n https://es.wiktionary.org/wiki/mirarse#Conjugaci%C3%B3n (And -monos is etymologically very transparent - it's just the first person plural ending -mos, familiar to everybody, with the first person plural reflexive pronoun nos suffixed onto it and eliding the -s of -mos.)
- adolph 5y ago
- jmclnx 5y agoThe image cannot be dispalied. I wish github only allowed Open Image Formats, but too late now since Microsoft owns them. Lately I have been running into image/video files people at work create on their MACs that cannot be viewed in Linux. I wonder if that crap is carrying ofer into github.
- enobrev 5y agoIn this case, it's not a matter of image formats, but simply a 404. https://github.com/norvig/pytudes/raw/5e745c392772d150b4146277e9061d44c1cc8d36/ipynb/map6.png https://github.com/norvig/pytudes/raw/5e745c392772d150b41462... Here's map4.png: https://github.com/norvig/pytudes/blob/main/ipynb/map4.png https://github.com/norvig/pytudes/blob/main/ipynb/map4.png There doesn't seem to be a 5 or 6.
- wodenokoto 5y agoI’m not sure I understand how the `border` variable works. Sets in Python are really cool when you can master them, but I do sometimes wonder if they are too clever, or just not evangelized enough.
- dec0dedab0de 5y agowhen you pipe a set it's the same thing as calling union on each one, it creates a new set and puts all the variables in them: so this: border = north | south | west | east is the same thing as: border = north.union(south, west, east) which is also: border = set() for border_set in [north, south, west, east]: for state in border_set: border.add(state) it's just a new set with all the previous items in it. Since it's a set there is no doubles. for example, WA is in north and east, but only in border once, because there is no duplicates in a set. to do it with lists you would need to make sure there was no doubles yourself. plus you wouldn't get the set operations later on, and would need similar loops to check things. border = [] for state in north + south + west + east: if state not in border: border.append(state) Sets are great any time you need to work with groups of unique things and see how they relate to each other. Since there is only one of each state, this is perfect use for them. edits throughout as I thought of other things.
- wodenokoto 5y agoI’ve never thought of that operation as shell pipes, but always as an “or” operator.
- dec0dedab0de 5y agoI just call the character a pipe, It's actually a "bitwise or". i think the reasoning is that it looks at each item in the two sets being compared and returns it if it is in either or both of the sets. Which functionally is the same thing as creating a union. I usually avoid using bitwise operators because they get confusing, and the kind of stuff my team does rarely needs them. In this case I would have used union. edit: here are some of the docs Bitwise operators: https://wiki.python.org/moin/BitwiseOperators https://wiki.python.org/moin/BitwiseOperators and how they work with sets: https://docs.python.org/3.10/tutorial/datastructures.html#sets https://docs.python.org/3.10/tutorial/datastructures.html#se... Plus the set docs have the methods with their corresponding operator: https://docs.python.org/3.10/library/stdtypes.html#set https://docs.python.org/3.10/library/stdtypes.html#set I can see how it would be nice and concise, but I think the methods are easier to understand.
- deleted 5y ago[deleted]
- charleskinbote 5y agoThis reminds me of balanced graph partitioning, where the graph is planar and its the nodes that have weights instead of the edges.
- d_burfoot 5y agoI was really hoping this was a political manifesto, not a programming puzzle
- karolsputo 5y agoMe too! I was surprised at the title, fully expecting Norvig to channel Michael Malice and talk about splitting the US.
- wwweston 5y agoThat kind of dramatic change usually only benefits people with nothing to lose or a distinct next-level gain to make. Norvig definitely isn't in the first category and has many better avenues for gains than an attempted split of the US (think about who does potentially benefit from that). Plus hackers love puzzles. So it's not surprising that politics isn't what it was about.
- deleted 5y ago[deleted]
- onychomys 5y agoThe accepted answer from 538 can be found here: https://fivethirtyeight.com/features/can-you-bowl-three-strikes/ https://fivethirtyeight.com/features/can-you-bowl-three-stri...
- biorach 5y agoI've read a lot of code. Peter Norvig's code operates at a different level to anything else I've ever read. And he's been doing this a long time. I've read part of the way through "Paradigms of Artificial Intelligence Programming" which is from 1991, and uses much the same approach as in the OP, but with Common Lisp.
- nl 5y agoHis code is beautiful and his explanations are so clear it makes me feel dumb for not seeing his solutions for myself. Obviously his approach is the right way. Except they usually aren't obvious until you've read the explanation. His 22 line spell checker[1] is a perfect example. [1] https://norvig.com/spell-correct.html https://norvig.com/spell-correct.html
- deleted 5y ago[deleted]
- archi42 5y agoOh, isn't this a variation of the Knapsack (or more precisely subset sum) problem? With the additional constraint of adjacency.