Recent posts (max 20) - Browse or Archive for more

About

Trying a new trac blog plugin. Apparently I need an "about" post. I imported all of my old posts, and they're still around on the wiki. I might have lost some versions. *Shrugs*.

  • Posted: 2008-07-04 14:06 (Updated: 2008-07-04 14:08)
  • Author: cory
  • Categories: (none)
  • Comments (0)

Remembering How to Rotate a Vector

For no reason that I can remember, I was recently reminded of a solution to a homework problem way back from my first semester in college that I thought was creative. Having not had anything to say here for four months, I thought it would be fun to dig up the code and take a look.

The challenge was to rotate a vector in place using constant extra memory and less than O(n2) moves. There was very little additional information. I remember scratching my head for a while and then coming up with this crazy scheme involving the greatest common divisor which I drew out in great detail with boxes and arrows explaining how everything would move. I was disgusted that I couldn't arrive at a way to remove the gcd function entirely.

Now that I look, I see it is an early problem in book Programming Pearls. Their solutions can be found here. Algorithm 3 is the closest to mine, and they indeed don't need to calculate the gcd ahead of time.

Oh, and I was sloppy with whitespace and some other details back then.

/* Euclid's algorithm for calculating the greatest common divisor of two numbers.
        Taken from page 58 of "Data Structures & Algorithm Analysis in C++ Second Edition" by Mark Allen Weiss. */
int gcd(int a, int b)
{
        while (b)
        {
                int r = a % b;
                a = b;
                b = r;
        }
        return a;
}
/* Rotates a vector i steps, using minimal moves.
        This requires an "extra" calculation of the greatest common divisor of i and v.size(), but this algorithm
        still wins out over rotating v one element at a time i times, because this is O(n) while the latter method is O(n^2) */
template<class T> void rotate(vector<T> &v, int i)
{
        int size = v.size();
        int factor = gcd(size, i);
        i %= size;
        int p;
        for (p = 0; p < factor; p++)
        {
                int n;
                T temp = v[p];  // Pull out one element so we can shift everything forward.
                for (n = (p + i) % size; n != p; n = (n + i) % size)    // Until we get back to where we start, shift each element forward.
                        v[(n - i + size) % size] = v[n];
                v[(p - i + size) % size] = temp;        // Put back original element.
        }
}
  • Posted: 2008-06-06 00:13
  • Author: cory
  • Categories: (none)
  • Comments (0)

Bargle

  • Posted: 2007-08-06 22:26
  • Author: cory
  • Categories: (none)
  • Comments (0)

Cory Can Read

I have been recommending reading material weekday morning for a handful of people for just over five weeks, now.

I make no claims to any of it being interesting, relevant, or entertaining, and I am not even sure how it will proceed from here. For the most part it has been programming-related articles with a mix of random things that amused me from the Internet.

http://groups.google.com/group/cory-can-read

  • Posted: 2007-05-09 00:07
  • Author: cory
  • Categories: (none)
  • Comments (0)

Colored Quote Bars

It has long annoyed me that Thunderbird sometimes treats the '>' characters in excerpts from diffs as reply markers and draws a blue line instead of the actual characters from the E-mail.

I finally found some talk about how to disable that feature here.

Put this in ~/.thunderbird/*.default/chrome/userContent.css:

  blockquote[type=cite] {
    padding-bottom: 0 ! important;
    padding-top: 0 ! important;
    padding-left: 0 ! important;
    border-left: none ! important;
    border-right: none ! important;
  }

Set the following options:

  user_pref("mail.quoted_graphical", false);
  user_pref("mailnews.display.disable_format_flowed_support", true);

And the bars go away. Along the way, I noticed that if format=flow is included in the Content-Type header, Thunderbird does the right thing. So, the source of these E-mails is partly to blame, but I am happy that there is something I can do about it for now.

  • Posted: 2007-03-23 00:12
  • Author: cory
  • Categories: (none)
  • Comments (0)

The Quest for a Hat

Hat Quest

I don't know what got into me, but I got a hat and made a little adventure game about it.

  • Posted: 2007-02-27 21:44
  • Author: cory
  • Categories: (none)
  • Comments (0)

No Comic

Freezing Rain, No Comic
  • Posted: 2007-01-14 20:13
  • Author: cory
  • Categories: (none)
  • Comments (0)

Comments

I have not allowed comments in a long time. Let's see how well this works out...

  • Posted: 2007-01-07 12:51
  • Author: cory
  • Categories: (none)
  • Comments (0)

Fun Was Had by All

  • Posted: 2006-10-23 23:47
  • Author: cory
  • Categories: (none)
  • Comments (0)

Would you like to see a movie?

Thanks to movie nights on Thursdays, MST3K Mondays, and going out to see movies on Fridays, I have been watching a lot more movies than I previously did. Here is a list of movies that I can remember:

  • The Adventures of Buckaroo Bonzai Across the Eighth Dimension
  • Amores Perros
  • Big Trouble in Little China
  • Clerks II
  • Conan the Barbarian
  • Crank
  • District B13
  • Drunken Master II
  • Hudsucker Proxy
  • Lock, Stock, and Two Smoking Barrels
  • MST3K (Rifftrax) - Star Trek V
  • MST3K - Hobgoblins
  • MST3K - The Day the Earth Froze
  • Mission Impossible III
  • Scotland, PA
  • Snakes on a Plane
  • UHF
  • V for Vendetta
  • Wordplay
  • X-Men III
  • Posted: 2006-09-04 21:47
  • Author: cory
  • Categories: (none)
  • Comments (0)

My Brother is Getting Married...

  • Posted: 2006-08-03 14:01
  • Author: cory
  • Categories: (none)
  • Comments (0)

Potato Villain or another Spud Fiend?

  • Posted: 2006-06-11 14:14
  • Author: cory
  • Categories: (none)
  • Comments (0)

Allergies!

At least I no longer suffer from allergies. I only suffer when I am not taking a copious amount of antihistamines. And then only when my ensuing itchiness, despondence, lack of sleep, and inability to focus on anything get in the way of what I am trying to do.


Dear The Food Industry of America,

Feel free to take the following ideas to do with as you please.

Sincerely,
Cory

  • Posted: 2006-05-28 19:19
  • Author: cory
  • Categories: (none)
  • Comments (0)

The Week in Review

  • Posted: 2006-02-26 14:54
  • Author: cory
  • Categories: (none)
  • Comments (0)

Triangle Peg Board Puzzle

That is what I get for eating lunch with a bunch of programmers.

  • Posted: 2006-01-16 00:34 (Updated: 2008-06-30 15:28)
  • Author: cory
  • Categories: (none)
  • Comments (0)

Rocking Out at Jordan Road

In about a week, VV is moving its office across the river. In a musical experience never to be duplicated, we got the band back together for one final performance at the old place.

  • Posted: 2006-01-14 14:14
  • Author: cory
  • Categories: (none)
  • Comments (0)

Degree Spam

Ten days of classes left, and I get spam like this:

Good jobs require a universityy education. Now you can get one in just a few days, and you'll also get that paper on your wall''

Sounds like a good deal to me.

  • Posted: 2005-11-27 09:16
  • Author: cory
  • Categories: (none)
  • Comments (0)

Tony Hawk's American Sk8land DS

  • Posted: 2005-11-19 00:01
  • Author: cory
  • Categories: (none)
  • Comments (0)

Math is Scary

http://rinse.unprompted.com/share/pumpkin.jpg

x = 2c / (-b +/- sqrt(b2 - 4ac))

  • Posted: 2005-10-30 11:48
  • Author: cory
  • Categories: (none)
  • Comments (0)

Tony Hawk's American Sk8land

  • Posted: 2005-10-25 13:12 (Updated: 2008-07-04 14:11)
  • Author: cory
  • Categories: (none)
  • Comments (0)