Serpent's Tooth

Book Notes

Walt Longmire, Book 9

Okay, I was somewhat excited to be reading a Walt Longmire book that didn't start off with some murder investigation. I mean, there are only so many deaths you can have in a small county before everyone, and I mean EVERYONE, notices and gets the fuck out of there. Okay, yes, some of the books were about escaped convicts, but even that resulted in a lot of death. And one particular story had only a stolen horse.

This one, the main plot premise doesn't involve the investigation into a death. Hot damn.

Once again, Johnson doesn't disappoint with a fast paced modern day, small down, western mystery. The clues were a little too obvious in this book as to what was going on, which, of course, leads the reader to think, COME ON, DON'T BE DUMB, at the characters. Of course, in Johnson style, Longmire has figured out what's going on, and it just playing along until the right time to expose his knowledge.

I really wish I would learn the art of playing along.

I enjoyed this book. I'm nearing the end of the written Longmire books, as there are only two left. I guess I'll have to wait for Johnson to write more. At least he doesn't write at GRRM pace. Gah, would suck.

You have two stacks, implement a queue.

Blog

Here's a favorite programming question for interviews that even those long out of college can do. Delightfully, one I hadn't been asked recently, except by Kris and Andy.

You have two stacks, implement a queue.

In programming, a stack is a first-in-last-out data structure with two functions: push and pop. You can push a piece of data to add it to the top of the stack, on top of all of the other pieces of data already on the stick, and you can pop the most-recently-added piece of data off the top of the stack to remove it from the stack and return its value to you.

A queue is a first-in-first-out data structure with two functions: enqueue and dequeue. You can enqueue a piece of data to add it to the end of the stack (whichever end you have declared to be the back), behind all the other pieces of data already in the queue; and you can dequeue the oldest piece of data from the opposite end of the queue, which is the front of the queue, and return its value to you.

With that all said, given two stacks, implement a queue.

If you're not reading this from the feed, it should display in black, and you should be able to mouse over or select the text for my hand-wavy notes.

Right, the answer.

The solution is "push on first, pull on second."

If the second stack is empty, you can't dequeue, so you take the value from the first queue, pop it. push on the second, and then pop from the second.

Essentially, you move items between the two stacks, popping from the first and pushing onto the second, to get to the last one on the first, then dequeue.

The worst case scenario is when you have to enqueue, dequeue, enqueue, dequeue, because that means moving all the items from one stack, then to the other stack, then back to the first stack then back the other stack, to add items to the bottom of the first stack, then the bottom of the second stack.

Follow up questions include, "What's the worst case scenario in data retrieval with the two-stacks-as-a-queue?" and "How would you do a runtime analysis of your implementation?"

Other exercises I've had recently are, "In a distributed system, implement put-if-absent." and "Implement a serialize function for an object with an integer and a string." The later includes follow ups on how do you determine the function's efficiency, and how does it change with 16 bit, 32 bit, and 64 bit systems?

A Twelve Year Old's Incorrect Correction

Blog

"Shit."

"You mean, 'Shoot.'"

"No, I mean, "Shit.'"

Ages of Miracles

Book Notes

One of the best things about my Mom's houses growing up was the bookcases full of books. I would often linger at the bookcases, pull out a book, and read it. It's how I like to read books: engrossed when I feel like this is the book I should be reading. It's how I picked Voltaire's Candide to read. It's how I picked this book to read.

Mom had suggested the book when we were in Portland last month. It was on sale. I bought it, and plunked it on my bookcase in the "haven't read, read at some point" stack of books. I picked it up late last week, and read it fairly quickly. I enjoyed it.

The book is a young adult book about an 11-turned-12 year old girl's life in the first months of the Earth's rotation slowing from 24 hours in a day to 72 hours in a day, and how the world changes to adapt, or not adapt as the case is with some people and places. Much of the gross (as in "total" not as in "disgusting") science is accurate enough to my understanding: the changing of the magnetic fields, the change of the radiation reaching the planet surface, the dying of many plants unable to adapt so quickly to the longer, hotter days and longer, colder nights. Many of the speculated societal changes presented were plausible.

Both of these, the sufficiently accurate science and the plausibly accurate changes in society, meant I wasn't distracted by the wrongness of the story background (I didn't have to suspend disbelief other than the initial "the Earth's rotation suddenly slowed"), and was therefore able to enjoy the storyline of the life of an eleven year old girl, told from look-back of a 23 year old woman.

It was a well-told story. I enjoyed the book. A fast, engrossing read.

For anyone else, I'd say, send the author ten bucks and borrow the book from the library. Or from me.

Celebrating the Partial Successes

Blog

This was originally posted on The Pastry Box.


"I had two today."

My roommate had decided to quit smoking. Down from a pack a day, she had had only two cigarettes, and seemed to be down on herself.

"That's 18 you didn't have! That's great!"

"I guess."


"Down four pounds."

My coworker was losing weight. Having been trying for only a week, he was down four pounds, and seemed disappointed in himself for not having lost the five he had set as his goal.

"Four pounds! That's great! That's four pounds closer to your goal weight!"

"I suppose."


"We launched today. We only had two sales."

My friend had launched the site he had been building for a couple months. He had gone lean and gone all in, working on his site obsessively. He wasn't very excited.

"Whoo! You launched! You had sales! Let's celebrate!"

"I'm not sure."


"Life is a journey, not a destination," We've all heard that quote from Emerson. I'm usually guilty of thinking, "Yes, yes, of course, that's right, I know that. Journey," and keep moving on with what I'm doing at the time.

Yet, how many times do we pause on that journey and look around, see how far we have come along that path? How many times do we celebrate the small successes along the way to accomplishing the big goal?

How many times do we see that while we may not have managed the goal, the journey was still worth taking? Worse, how many times do we move that goal farther away from us?

Small victories are worth celebrating.

Rising out of bed and starting a day is worthy of celebrating with a stretch, a smile, and an acknowledgement that, hey, I woke up!

Going for a run, a ride, a class, feeling the movement and learning what your body can do is worthy of celebrating.

That small exercise of will-power, not buying something you don't need, is worthy of celebrating.

Practicing a new skill, even if the result is not what you'd like, is worthy of celebrating. I'd argue especially if the result isn't what you'd like, it's worth celebrating.

Failure is a part of all of this. Maybe celebrating the partial successes can also be.

Pages