Sunday, November 28, 2010

Spanish Woman Claims Ownership of the Sun

(link in post title)


Umm...


A lady in Spain registered the sun as her personal property with a local notary after hearing about an American man who did the same with the moon and a bunch of planets in the solar system.


The best part of the article:


"There is an international agreement which states that no country may claim ownership of a planet or star, but it says nothing about individuals, she added."

Saturday, November 27, 2010

Chopiner

So, I'm learning Chopin's piano concerto in e, and wrote something simple up to help with the complicated rhythms. If you're ever having rhythm trouble, just compile it in GCC or any other C++ compiler and the rest should be pretty self-explanatory. You'll have to #include iostream, sstream, vector, cmath and assert.h.


using namespace std;
string LH;
string RH;
int nSubBeats;
int timeSig;

struct noteT {
double value;
bool rest;
double position;
};

string GetLine() {
string result;
getline(cin, result);
return result;
}

int GetInteger() {
while(true) {
stringstream converter;
converter << GetLine();

int result;
converter >> result;

if(converter.fail())
cout << "Please enter an integer. ";
else {
char remaining;
converter >> remaining;

if(converter.fail())
return result;
else
cout << "Unexpected character: " << remaining << endl;
}

cout << "Retry: ";
}
}

double Abs(double n) {
return (n<0) ? -n : n;
}

bool CloseEnough(double sum) {
return Abs(1 - sum) < .01;
}

double LCM(double a, double b) {
double A = a;
double B = b;
while (!CloseEnough(1.0-(a-b)))
(a < b) ? a += A : b += B;
return ((int)a - a == 0) ? a : b;
}

int Round(double n) {
int flooring = floor(n);
int ceiling = ceil(n);
return (n - flooring < ceiling - n) ? flooring : ceiling;
}

void PrintfBeat(string hand) {
for (size_t i = 0; i < hand.length(); i++)
hand[i] = '-';

int every = hand.length()/timeSig;
for (size_t i = 0; i < timeSig; i++)
hand[i*every] = '!';

cout << "(The first line is the beat)\n" << hand << endl;
return;
}

void CalculateNoteValue(const string source, noteT &currNote, const int i, int &n) {
while (true) {
if (source[i+n] == '_')
currNote.value /= 2;
else if (source[i+n] == '-')
currNote.value *= 2;
else if (source[i+n] == '.')
currNote.value *= 1.5;
else {
n--;
return;
}
n++;
}

return;
}

double FindModifier(const string source, int &n) {
double modifier = 1;
n++;
while (source[n] == '_' || source[n] == '.' || source[n] == '-' ) {
if (source[n] == '_')
modifier *= .5;
if (source[n] == '.')
modifier *= 1.5;
if (source[n] == '-')
modifier++;
n++;
}
n--;
return modifier;
}

double WhatsTheKPlet(const string source, int &i);

double kPletBracketsSituation(const string source, int i) {
vector bracketedNotes, total;
while (source[i] != ')') {
double currentNoteValue = FindModifier(source, i);
bracketedNotes.push_back(currentNoteValue);
i++;
}

if (source[i+1] != '<') {
int increment;
for (size_t j = 0; j < bracketedNotes.size(); j++) { // Slightly inefficient but more readable and no copied code.
increment = 1;
noteT dummy;
dummy.value = bracketedNotes[j];
CalculateNoteValue(source, dummy, i, increment);
total.push_back(dummy.value);
}
i += increment;
} else if (source[i+1] == '<') {
i += 2;
double kPlet = WhatsTheKPlet(source, i);
string number = "     ";
double divideBy;
int n = 0;
while (source[i+n] != '>') {
number[n] = source[i+n];
n++;
}
i += n;

divideBy = atof(number.c_str());
double multiplier = divideBy/kPlet;

for (size_t j = 0; j < bracketedNotes.size(); j++)
total.push_back(bracketedNotes[j]*multiplier);

} else {
cout << "\nBad input: char \'" << source[i+1] << "\' after \')\'.\nSIGABRT time! Wheeeeeeeeeeeeeeeeeeee";
assert(false);
}

double totalValue = 0;
for (size_t x = 0; x < total.size(); x++)
totalValue += total[x];

return totalValue;
}

double WhatsTheKPlet(const string source, int &i) {
int n = i;
int count = 0;
while (true) {
if (source[n] == ')')
count++;

if (source[n] == '(') {
count--;
if (count == 0) {
n--;
break;
}
}
n--;
}

n += 2;
double kPlet = 0;
while (n <= i - 2) {
if (source[n] != '_' && source[n] != '-' && source[n] != '.' && source[n] != ')' && source[n] != '(' && source[n] != '>' && source[n] != '<') {
double noteModifier = FindModifier(source, n);
kPlet += 1.0*noteModifier;
n++;
} else if (source[n] == ')') {
n++;
} else {
while (source[n] == '(')
n++;

if (source[n+1] == '>')
break;

kPlet += kPletBracketsSituation(source, n);

while (source[n] != ')' && source[n] != '>')
n++;
n += 2;
if (source[n+1] == '>')
n += 2;
if (source[n-1] == '<') {
while (source[n] != '>')
n++;
n++;
}
}
}

while (source[i-1] != '<')
i++;

return kPlet;
}

void CalculateNplet(int &i, const string source, vector &setOfNotes, vector &notes) {
i += 2;

double kPlet = WhatsTheKPlet(source, i);

string number = "      ";
double divideBy;
int n = 0;
while (source[i+n] != '>') {
number[n] = source[i+n];
n++;
}
i += n;

divideBy = atof(number.c_str());
double multiplier = divideBy/kPlet;

for (size_t j = 0; j < setOfNotes.size(); j++) {
setOfNotes[j].value *= multiplier;
notes.push_back(setOfNotes[j]);
}

return;
}

void CalculateCurrentNote(noteT &currNote, const string source, int i, int &increment) {
CalculateNoteValue(source, currNote, i, increment);

if (source[i] == '0')
currNote.rest = true;
else
currNote.rest = false;
return;
}

void WithinBrackets(const string source, int &i, vector &notes) {
vector setOfNotes, within;
i++; // To get past '(' char
while (source[i] != ')') {
if (source[i] == '(') {
WithinBrackets(source, i, within);
i++;

for (size_t j = 0; j < within.size(); j++)
setOfNotes.push_back(within[j]);

within.clear();
}

if (source[i] == ')')
break;

noteT currNote;
int increment = 1;
currNote.value = 1.0 / timeSig;
CalculateCurrentNote(currNote, source, i, increment);
i += increment + 1;

setOfNotes.push_back(currNote);
}

if (source[i+1] == '_' || source[i+1] == '-' || source[i] == '.') {
int increment;
for (size_t j = 0; j < setOfNotes.size(); j++) { // Slightly inefficient but more readable and no copied code.
increment = 1;
CalculateNoteValue(source, setOfNotes[j], i, increment);
notes.push_back(setOfNotes[j]);
}
i += increment;
} else if (source[i+1] == '<') {
int dummy = i;
CalculateNplet(dummy, source, setOfNotes, notes);
i = dummy;
} else {
cout << "\nBad input: char \'" << source.substr(0, i+1) << "\' after \')\'.\nSIGABRT time! Wheeeeeeeeeeeeeeeeeeee";
assert(false);
}
}

bool BadBrackets(string &source) {
int openSmooth = 0;
int openAlligator = 0;

for (size_t i = 0; i < source.length(); i++) {
if (source[i] == ')')
openSmooth--;
if (source[i] == '(')
openSmooth++;
if (source[i] == '<')
openAlligator++;
if (source[i] == '>')
openAlligator--;
}
return  openSmooth != 0 && openAlligator != 0;
}

void VectorizeNotes(vector &notes, const string source) {
for (size_t i = 0; i < source.length(); i++) {
if (source[i] == ' ')
return;

if (source[i] != '(') {
noteT currNote;
int increment = 1;
currNote.value = 1.0 / timeSig;
CalculateCurrentNote(currNote, source, i, increment);
i += increment;
notes.push_back(currNote);
} else {
int dummy = i;
WithinBrackets(source, dummy, notes);
i = dummy;
}
}
return;
}

bool VectorCount(const vector &v, double n) {
for (size_t i = 0; i < v.size(); i++)
if (v[i] == n)
return true;
return false;
}

void RemoveSpaces(string &hand) {
while (hand.find(" ") != -1) {
for (size_t i = 0; i < hand.length(); i++) {
if (hand[i] == ' ') {
string left = hand.substr(0, i);
string right = hand.substr(i+1, hand.size() - 1);
hand = left + right;
}
}
}
return;
}

void ReadHand(vector &notes, string &hand, const string whichHand) {
cout << "Enter notes for the " << whichHand << " hand: ";
while (true) {
hand = GetLine();
if (hand[hand.length()] != ' ')
hand += " ";

if (BadBrackets(hand))
cout << "Unbalanced brackets! Try again: ";
else
break;
}

RemoveSpaces(hand);
VectorizeNotes(notes, hand);
return;
}

int FindNNotes(vector notes) {
vector values;
// Get rid of duplicate note values
for (size_t i = 0; i < notes.size(); i++) {
double value = 1.0/notes[i].value;
if (!VectorCount(values, value)) {
values.push_back(value);
}

}

// Find LCM of all the note values
for (size_t i = 0; i < values.size() - 1; i++) {
values[i] = LCM(values[i], values[i+1]);
values.erase(values.begin() + i +1);
i--;
}

return values[0];
}

void DoHand(vector &notes, string &hand) {
hand = "";
for (int i = 0; i < nSubBeats; i++)
hand += "-";

int numNotes = notes.size();

notes[0].position = 0;
for (size_t i = 1; i < numNotes; i++) {
notes[i].position = (notes[i-1].position + notes[i-1].value);
}

double sum = notes[numNotes-1].position + notes[numNotes-1].value;
if (!CloseEnough(sum)) {
cout << "\nOK, so, you didn't enter a full bar of notes. \nOr more than one. Try compiling and running again!\n";
cout << "SIGABRT time!\n";
assert(false);
return;
}

for (size_t i = 0; i < numNotes; i++) {
if (notes[i].rest == false) {
int index = Round(notes[i].position*hand.length());
hand[index] = 'o';
} else {
hand[notes[i].position*hand.length()] = '_';
int howManyMore = notes[i].value*hand.length();
for (int j = 1; j < howManyMore; j++) {
hand[notes[i].position*hand.length()+j] = '_';
}
}
}

return;
}

void Welcome() {
cout << "Hiya! Enter rhythms for both hands to see how they fit together.\n";
cout << "First, some formatting and syntax info: \n";
cout << "• Notes are assumed to be one beat long\n";
cout << "• Select sets of notes with ( and ). For example: (oooo)\n";
cout << "• Lengthen or shorten a note or set of notes with the following operators:\n '-'(+1 beat)\n '_'(/2)\n '.'(*1.5)\n\n";
cout << "• Make n-plets with alligator mouths; use them after a ')' char. An n-plet is n notes in the time of however many.\n";
cout << "• For example: (ooooo)<2> is ooooo in the time of two beats. That is, five notes (ooooo) in the time of two notes of one beat each.\n";
cout << "• You don't need to mark the notes within an n-plet as sixteenth notes or whatever -- just without any modifications will be fine.\n";
cout << "• If notes within a n-plet are of different lengths, be sure to mark the first number within the alligator mouths as the number of beats within the n-plet.\n";
cout << "• Finally, pretty much any character can signify a note, except for '_', '-', '.', '<', '>', '(', ')' and '0'. (0 signifies a rest).\n";
cout << "Here's an example (In 3-4 time): \nRH is (ooo_)<2>o, LH is ooo. Generates the following: \no---o---o-o----\no----o----o----\n\n";
return;
}

void Simpler() {
cout << "Enter the number of notes played in the hand that has more notes to play: ";
int more = GetInteger();
cout << "Enter the number of notes played in the hand that has fewer to play: ";
int fewer = GetInteger();

string moreH = "";
int totalLength = more * fewer;
for (int i = 0; i < totalLength; i++)
moreH+= "-";

string fewerH = moreH;

for (size_t i = 0; i < fewer; i++)
fewerH[i*more] = 'o';

for (size_t i = 0; i < more; i++)
moreH[i*fewer] = 'o';

cout << moreH << endl << fewerH << endl;
return;
}

int main (int argc, char * const argv[]) {
while (true) {
cout << "Would you like to enter rhythms for both hands (enter '1') or uniform rhythms (enter '2')? ";
string answer = GetLine();
if (answer[0] == '2') {
Simpler();
return 0;
} else if (answer[0] == '1')
break;
}

vector RHnotes, LHnotes;
Welcome();

while (true) {
cout << "\nEnter the number on the top part of the time signature: ";
timeSig = GetInteger();

ReadHand(RHnotes, RH, "right");
ReadHand(LHnotes, LH, "left");

cout << "RH is " << RH << endl;
cout << "LH is " << LH << endl;

double nR = FindNNotes(RHnotes);
double nL = FindNNotes(LHnotes);
nSubBeats = LCM(nR, nL);

DoHand(RHnotes, RH);
DoHand(LHnotes, LH);

cout << "The minimal number of beats to represent the right hand is " << nR << ".\n";
cout << "The minimal number of beats to represent the left hand is " << nL << ".\n";
cout << "The minimum total number of sub-beats is " << nSubBeats << ".\n";
PrintfBeat(RH);
cout << RH << endl;
cout << LH << endl;

cout << "Would you like to do another one? ";
string response = GetLine();
if (response[0] == 'n' || response[0] == 'N')
break;
}
return 0;
}

Monday, November 8, 2010

Apollo 11 Launch 500 fps Video

(link in title)

Wow -- this is an incredible video. It's a slow-motion video of the Apollo 11 launch. I didn't know they had such high camera technology back then! There's a very interesting running narration that's the audio for the video.

Thursday, October 28, 2010

Monday, October 25, 2010

The Dangers of Twitter and URL shorteners

Oh, gosh, this is so surreal... a spokesperson for Meg Whitman, the Republican nominee for governor of California, tweeted a link to the campaign website... only it wasn't a link to the campaign website. They used a URL shortener, and, when tweeting, accidentally left off an 'r' at the end. I won't spoil what it linked to, but I will provide the link: http://bit.ly/bNCAV.

Cats Morph into Croissants



Waaah... what a hilariously amusing video. I can't stop watching it...
(thanks to Wendy/Sarah for showing me this!)

Sunday, October 24, 2010

Bridge Crossing

There are four people who want to cross a bridge. They take 1, 2, 5 and 10 minutes, respectively. They're crossing at night, so, to cross, you need a lantern, and they have one between the four of them. The bridge is only wide enough to fit two people crossing at a time.

What's the floor on their crossing time? That is, what's the shortest possible time for them all to cross?

Friday, October 22, 2010

A Wonderful Puzzle

(thanks to Wendy for giving this to me)

You read in a stream of integers one by one. You don't know in advance how long the sequence will be, though, of course, you can recognize the EOF char when you get to it. You have to find which integer is the majority, where the majority is defined to be the integer that appears at least (n/2) + 1 times, where n is the length of the sequence.

Do it in constant memory. And, linear time, of course.

Jack-in-the-Box Pluralizations




A weird discussion with Wendy and Frank led to the question, how does one go about pluralize "Jack-in-the-box?" The following would have weird denotations, though they're what an online search brought up:
• Jacks-in-the-box (á la passersby ou coups-d'etat, though note: tête-à-têtes)
• Jack-in-the-boxes (one Jack in multiple boxes)

Which leaves us with "Jacks-in-the-boxes." Which sounds like it should be right.

Saturday, October 16, 2010

Mandelbrot is dead :(

He died of pancreatic cancer. Apparently he first developed the concept of a fractal when he was asked how long Great Britain's coastline is, when he realized that the answer seemed to grow as one "zoomed in" on the coastline.

His approach to math is interesting (quoted from the NYTimes article; link in post):


"Dr. Mandelbrot received more than 15 honorary doctorates and served on the board of many scientific journals, as well as the Mandelbrot Foundation for Fractals. Instead of rigorously proving his insights in each field, he said he preferred to “stimulate the field by making bold and crazy conjectures” — and then move on before his claims had been verified. This habit earned him some skepticism in mathematical circles."

16th International Fryderyk Chopin Competition

The competition only happens every five years! It's been going on since October 3, now. The finals start in two days! This is basically the most prestigious piano competition that exists today. Martha Argerich (a former winner of the competition) is one of the judges! Participants must be between 17 and 30 years old. By the time one gets to the finals, they will have learnt nineteen pieces (all by Chopin) from a selection of about... 40? Ten people qualified for the finals, and there were 80 at the start. For the final, they have to play one of the two concertos, with an orchestra instead of a second piano reduction, I think.

There's a live broadcast going on (resumes on Monday); it's definitely worth a listen. The Chopin concertos are super-awesome. I'm currently learning one of them, Op. 11 in e.

As an aside, Yundi Li (李云迪), who I'm going to hear play the Tchaikovsky concerto in the Spring in SF, won this competition at 18. He was the first person to win the first prize in 15 years.

Wednesday, October 13, 2010

Prokofiev concerto 2 and Flight of the Bumblebee

This must be the most technically impressive piano playing I've ever seen in my life. Here's Wang Yujia (王羽佳) playing the second movement of Prokofiev's second concerto and, for an encore, Cziffra's arrangement of Flight of the Bumblebee. In the Prokofiev, by the way, that movement has the right hand and left hand playing almost 1500 16th-notes each in under 3 minutes, or basically 10 notes per second, both hands together.

That's the kind of finger independence each pianist wishes for: each finger on each of her hands is controlled completely individually! And look at how relaxed her hands are throughout! It's just astounding. Check out 6:55-7:00, especially.

By the way, that's Michael Tilson Thomas conducting -- he's the head conductor of the San Francisco Symphony Orchestra, a nearby orchestra I go to often (just heard Beethoven 7 and on Oct. 24 is Beethoven piano concerto 4).

3D Duckrabbit

The famous Duckrabbit illusion, recreated through taxidermy:


Here's the original:

Wednesday, September 29, 2010

A Trumpeter's Shadow

(from an gallery in Wired on iPhone photography. Link in post title)

What a pretty photo:

Tuesday, September 28, 2010

Rotating Canvas Painting

(thanks to Yang for sending this to me)

Wow... this is pretty amazing: http://www.youtube.com/watch?v=OIJtKxdRQzY&hd=1

Classes and Fire Tornadoes

Settled on classes this quarter, in case anyone's curious:
• Music 21 (music theory)
• Phil 80 (consciousness, a WIM class)
• CS 103 (math and logic in CS)
• Russian, before it's too late
• ME110 (sketching), which is one unit
• Social Dance 2 (swing, waltz), which is one unit

In other news, just when you thought nature couldn't get any more awesome:

Here's a video from the AP and some pictures from National Geographic.

Sunday, September 26, 2010

Thursday, September 23, 2010

Multitask

(thanks to Frank for showing me this)

There's this really cool online Flash game (link in post title) that tests your multitasking abilities. It starts off really easy, but it gets really hard very quickly: