Thomas’ Tales: Walt Disney World, Day One

Note: Today’s post was written by my son, Thomas. He’s eleven and very excited that we are at Walt Disney World. I edited his post, but the text is his.

Hello. I, the blog famous Thomas, will be writing every day until Monday about our trip to the almost as famous as me, Disney World. Now to get started, we rode down here yesterday and unpacked, but that was twenty-four hours ago, so let’s just forget that. Today, we woke up early to see the Magic Kingdom opening show/song , and it was good. After that, we went to Tomorrowland, where we blasted aliens and moved people, and sent my parents into a mountain in space. Then we headed over to Adventureland, where we went to see the tiki birds and rode on boats. One boat ride being a simple tour of the wildlife and the back-side of water (which was amazing), on the other we went through a pirate-infested town that was currently on fire. I don’t know why it was on fire; maybe someone dropped a lantern or something.

Now for the interesting part. When we were on the People Mover,  I couldn’t believe what happened. As we were entering the part where it goes through Space Mountain, the ride came to a non-screeching halt. I don’t know why, but it took FOREVER to get it going again. Luckily, there were no more problems with our visit; so far, that is. Now we are in our room, relaxing.

That’s all, folks, but expect more from me tomorrow, and the next day, and the next day, and so forth.

WCBHM10 & Birmingham’s New Railroad Park

For the third year in a row, I attended WordCamp Birmingham. And for the third year in a row, it’s delivered on great content. My favorite session was one that I almost passed on; Sara Cannon‘s “Beyond the System Font: Advanced Web Typography” sounded like the same talk she delivered last year, but the technology has leaped forward in the past year, so the session was totally new. I will be implementing on this blog, very soon. Thanks, Sara.

Yesterday, we were meeting outside at Birmingham’s newest urban project called Railroad Park. It’s a very nice greenspace right in the middle of town, with spacious covered pavilions that we used for shelter from the really hot sun. I walked around the park before heading back to Georgia and took a bunch of photos, the best of which are below.

[ichc-flickr-slide width=”480″ height=”385″ username=”joeygibson” set_id=”72157624995821638″ player_r=”71649″]

99 Scala Problems #28 – I Like My Solution Better

I’ve been working through this list of 99 Scala Problems, which is modeled after this list of 99 Prolog Problems. As I’ve been going through them, I have been comparing my solutions to those provided (obviously). Sometimes, my solution is more or less the same as the “official” solution. Sometimes, theirs is better. In the case of problem 28, I think mine is far easier to read and understand.

Problem 28 has two parts. The first part reads:

a) We suppose that a list contains elements that are lists themselves. The objective is to sort the elements of the list according to their length. E.g. short lists first, longer lists later, or vice versa.

Running the function should look like this:

scala> lsort(List(List("a", "b", "c"), List("d", "e"), List("f", "g", "h"), List("d", "e"), List("i", "j", "k", "l"), List("m", "n"), List("o")))

res0: List[List[java.lang.String]] = List(List(o), List(d, e), List(d, e), List(m, n), List(a, b, c), List(f, g, h), List(i, j, k, l))

For this part, my solution was almost identical. Here’s what I came up with:

def lsort[T](ls: List[List[T]]) = {
ls.sortWith {(a, b) => a.length < b.length}

You can see that this function takes a List of type T, and then calls the sortWith method on that list, passing in a function value that sorts the lists based on their length, shortest to longest. The “official” solution was only slightly different:

def lsort[A](ls: List[List[A]]): List[List[A]] =
ls sort { _.length < _.length }

Here, they used A instead of T, but that doesn’t affect anything, and they specified the return type, while I left mine inferred. Instead of assigning each bucket of the list to a named variable, as I did, they use the underscore placeholder. The two functions are functionally (get it?) identical, but theirs is a bit shorter because they removed the outer braces, and were able to skip the parameter list, since they used the underscores.

Now, the second part is where I diverge from the official solution. Here’s the problem description:

b) Again, we suppose that a list contains elements that are lists themselves. But this time the objective is to sort the elements according to their length frequency; i.e. in the default, sorting is done ascendingly, lists with rare lengths are placed [first], others with a more frequent length come later.

And the expected call and result is

scala> lsortFreq(List(List("a", "b", "c"), List("d", "e"), List("f", "g", "h"), List("d", "e"), List("i", "j", "k", "l"), List("m", "n"), List("o")))

res1: List[List[java.lang.String]] = List(List(i, j, k, l), List(o), List(a, b, c), List(f, g, h), List(d, e), List(d, e), List(m, n))[/scala]

First, let’s look at what they presented as the solution. It referenced functions from other files, but I have included them all here for easy of viewing.

def lsortFreq[A](ls: List[List[A]]): List[List[A]] = {
val freqs = Map(encode(ls map { _.length } sort { _ < _ }) map { _.swap }:_*)
ls sort { (e1, e2) => freqs(e1.length) < freqs(e2.length) }

def encode[T](ls: List[T]): List[(Int, T)] = {
val packedList = pack(ls)
packedList map {list => (list.length, list.head)}

def pack[T](ls: List[T]): List[List[T]] = ls match {
case Nil => Nil
case h :: tail => (h :: tail.takeWhile(_ == h)) :: pack(tail.dropWhile(_ == h))

I think this is very confusing code. It’s calling the encode function which does run-length encoding of the passed-in thing. It then uses a Map of these encodings to sort the passed-in list. The presence of five underscores in the first line, obscures where those parameters are coming from, and the final underscore is actually part of the _* method of the Array class!

My solution, while being a longer function, is far more readable, in my opinion. And, it’s the same number of lines as the three-method solution. Here it is

def lsortFreq[T](ls: List[List[T]]) = {
val lengthMap = scala.collection.mutable.Map[Int, Int]()

for (l <- ls) {
val len = l.length
if (!lengthMap.contains(len)) {
lengthMap(len) = 1
} else {
lengthMap(len) += 1

ls sortWith {(a, b) => lengthMap(a.length) < lengthMap(b.length)}

In my function, I created a mutable Map and then iterate over the list, getting each item’s length, and then keep a running tally of how many items had that length. The map has these lengths as its keys, and the number of items with that length as its values. Get it? I then sort the original list by having each item in the comparison lookup how many items share its length, and use that as the sort criterion.

I have no idea which of these solutions is more efficient. For small problems like this, I doubt there’s any measurable difference. But I do believe that my solution is easier to read and understand. So much so, in fact, that I think someone who is not familiar with Scala would be able to easily figure out what it’s doing. I don’t know that the same can be said of the other solution.

I got criticized for promoting terse code in this article, so this is my attempt at balance. 🙂

Note: I did change the inputs to these functions from symbols to strings. The code formatter I use on the blog wasn’t colorizing things properly when there were symbols involved.

Two Videos From Lula Lake

As I said earlier today, my buddy Tim and I went hiking on Saturday and ended up spending much time at Lula Lake. You can see pictures from that excursion in the previous entry. (The first of the pictures are from Cloudland Canyon. The pics from Lula Lake begin with the rocks in the river that actually contained water.) Below are two videos of the beauty at Lula Lake. The first I took standing directly next to the cliff edge at the top of the falls. The second was taken from across the lake, looking at the falls and the surrounding cliff. If that place were on my property, I don’t think you could pry me away.

Hiking Cloudland Canyon and Lula Lake

[ichc-flickr-slide width=”500″ height=”375″ username=”joeygibson” set_id=”72157624892733526″ player_r=”71649″]

My buddy Tim and I went hiking this past Saturday. We went to Cloudland Canyon, which is up in North Georgia, near Chattanooga. We spent about 2.5 hours there, scaling the 600 step staircase, looking at the almost-completely-dry waterfalls and the nearly-devoid-of-water creeks and looking for the I-know-it’s-here-somewhere-dangit geocache, placed there by the GA parks service. We never found the cache, but vowed to return when there is water around, since one of the clues to finding it depended on there being water. Doesn’t everything?

After the hike there, which was beautiful and fun, don’t get me wrong, we inquired of Ranger Amy if there were any falls nearby that had, you know, some water in them. She told of us about one that wasn’t too far, but then she said, “Wait, maybe Lula Lake. It’s beautiful, but they aren’t open all the time. Let me call them for you.” A few minutes later, she told us that they were open, and we definitely needed to go. She gave us a map (which we quickly discovered was not to scale), drew “about where” it was on this map, and wished us good luck. We got back into my car, and headed out.

After about 45 minutes of “wast that the turn?” and “do you think we just missed it?” we finally found the proper turnings, and ultimately made it to the entrance. If you were not looking for it, you would have missed it. If you were looking for it, you still could have missed it, since there was nothing but hand-written paper signs, peeling and twisting with the sun and heat.

Anyway, we drove down the somewhat perilous (for a car) drive and found that we were not alone in our quest. There were probably 50 or more cars in the parking area. It’s free to be there, but they ask for donations, since it’s a private land trust. They gave us a map, told us the easiest way to get to the lake and falls and sent us on our way.

I should pause here to relate our Big Mistake™ for the day. Ranger Amy had told us that getting to the falls at Lula Lake was “easy” and would probably only take “ten or fifteen minutes.” Thus, as we got out of my car, we both decided to leave our water packs in the trunk. Please keep that in the back of your mind as you read on. Tim also decided to leave his trekking pole, but I took mine. Now, let’s continue.

We started out walking down the gravel road, but when hiking, “paved” roads sort of seem like cheating to me, so we took the first trail off the road we found, the “Ford Trail,” which began with fording a stream. It was easy, and nobody got wet. We then started following this trail, which essentially paralleled the river. It did not parallel the river in terms of altitude, going up and down, over and over. This trail ultimately rejoined the paved road at a bridge, just above the falls. We walked to the very precipice of the falls and looked over. Wow. What a view. We were standing at the edge of a cliff, about thirty feet above one of the most beautiful lakes I’ve ever seen. It had stunningly green water and was surrounded on one side by a bowl-shaped cliff. The water looked deep at the bottom of the falls, and it was just begging us to jump in. We did not.

We then got back to the paved road and walked a little farther so we could get to the lake proper. This place was gorgeous. I wanted to swim, but I didn’t have trunks, there were other people around and there were big signs saying swimmers would be prosecuted. All three conspired to keep me from swimming.

Farther down the paved road was the second falls. We were’t able to get very close to this one, but it was at least one hundred feed tall. There wasn’t a whole lot of water going over it, but the sound it make when hitting the bottom was impressive. I wish we could have gotten closer, but neither of us could see how we could. We did see some people at the very bottom of this falls, but the trail we found that went down was really steep, and neither of us wanted to have to come back up that way, so we took a pass.

A short way farther down the paved road, we came to the end of the property and a slightly trail-like spur off to the right. Tim checked the map and based on the topo lines, it looks like it would be pretty steep in places. We decided to double back a ways to the “somewhat more gentle” trail we had seen that would still get us to the top of the ridge, just “more gently.” But as we started to leave the spur behind, my curiosity got the best of me and I said, “You know, I’m probably going to regret this, but I sort of want to know what this trail is like.” (Or something close to that. The next hour is a bit fuzzy at times.) So we headed on to the slightly trail-like spur.

Within just a few minutes, the trail got steeper and I started huffing and puffing as my legs began to complain loudly to me about what I was asking them to do. I continued on, with Tim about ten feet or so ahead of me. At one point, I looked back to where we had come from and saw that we had already ascended quite a bit, and that I really didn’t want to try to go back down that way. The only way for us to go, realistically, was up. And so we continued.

Another twenty minutes or so later we came to the “So, You Think You’re A Man” stage of the ascent. I like to call this section the, “How the F@#k Am I Supposed To Get Up There‽” section of the trail. The land owners had generously hung sturdy ropes with knots in them to assist you in your climb (yes, climb, this was no longer a hike), and we used these ropes to good use. Tim made it up first, of course, and after I made it up the second of three ropes, I tossed him my pole, because it was a hindrance at this point. I pulled myself up the final rope, cursing and spitting all the way. Now, I should mention that the trail leading up to this had been getting more and more narrow, with drops of twenty to thirty feet should you misstep. And this bit with the ropes was just crazy. My point is that we were facing a bit of actual danger, and I don’t know that either of us realized it until we were mostly through it.

Once past the ropes, we assumed that we were at the top, and there wouldn’t be any more vertical to worry about. We were wrong, but it wasn’t horrible. I was still thankful when we finally did make it to the top, and the trail got nice and flat. Up on top, there was a field, and some pik-nik tables. We spoke with some nice folks who had taken the sensible route up, and warned some others who were heading in the direction from which we came about the steepness of what they were heading toward. They all seemed grateful. The views of the valley below from way up here were lovely, and I took several photos.

But what I really, really, wanted was some water. Of course, since we were both dumb-asses, we had left it in the car. Remember the Big Mistake™? So I debated on whether or not it would be considered gauche to ask some other hiker for a sip of the water that they so smartly brought with them. I didn’t ask the nice couple up top, nor did I ask the next two or three people we saw. But finally, I saw a guy with a huge bottle of water that was clearly frozen in the middle. That meant ice cold water, which would feel so good. We greeted him, and then I said something like, “Excuse me um you see we didn’t think we were going to be out here so long and so we left our water in the car and I hate to ask and everything but if you could would you mind terribly much if I could have just a small swig of your water please?” He smiled and handed me the bottle. I wanted to wrap my lips around the bottle and drain every non-frozen drop (like Homer when Moe told him the beer taps had run dry), but I restrained myself and just poured a bit into the palm of my left hand. As I expected this water was the absolute best water I had ever tasted. It was cold and refreshing, and just that small amount was enough to revive me. And to keep my lips from sticking to my teeth, which had been impairing conversation.

We walked about a mile on the top of the ridge, and then started our descent. This was not terribly steep, but after a while, my legs began complaining again. I just ignored them. We were heading back down and that’s all that mattered. We finally made it back to the parking area, and went to task the people in the tent about the lake. It’s a natural lake, which is why the water doesn’t look like chocolate milk as most Georgia lakes do, and is around thirty to forty feet deep. In case you were wondering. He also said the dark discoloration on the rock was from where they used to wash coal there, since the whole area used to be a coal mine.

We ended up spending about 3.5 hours at Lula Lake, longer than we spent at Cloudland Canyon, and we had water then!

So, to sum up. Cloudland Canyon is beautiful, but it really needs moving water. Ranger Amy said March is quite nice. Lula Lake is sublimely beautiful and I would recommend it to anyone who likes to look at natural beauty. If you stay on the paved road, it really would be about a fifteen minute walk from the parking area.

And remember this: if you have a water bottle/water pack, take it with you, even if you think you’re only going to be there for a short while. You will thank me for this later. Trust me.