Saturday, March 20, 2010

Where the Wild Things Are

We read the book to the kids years ago, and last night rented the DVD from Blockbuster®. The two stories are quite different, and each very good. The book is a children's book, but I wouldn't call the film a children's film. I mean, it's not The Book of the Dun Cow, which I consider rather creepy for the pre-teen set, but as Wikipedia® reports, the film has a PG rating in the US. It is a little intense.

But I think the film a great conversation-starter. Why are the creatures so unhappy? What could KW or Claire or Carol or Max do to make the situation better? What are the limits of parental or civic/governmental power, and what must each person do for him/herself? And what do you suppose God would say about the problems shown here?

Friday, March 19, 2010

Last kakuro posting for a while, I promise

    A     B     C     D     E     F     G  
0        
 
⇓10
 
⇓17
 
1    
12⇒
⇓3
1 2 9  
2
3⇒
 
2 1
9⇒
⇓10
1 8  
3  
6⇒
 
2 1 3
 
⇓17
 
4    
15⇒
⇓3
2 4 9  
5  
5⇒
 
2 3
9⇒
 
8 1
6  
7⇒
 
1 4 2    
Couldn't resist the temptation so the solver now outputs HTML like what you see on the left. It's still not pythonic and not even really OO, but it works so far. I am probably never going to perfect it.

A few more pictures, and sources are here: http://cpark.users.sonic.net/kakuro-python/

Lord, Save Us From Your Followers

The teen-ager and I saw the film today. We were a little worried that maybe it was going to be a guilt-fest. It wasn't really, though it was easy to feel overwhelmed.

It reminded me a little of "They Like Jesus But Not the Church." The part of the film I'll probably remember the most was the "Culture Wars" game show, wherein some representative evangelicals competed with some representatives of the "liberal media elite"; the emcee asked questions like "what are some important things Christians say Jesus did" or "what are some common reasons a woman would want to have an abortion." Turns out that the liberal media folks beat the pants off the conservative evangelicals. I actually find this easy to believe.

The exciting thing about all this, though, was what happened after the game-show part was taped. The "contestants" sat around in a back room talking to each other for an hour or two, just talking. After that time, they had a sense that those people are actually pretty nice and enjoyable to talk with -- even though we think completely differently about some pretty fundamental things. I find this really easy to believe, too. Some of my best friends are liberal atheists. We disagree on some pretty fundamental things, but we also agree on a lot of things.

The other thing from the film I'll probably remember for a long time is the importance of service. The outpouring of aid from churches after Katrina/Rita, and helping the homeless in Portland, Oregon, were demonstrations to those outside that the church can actually be some earthly good.

We walked out of the theater and down the street, past a homeless woman. We got about about 3 yards past her and we both stopped and looked at each other. "Want something to eat?" we asked. "Are you allergic to anything?" Only onions, she said. We asked for two bagels, toasted, with cream cheese (Sheri noticed another homeless person -- lucky for him, since I didn't see him at all). Bottled water. A little cracker with chocolate over it.

We handed "Steve" (not the name he told us) one kit, introduced ourselves, and learned his name. He didn't seem to want to talk much. We then found "Sally" and did the same. She told us her name and a little about herself. Laid off after some seasonal work expired. Her children are with their father currently. We listened and wished her well.

The film changed me for a little while, anyway. I hope it sticks.

Thursday, March 18, 2010

It's not Pythonic, but it works (so far)

The code described below doesn't handle very hard puzzle #345943 by Vegard Hanssen; see this later post for an update.
– 2010-03-21
Following up on my earlier post on Python and kakuro, I did a few more things and it now solves every puzzle I've tried on it. I'll explain using this fragment of the earlier puzzle:
      A     B     C     D     E     F    
   +-----+-----+-----+-----+-----+-----+... 
  0|XXXXX|XXXXX|XXXXX|17\  |15\  |XXXXX| 
   +-----+-----+-----+-----+-----+-----+ 
  1|XXXXX|XXXXX|  \10| ___ | ___ |XXXXX| 
   +-----+-----+-----+-----+-----+-----+ 
  2|XXXXX|XXXXX|  \15| ___ | ___ |18\... 
   +-----+-----+-----+-----+-----+-----+-----+ ... 
  3|XXXXX| 9\  |16\  |  \11| ___ | ___ | ___ | ... 
   +-----+-----+-----+-----+-----+-----+-----+
                           | ... | ... | ... |
The earlier version did this:
  1. For each blank cell, create a list of possible values. This is initially [1,2,3,4,5,6,7,8,9].
  2. Given the number of cells that must add up to a given total (e.g., 1D+1E=10 because of 1C across), figure out all possible combinations of values (e.g., 1+9, 2+8, 3+7, 4+6; can't do 5+5 because that would repeat). Remove from the cells any possible value that isn't in this list of combinations (so that 1D and 1E would have at most [1,2,3,4,6,7,8,9]).

    Do this for all totals. (In the above example, 1D+2D=17 because of 0D, hence 1D and 2D can be at most [8,9]. Similarly, 1E can be at most [1,2,8,9]. More on this below.)

  3. If the number of possible values becomes 1 for any cell, then that cell's value is decided. No other cell that's part of the same total (whether an across total or a down total) can have that value, so eliminate that value from the list-of-possibles for those cells. This may cause another cell's list-of-possibles to have only one value, so this other cell is now decided, and so on. Repeat until no more cells are getting decided.
  4. Another way a call's value can be decided is this: Suppose that all combinations require a certain value (if you have to produce 22 in 3 cells, for example, this can be 9+8+5 or 9+7+6; in any case you need a 9), and suppose only one of your cells could possibly have that value (because of other decided cells/combinations), then that cell must have that value, so it's also decided. Repeat the loop of step#3 until cells stop getting decided.
  5. For all totals, eliminate any combination that's impossible by virtue of step #2 (for example, the combinations possible for 1C are now reduced to 1+9 and 2+8, since 3+7 and 4+6 require values that 1D cannot have)
  6. Repeat #2-#5 until they don't modify anything in the puzzle
That got me to the result shown earlier, with 41 cells left undecided. Here's what I added since that earlier posting:
  • Handle 2x2 boxes with a tail on them. (The "box technique" is described concisely in the Wikipedia article.) In the above example, 1C says 1D+1E=10, and 2C says 2D+2E=15. Hence 1D+2D+1E+2E=25. Similarly 0D and 0E dictate that 1D+2D+1E+2E+3E=17+15=32; combining we see that 3E=7. This is another way a cell's value can be decided. Repeat the loop of step#3 above until no more cells are decided. This filled in a dozen cells, leaving 29 undecided.
  • Make steps #2,#5 more effective by using ordered lists of numbers rather than unordered lists. In the example of step#2, we determined that 1E has possible values [1,2,8,9]; this is because 1C's list of possible combinations was reduced to 1+9 or 2+8; that code didn't take cell ordering into account. Yes, I know it was dumb, but I code the easy cases first! If we keep track of permutations (ordered lists) of possible cell values rather than merely combinations, the program will know that 1E can't be 8 or 9; it can only be 1 or 2, since 1D can be 9 or 8. With this logic added, the program solves all kakuro puzzles I tried, including today's from the Examiner.

    It seems like we have a sort of belt-and-suspenders thing going here; the "box" logic described in the previous bullet might overlap with what step#4 does, and the step of using permutations rather than combinations might have been adequate by itself. But I'm not sure and I'm not motivitated to work more on it now.

    Why not just start with the permutations in the first place? Well, if you have 9 cells (45 in nine), then how many permutations is that? Right, 9!=362880. Well, that's possible on most well-equipped modern computers, but it seemed rather much to me.

That sure was fun! I've put my code, and a few examples, on http://cpark.users.sonic.net/kakuro-python/ for your viewing pleasure.

Sunday, March 14, 2010

Python and kakuro

I don't know when these started appearing in the Examinator, but the lovely Carol has started doing kakuro puzzles. In case you haven't been bitten by the bug yet, the idea is... ah, best you read it yourself on the link above.

Now I thought it would be more interesting to write a solver than to actually do the puzzles, so I gave it a shot, thinking it would be no harder than writing a sudoku solver. You probably guessed it -- I was wrong. Well, at least it's harder for me. If I had started with an easier example I might be feeling cocky right now, but instead I started with this one... which my solver (so far) has left a bunch of blanks in:

      A     B     C     D     E     F     G     H     I     J     K     L     M     N  
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  0|XXXXX|XXXXX|XXXXX|17\  |15\  |XXXXX|XXXXX| 5\  |17\  |XXXXX| 9\  | 8\  |XXXXX|XXXXX|
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  1|XXXXX|XXXXX|  \10| ___ | ___ |XXXXX|15\11| ___ | ___ |  \14|  8  |  6  |12\  |XXXXX|
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  2|XXXXX|XXXXX|  \15| ___ | ___ |18\14| ___ | ___ | ___ |  \ 6|  1  |  2  |  3  |10\  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  3|XXXXX| 9\  |16\  |  \11| ___ | ___ | ___ |XXXXX|XXXXX|XXXXX| 6\  |14\ 4|  1  |  3  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  4|  \10| ___ | ___ |15\  |  \ 9| ___ | ___ |27\  |XXXXX|16\29|  5  |  9  |  8  |  7  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  5|  \11| ___ | ___ | ___ | 9\18| ___ | ___ | ___ |10\ 8|  2  |  1  |  5  |15\  | 4\  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  6|XXXXX|10\17| ___ | ___ | ___ | 6\  | 8\11| ___ | ___ | ___ | 9\  |  \ 5|  4  |  1  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  7|  \12| ___ | ___ |  \36| ___ | ___ | ___ | ___ | ___ | ___ |  2  |11\ 4|  1  |  3  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  8|  \ 8| ___ | ___ |16\  |15\10| ___ | ___ | ___ |13\  | 6\21|  7  |  9  |  5  |17\  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  9|XXXXX|16\  |17\18|  9  |  7  |  2  |  \18|  8  |  7  |  3  |  \13|  2  |  3  |  8  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 10|  \30|  9  |  6  |  7  |  8  |XXXXX|XXXXX|  \ 4|  3  |  1  |22\  |  \11|  2  |  9  |
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 11|  \ 9|  7  |  2  |15\  | 8\  |XXXXX|17\  | 4\ 9|  1  |  2  |  6  | 9\  |XXXXX|XXXXX|
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 12|XXXXX|  \24|  9  |  8  |  7  |  \12|  9  |  1  |  2  |  \ 8|  7  |  1  |XXXXX|XXXXX|
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 13|XXXXX|XXXXX|  \ 8|  7  |  1  |  \11|  8  |  3  |XXXXX|  \17|  9  |  8  |XXXXX|XXXXX|
   +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

Basically what my solver does is calculate all possible combinations of cells that can add up to the prescribed totals. This gives an easy start -- if you look in the lower right-hand corner you see that cells 13K and 13L must add up to 17. The only legal way for this to happen is for 13K to be 9 and 13L to be 8. The reverse might be possible except that because of cell 11L, we see that 12L+13L must add up to 9. If 13L were 9, then 12L would have to be zero, which isn't allowed.

That simple strategy didn't get me all that far; I then went to the rather sophisticated (I thought) step of saying, "If all combinations adding up to the prescribed total require that at least one '5' be present, and only one cell could possibly be '5', then that cell must be '5'." This allowed me to decide that 8M=5.

But beyond that, you see there are still a bunch of blanks in the puzzle above. I have an idea for a next step, but I'm not sure that'll be enough. Well, that's enough fun for today; time for sleep.

Ahhh, too wide

I'll have to hack the output to be html rather than fixed-width font. Later.

Jesus is God, and you are not. Neither am I for that matter.

In yet another great sermon, our pastor asked us a lot of rhetorical questions. If the world is the Lord’s, then whose is it not? Well, it's not ours, that's not whose it's not.

So when the Bible says we were created to rule over creation, this doesn't mean it's ours; it means we're to be regents, or stewards. We're supposed to take care of it, because it's his, not ours. (This is where I'm tempted to pick a fight with atheistic relativistic environmentalists: if the world doesn't belong to God, if man is "just" another part of nature, then what objection is there to the idea of just having most powerful exploit our planet for whatever reason they want? In the wild it's survival of the fittest, right? But that's a fight for another day.)

Today's objection is to the Mormons and the “Jehovah’s Witnesses” -- both of whom have a view of Jesus Christ contradictory to what the Scriptures teach us. I'll sum up the orthodox (note the lowercase "o") view:

Jesus is God, and we are not.
If I think Jesus isn't God, I make one kind of error; if I think that I am God (or could become God), I make another.

Rather a simplistic way to summarize the Christian faith I know, but really what I'm trying to do here is simply show how it differs from two major cults. So rather than talking about what the cults say, let's focus on what the Bible does say about Jesus. Here are a few points for consideration.

  1. Jesus is the creator: Colossians 1:16 says that "all things were created by him and for him." John 1:3 says so too: "Through him all things were made; without him nothing was made that has been made."
  2. John 1 has a lot to say about this: In the beginning was the word, and the word was with God and the word was God. We know this is talking about Jesus because in John 1:14 it says that the word became flesh, and his name, the name of Jesus Christ, appears in John 1:17.
  3. Jesus never ever sinned, as Hebrews 4:15 (and many other passages) say. This is why he was able to pay for the sin of the whole world (1 John 2:1-2).
  4. As Jesus himself said, "Worship the Lord your God and serve him only" (Matthew 4:10) Yet the Magi worshiped him (Matthew 2:10); the disciples worshiped him (Matthew 14:33); the women who saw him after the resurrection worshiped him (Matthew 28:9) -- and that's just in Matthew's gospel! There are lots more cases where Jesus doesn't reject worship. (Note that Paul and Barnabas rejected worship in Acts 14:10-18.)
  5. Thomas correctly recognized Jesus as God (John 20:28) and Jesus didn't contradict him.
So the Holy Bible teaches us that Jesus is extraordinary and in fact that he is God, and that we are not! Christ does call us brothers (Hebrews 2:11-12) as he called his disciples brothers (John 20:17). Yet although the Bible says "we will be like him" (1 John 3:2) this doesn't mean we're going to be God; it means that we will be purified (1 John 3:3).

If therefore someone tells you that Jesus used to be sinful like we are, or that we can someday become God like he is, you can be sure that they don't have a firm grasp on the truth as taught in the Bible. Likewise if someone tells you that Jesus isn't eternal -- e.g., that he's just very old.

Sunday, March 07, 2010

Firefox won't start!

So I'm running Ubuntu 9.04 32-bit on this AMD Athlon(tm) 64 Processor 3000+ box my buddy Kipp gave me. Yesterday I booted it to get the flight status of the lovely Carol's return home. Clicked on the little firefox icon and saw the "Starting Firefox..." label pop up on the "dock" at the bottom of the screen. Then it went away. Huh??

Opened a terminal window and said "ps x|grep fire" -- nothing. I looked in $HOME/.mozilla/firefox/*default for a lock file -- I think it was .parentlock but removing that didn't do me any good.

That's weird, I thought. Tried "mv .mozilla .mozilla-old" to see if something else in there might have been causing a problem. Nope -- the firefox rectangle appeared and disappeared, and there was a brand new "$HOME/.mozilla" directory there, but still no browser!

Next: did the System→Administration→Synaptic Package Manager thing, marking firefox for reinstallation. No effect. Deleted it, then installed again. Ditto.

Well, that was rather annoying! Typically I'd use a web browser to download a tarball and then unpack it, but since my browser (i.e., firefox) was itself toast... clearly I had a chicken-and-egg (or a bootstrap problem if you like): I didn't have a functioning browser, so I needed a browser to download a browser. The package manager didn't know about opera (and maybe it's not free anymore anyway?).

Fortunately, there is a non-graphical browser that worked fine; lynx. I typed "lynx http://www.firefox.com" and my shell told me I needed to install it. No problem; once it was there I just did what came naturally: accepted all cookies, and it directed me to www.mozilla.com/firefox or something. I selected the 9.8MB Linux download at the bottom of the web page (not just the bottom of my screen; had to use the arrow keys to get there). After a short while I had the file; where should it be saved? $HOME/firefox-3.6.tar.bz2 was fine.

Probably wget would have worked too, but since I'm a dinosaur I thought first of lynx.

Now to install; I became root and said "mkdir /opt/firefox-3.6; chown collin /opt/firefox-3.6" then became myself again. "cd /opt/firefox-3.6; tar -xjf $HOME/firefox-3.6.tar.bz2" did the job.

Whew! Firefox is back. Why did the old one (a 3.0 version) go bad in the first place? No idea. But I'm up and not sufficiently curious....