The Inferno



The Inferno :: It is a fallacy to state that something exists just because it can’t be proven that it doesn’t
Archive for May, 2009
5/29/09
11:08 am
Combinations and Permutations

Recently, a lot of people have expressed interest in generating all combinations and permutations of various objects. While this is a topic covered in second-year Computer Science courses, it seems a fair number of people have no idea how to go about generating them. In this post, I’ll provide code on how to go about doing this in an imperative language (Java). Doing it in a functional language like Haskell is much shorter, only 2 lines or so, but this version is imperative. Also, I’ve used strings, but feel free to modify it to any sort of container.

For generating combinations of length k, briefly:

  • Extract the first element from the list
  • Prepend it to all combinations of length k-1 from the leftover list
  • Calculate all combinations of length k-1 from the leftover list.

For generating permutations of length k, briefly:

  • Iterate over the list
  • Remove one element at a time from the list
  • Prepend the removed element to all permutations of length k-1 from the leftover list.

It’s really that simple, handle the base cases and you’re all set. Do a couple of examples on paper if you still don’t get it. Also, modifying the permutations code to generate all permuations with repetitions should be fairly simple too. Give it a shot.

Run my code to generate all combinations of my name:

        Combinations c = new Combinations();
        ArrayList<String> result = new ArrayList<String>();
        String test = "viren";
        for(int i = 1; i <= test.length(); i++){
            result.clear();
            result = c.getCombos(test,i);
            System.out.println(result);           
        }

This results in:

[v, i, r, e, n]
[vi, vr, ve, vn, ir, ie, in, re, rn, en]
[vir, vie, vin, vre, vrn, ven, ire, irn, ien, ren]
[vire, virn, vien, vren, iren]
[viren]

And similarly, the permutations code results in:

[v, i, r, e, n]

[vi, vr, ve, vn, iv, ir, ie, in, rv, ri, re, rn, ev, ei, er, en, nv, ni, nr, ne]

[vir, vie, vin, vri, vre, vrn, vei, ver, ven, vni, vnr, vne, ivr, ive, ivn, irv, ire, irn, iev, ier, ien, inv, inr, ine, rvi, rve, rvn, riv, rie, rin, rev, rei, ren, rnv, rni, rne, evi, evr, evn, eiv, eir, ein, erv, eri, ern, env, eni, enr, nvi, nvr, nve, niv, nir, nie, nrv, nri, nre, nev, nei, ner]

[vire, virn, vier, vien, vinr, vine, vrie, vrin, vrei, vren, vrni, vrne, veir, vein, veri, vern, veni, venr, vnir, vnie, vnri, vnre, vnei, vner, ivre, ivrn, iver, iven, ivnr, ivne, irve, irvn, irev, iren, irnv, irne, ievr, ievn, ierv, iern, ienv, ienr, invr, inve, inrv, inre, inev, iner, rvie, rvin, rvei, rven, rvni, rvne, rive, rivn, riev, rien, rinv, rine, revi, revn, reiv, rein, renv, reni, rnvi, rnve, rniv, rnie, rnev, rnei, evir, evin, evri, evrn, evni, evnr, eivr, eivn, eirv, eirn, einv, einr, ervi, ervn, eriv, erin, ernv, erni, envi, envr, eniv, enir, enrv, enri, nvir, nvie, nvri, nvre, nvei, nver, nivr, nive, nirv, nire, niev, nier, nrvi, nrve, nriv, nrie, nrev, nrei, nevi, nevr, neiv, neir, nerv, neri]

[viren, virne, viern, vienr, vinre, viner, vrien, vrine, vrein, vreni, vrnie, vrnei, veirn, veinr, verin, verni, venir, venri, vnire, vnier, vnrie, vnrei, vneir, vneri, ivren, ivrne, ivern, ivenr, ivnre, ivner, irven, irvne, irevn, irenv, irnve, irnev, ievrn, ievnr, iervn, iernv, ienvr, ienrv, invre, inver, inrve, inrev, inevr, inerv, rvien, rvine, rvein, rveni, rvnie, rvnei, riven, rivne, rievn, rienv, rinve, rinev, revin, revni, reivn, reinv, renvi, reniv, rnvie, rnvei, rnive, rniev, rnevi, rneiv, evirn, evinr, evrin, evrni, evnir, evnri, eivrn, eivnr, eirvn, eirnv, einvr, einrv, ervin, ervni, erivn, erinv, ernvi, erniv, envir, envri, enivr, enirv, enrvi, enriv, nvire, nvier, nvrie, nvrei, nveir, nveri, nivre, niver, nirve, nirev, nievr, nierv, nrvie, nrvei, nrive, nriev, nrevi, nreiv, nevir, nevri, neivr, neirv, nervi, neriv]

Without further ado, here’s the source code. As always, if you find any bugs or have suggestions for improvements, let me know.

Combinations.java

Permutations.java

5/17/09
8:01 pm
Septoplasty Update

I’m back from the checkup at the surgeon’s. He castigated me for not hydrating my nose with the prescribed saline solution, but in all fairness, I wasn’t exactly eager to shove hot salt water up my nose in the hours following my surgery.

In any case, I have to do it now to dissolve the blood clots and assorted gunk up there. Quite disgusting but mandatory. To show me why I had to do it, during my checkup, he inserted tweezers into my nostrils and pulled out a giant blood clot. If you’ve ever extracted any nasal hair by giving them a good tug and enjoyed the sting and watery eyes after, then you can imagine what it feels when around 40,000 hairs are forcibly extricated in this fashion. Ow.

So, I have to hydrate with this hot water and salt solution four times a day until May 22nd, when the splints come out. The blood has stopped flowing down the front of my nose, but the seepage continues down the back of my throat. My painkillers have almost run out and the hot water certainly makes my entire face ache with a dull pain. It’s not pleasant, but only a few more days.

In conclusion, things are better than they were last week, but there’s a dull ache, only relieved by the promise of the splints’ extraction on the upcoming Friday. One can only hope it won’t hurt too much, but I think I’m being overly hopeful. They are stitched to my healing septum after all. Ow.

5/14/09
2:23 pm
The Monolith

So it’s the end of the KDE monolith for me. I’ve come to like KDE and use it as my primary desktop over the years, but everything must come to an end. Never fear, I’m not switching to GNOME or Xfce (which kicks ass), but just going with the split ebuilds.

So basically, if, like me, you installed the monolithic KDE in Gentoo, circa 2005 and are now looking to upgrade to KDE 4.2.x, here’s the easy way to do it. Be warned that all your KDE 3.5.x apps will disappear, but your data will remain. For example, the new Kmail 4.2.3 replaced Kmail 3.5.9 but left all my email intact.

A caveat, you might need to install KDE 3.5.10, which is the last KDE 3.x version out there, if you intend to run apps such as Kile or Krusader, which rely on KDE 3.5 libraries. Luckily, Gentoo works with slots, which allow you to have KDE 3.5.10 and 4.2.3 installed concurrently.

So, first unmerge that evil monolithic KDE (from a terminal, of course, not within KDE, I’m not responsible if you do so)

emerge -C kde
emerge --depclean -a

Clean out everything you don’t need, trim the list if you wish.

Now, check the availability of the KDE version  you require with eix:

eix -e kdebase-meta

You should see both 3.5.10 and 4.2.3, which is the latest one as of this writing. Now use autounmask to unmask them both, at least on the x86 platform:

autounmask kde-base/kdebase-meta-4.2.3

Let this run for a while, it takes around 20 minutes. Then emerge it and you should have a working kde 4.2.3:

emerge --newuse =kdebase-meta-4.2.3

Once you’re in your new KDE, you’ll see that many apps that worked before no longer do so, such as Kmplayer and Kile. Just unmerge the previous monolithic KDE 3.5.9 versions and emerge the KDE 3.5.10 equivalents

emerge -aC kdegraphics
autounmask kde-base/kdegraphics-meta-3.5.10
emerge =kdegraphics-meta-3.5.10

And there you have it, a seamless upgrade from monolithic KDE 3.5.9 to a split ebuild KDE 4.2.3 on Gentoo. Enjoy.

5/13/09
1:28 pm
Septoplasty

Last week, on May 6th, to be precise, I underwent a septoplasty. This post will chronicle some of my experiences in the hope that it might help people with questions about the procedure, espeically if they are about to undergo it themselves.

Last Feb, the specialist diagnosed my chronic sinusitis as being caused by a deviated septum. Apparently, I broke my nose as a kid, but never realized it and my septum grew all crooked ever since. It wasn’t a problem, until my mid-twenties when it started to obstruct a nostril and impede circulation, thereby causing all sorts of sinus problems.

To cut to the chase, I didn’t eat or drink anything (even water) after midnight on the 5th of May. I showed up at the appointed time of 9.00 AM and sat there. At 10.20, they wheeled me in and put me on an IV feed. Then I was subjected to a barrage of questions about dentures, blood pressure and whatnot, all because of the imminent anesthetic. I was anesthetized at 1.00 PM and I don’t remember a thing after it, obviously.

I came to around 4 PM, groggy as hell and in pain. The nurse asked me to rate my pain on a scale of 1 to 10, with 10 being unbearable, 3 being tolerable and 1 being bliss. I said 3, because the pain was present, yet tolerable. Around 20 minutes later, she asked if I was in pain and I said yes. The right answer is always 10, since if you say anything below that, they think you’re trying to be a tough guy. Having said 7, they pumped me full of morphine and I drifted off again.

I came to and they were measuring my blood pressure, which was insanely high because they’d pumped me full of cocaine during the surgery, to aid with the septoplasty. What a day, being pumped full of cocaine and morphine and not feeling a damn thing. I understood that they weren’t going to release me until my blood pressure returned to normal, and I drifted in and out of consciousness.

Around a few hours later and several bandage changes later, I was allowed to leave, it being a day surgery and all. Fortified with plenty of T3s and that huge dose of morphine, I was wheeled out to my car, which my girlfriend then drove home.

The last seven days have been a blur of painkiller-induced sleeptime and hazy bouts of pain. My nose leaked blood down the front, which was heavily bandaged, and also down the back of my throat, but I wasn’t allowed to clear my throat or blow my nose, for fear of dislodging the blood clots.

Other things that were verboten:

  • Hot drinks
  • Hot Showers
  • Steam of any kind
  • Exertion of any kind

Luckily, thanks to the painkillers, discomfort was minimal, as long as I remembered to take them regularly. The strong antibiotics  make me fairly dizzy, so I’m still not allowed to drive or anything like that.

As for my diet, it was basically soup and soft foods for the first few days after the surgery, since chewing anything hard jarred the upper jaw and caused pain. But now it’s fine, I can eat almost anything, but I’m still taking it easy, at least until the bandages come off.

One week after the surgery, tomorrow, I get to go back to the specialist to take my bandages off. They’ll examine the nose and check that everything’s ok. I really hope everything is, since I really don’t want to undergo all of last week again.

If all has gone well, one week from tomorrow, they’ll take out the splints from my nose and it won’t be so swollen anymore. I’ll return to looking normal, and not be a bandaged freak of nature.

Speaking of a swollen nose, the outcome wasn’t as bad as I’d expected. I had anticipated black eyes, a fully swollen face, the works! But luckily, all that’s swollen is my nose and upper lip (not that I can see them, they’re under the bandages, but they are puffy and tender). The doctor assures me that my nose will look the same externally, so I guess I’ll find out tomorrow when the bandages come off.

I’ll keep you posted.

5/01/09
11:20 pm
Chris Cornell Live

With two free tickets to Chris Cornell at the Commodore, how could I resist? My friend Schmidty and I showed up late, yet didn’t miss any of the openers. What luck. The Crash Kings were first, and were alright, closing with a cover of War Pigs. No axeman, but the lead keyboardist compensated with enough phallic manoeuvres to fool any of us.

That’s it, one opener and then Cornell came on. He was excellent, I must admit I didn’t know anything new after 1996. I’d never liked Audioslave and I have no idea what he’s doing now, but he must be doing well to be touring.

Anyway, like the majority of people there, I was there for the Soundgarden songs. Here’s a brief setlist of the ‘Garden tunes he played:

  • Fell on Black Days
  • Blow Up the Outside World
  • Outshined
  • Rusty Cage
  • Hunger Strike (Temple of the Dog, but who’s complaining)
  • Black Hole Sun
  • Like Suicide

The highlight of the night was Schmidty walking around with the N95 mask..

I lost count of how many people who came up to me, on Granville and elsewhere, asking me what was wrong with him. In the Commodore itself, people thought he was nuts. I patiently explained to everyone who asked that he’d just come back from Mexico and that he was feeling a bit under the weather (a blatant untruth). Schmidty often piped in with “It’s more for you than for me”. Apparently, the N95 really stinks after a few hours of use, but oh well. Schmidty did his bit to spread a bit of panic about the swine flu and a good time was had by all.

This makes the last two bands I’ve seen start with CC, Cannibal Corpse and Chris Cornell. All I need is for Cephalic Carnage to go on tour and my alliterative triplet is complete.

Thanks to Schmidty for the pictures.