comment 0

To the left? Now Slide!

Welcome to the Island of Knights, Knaves, and Sir Mix-a-lot! There are a few things you should know about this island:

  • Knights always tell the truth
  • Knaves always lie
  • There is exactly one Knight named “Sir Mix-a-lot”. Like every other knight, he cannot lie.
  • This island is one of a chain of islands containing knights and knaves, each one having its own quirk.

Today we are on the basic island of Knights and Knaves. We are driving along, trying to find the way back to our hotel when we come to a fork in the road. There is a resident of the island standing alongside the road, so I get out out to ask him for directions. I ask one question before returning to the car, to which the resident nods “Yes.” Upon returning to the car, I say, “We have to go left at this fork in the road to get back to our hotel.” You ask, “Did he tell you that? Do you even know if he is a knight or a knave?” I respond, “I have no idea if he is a knight or a knave, but I do know we need to go left.” What did I ask him?

 

 

Solution:

If I had just asked, “Is the hotel to the left?” I would have no way of knowing if his answer was the truth or not. The resident could have been lying and I would have no way of knowing. Instead, I asked, “Are you the type of person who could claim that the hotel is to the left?” Assuming that the hotel is actually to the left, a knight would answer “Yes.” Surprisingly, a knave would also answer “Yes.” If asked directly if the hotel were to the left, he would lie and say “No,” but since he is a knave, he will also lie about lying.

Perhaps it would be easier to think about it another way. What would a knave say to, “Are you the type of person who could claim 2 + 2 = 4?” That question could be changed to “Are you the type of person who tells the truth?” Even more simply, you could ask, “Are you a knight?” A knave would certainly say yes to all of those questions.

Conversely, a “No” answer would have meant the hotel was to the right, no matter what.

comment 0

The Leader

By default the leader key in vim is  \ . (For more on the leader key and mapping in general, see this.) You’ll find that many people remap the leader key to something easier to reach. A common choice is to use the comma as the leader.

But wait! The comma already has a use in normal mode, and it’s a key I actually use now and again. After searching high and low for a new leader key, I finally settled on the spacebar. I thought it was worthy of a blog post because it was more difficult to set up than most other choices would be.

The following two lines in my vimrc are responsible for mapping my leader key to the spacebar:

So there it is. Next time you’re feeling unproductive, remember that it took me an hour or so to figure this out.

comment 0

Pattern Recognition

I’m not sure if I’m getting better at pattern recognition in this area or if this is actually a relatively simple pattern to figure out, but I thought the pattern embedded in the following set of integers was fun to discover:

I found this set on page 73 of Gödel, Escher, Bach: an Eternal Golden Braid. If it hadn’t been presented in the context of positive and negative space, I think it would have taken me much longer to figure it out.

comment 0

Guilty or Not?

Welcome to the Island of Knights, Knaves, and Sir Mix-a-lot! There are a few things you should know about this island:

  • Knights always tell the truth
  • Knaves always lie
  • There is exactly one Knight named “Sir Mix-a-lot”. Like every other knight, he cannot lie.
  • This island is one of a chain of islands containing knights and knaves, each one having its own quirk.

Today we are in a police station on the regular Island of Knights and Knaves. A detective friend of yours brought a resident of the island in for questioning, and suspects him of committing a crime. Before the questioning could begin, the suspect said one sentence to the detective. The detective immediately said he was free to go. You walk up to the detective and he says, “Well, I don’t know if he is a knight or a knave, but I do know he is innocent!” What did the suspect say to the detective?

 

 

Solution:

One possibility is “A knave committed this crime.” If this sentence is true, the suspect is a knight and could not have committed the crime. If the sentence is false, then the suspect is a knave and once again could not have committed the crime, because if he did, our false statement would also be a true statement, and we would have a contradiction.

comment 0

The Little Schemer

I finished reading and working through The Little Schemer a few days ago. I’m still recovering from having my mind blown again and again.

It presented several programming concepts that were relatively new to me in a very unique format. I can see why some people would dislike it, but I thought it was wonderful. If I have one critique it would be that the last three chapters were significantly more challenging than the first seven. I probably spent twice as long on those chapters as I did on the rest of the book.

All the information required to succeed is present, however. The book is completely self contained. Several times I looked to sources outside of the book to better understand the concepts it was trying to teach, only to discover later on that the information I was looking for was in the book the entire time.

I give this book this many stars:

 

comment 0

Awake or Asleep? Knight or Knave?

Welcome to the Island of Knights, Knaves, and Sir Mix-a-lot! There are a few things you should know about this island:

  • Knights always tell the truth
  • Knaves always lie
  • There is exactly one Knight named “Sir Mix-a-lot”. Like every other knight, he cannot lie.

Today, we are on the island of sleepwalking knights and knaves. At night, half of the population sleepwalks around the island. When a resident sleepwalks, they are living in a dream world where everything is the opposite of reality. In other words, every belief held by a sleepwalking resident will be wrong. For example, if you ask an awake knight if he is a knight, he will say “yes”. If you ask a sleepwalking knight if he is a knight, he will say “no”! He is sleepwalking, so he believes he is a knave. Since he is actually a knight, he answers all questions truthfully, so he will tell you that he is actually a knave!

It’s nighttime on the island, and you come across a resident who says, “I am not an awake knight.” What is she?

 

 

Solution

First, our resident can’t be an awake knight, because it would be impossible for an awake knight to claim such a thing. A sleepwalking knight would believe himself to be awake, and would truthfully tell you so, so a sleepwalking knight can’t claim such a thing, either. An awake knave correctly believes he is what he is, but he will lie to you about that. To make the claim our resident is making would be a true statement for a knave to make, so this is impossible for an awake knave to make as well. This leaves only one possibility, so our resident is a sleepwalking knave. Can you figure out why a sleepwalking knave can make such a claim, but no other type of resident can?

comment 0

Netrw

Although it can seem like it’s a part of vim itself, netrw is actually a plugin that’s activated every time you use the  :e  command. There is extensive help to be found with  :help netrw , including a large list of ways you can customize it. I have the following two lines in my .vimrc:

The first line removes the large text banner that appears by default at the top of every netwr buffer. The second increases the amount of information listed about each file in a netrw buffer, showing the date last modified and the file size. The netrw help file is a few thousand lines long, and these two options barely scratch the surface of what’s available.

comment 0

Knight or Knave or Sleepwalker?

Welcome to the Island of Knights, Knaves, and Sir Mix-a-lot! There are a few things you should know about this island:

  • Knights always tell the truth
  • Knaves always lie
  • There is exactly one Knight named “Sir Mix-a-lot”. Like every other knight, he cannot lie.

Today, we are on the island of sleepwalking knights and knaves. At night, half of the population sleepwalks around the island. When a resident sleepwalks, they are living in a dream world where everything is the opposite of reality. In other words, every belief held by a sleepwalking resident will be wrong. For example, if you ask an awake knight if he is a knight, he will say “yes”. If you ask a sleepwalking knight if he is a knight, he will say “no”! He is sleepwalking, so he believes he is a knave. Since he is actually a knight, he answers all questions truthfully, so he will tell you that he is actually a knave!

Let’s say you run into a resident of this island during the night. Last time, you wanted to know if someone was a knight or a knave. Now you want to know if this other resident is sleepwalking or not. Can you figure it out in one question?

 

 

Solution

One possibility is “Are you a knight?” An awake knight will tell the truth and say “yes.” An awake knave will lie and also say “yes.” Easy enough so far, and we now know that no awake resident can say “no.” But what do sleepwalkers say?

A sleepwalking knight will believe himself to be a knave. When asked if he is a knight, he will tell you the truth about that belief and say “no.” A sleepwalking knave will believe himself to be a knight. He will then lie to you about that belief and will also say “no.” So a “yes” answer means that person is awake, and a “no” answer means that person is sleepwalking. We don’t know if we are talking to a knight or a knave, but we do know if that person is sleepwalking or not.

comment 0

Functions from Functions

I’ve been going through The Little Schemer recently. Many of the concepts in the book are simple and yet mind-blowing at the same time. One idea that I found particularly enlightening is that of functions returning other functions.

Here’s an example from page 127:

Lo and behold, a function that returns a function. What function does it return? Let’s use it and find out. The outer lambda is a function that takes a single argument, so let’s give it one.

This returns a function that takes a single argument. This returned function will test its argument to see if it is equal to ‘salad or not. Essentially, it returns the function:

So, how is this helpful? This example is not particularly useful in a practical sense, but it introduces the idea of functions returning functions, and sets up the introduction to the idea of passing functions to other functions as arguments. It’s at this point the book increases its rate of MBPP* significantly.

* mind blowings per page