The READIN Family Album
Me and Sylvia, on the Potomac (September 2010)

READIN

Jeremy's journal

Understanding makes the mind lazy.

Penelope Fitzgerald


(This is a page from my archives)
Front page
More recent posts
Older posts

Archives index
Subscribe to RSS

This page renders best in Firefox (or Safari, or Chrome)

Sunday, January 15th, 2006

🦋 Sums of squares

I refined that program from Friday night a bit, to make it a little more readable and to make it calculate numbers that can be expressed as the sum of two squares in more than three different ways. The code is:

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>

bool exclude(int n, int *x)
{
while (*x)
{
if (n == *x)
return true;
++x;
}
return false;
}

bool IsSumOfSq(int s, int &a, int &b, int *x)
{
for (int i = a + 1; i < s; ++i)
{
int sq = i * i;
if (s < sq)
return false;
int diff = s - sq;
for (int j = 1; j < diff; ++j)
if (exclude(j, x))
continue;
else if (j * j == diff)
{
a = i;
b = j;
return true;
}
}
return false;
}

int main(int argc, char **argv)
{
int reps = atoi(argv[1]);
int i;
for (i = 1; i < 4000000; ++i)
{
int x[10];
memset((char *) x, 0, sizeof (x));
int pairs[10][2];
pairs[0][0] = 0;
if (!IsSumOfSq(i, pairs[0][0], pairs[0][1], x))
continue;
bool match = true;
for (int j = 1; j < reps; ++j)
{
pairs[j][0] = pairs[j - 1][0];
x[j - 1] = pairs[j - 1][0];
if (!IsSumOfSq(i, pairs[j][0], pairs[j][1], x))
{
match = false;
break;
}
}
if (match)
{
printf("%d", i);
for (int j = 0; j < reps; ++j)
printf(" = %d^2 + %d^2\n", pairs[j][0], pairs[j][1]);
}
}
return 0;
}

Results: the smallest number that can be expressed as a sum of squares in three different ways is still 325. Four different ways, 1,105. Five different ways, 5,525. Six different ways (this result I find really cool), 5,525. Seven different ways, 27,625. Then I got bored and stopped checking. Note that this program could easily be optimized, it's pretty slow as presented.

Update: Wowie zowie! 27,625 is also the smallest number which can be expressed as a sum of two squares in eight different ways! This seems awesome to me though I'm not sure what to make of it.

Update: Frederick points out that 1,105 = 5 * 13 * 17; 5,525 = 5 * 1,105; 27,625 = 5 * 5,525. No idea what's going on here but it sure looks like something. I have confirmed that 138,125 (5 * 27,625) can be expressed as the sum of two squares in ten different ways; 690,625 (5 * 138,125) can be expressed as the sum of two squares in twelve different ways; and 3,453,125 (5 * 690,625) can be expressed as the sum of two squares in fourteen different ways! I do not however know if those numbers are the smallest number that can be expressed as such. (Further update: The Online Encyclopædia of Integer Sequences has some interesting stuff on this.)

posted afternoon of January 15th, 2006: Respond

🦋 The big hill all to ourselves

It snowed last night -- there is not a lot on the ground but Ellen thought Sylvia and I should take the opportunity to head down to the park and go sledding. I was a little skeptical, whether there would be enough snow to bear the sled; but we set off. A good thing right off the bat -- I had forgotten that we got Sylvia a new sled last year, a very lightweight orange thing to replace the ponderous red sled we had two years ago. The red one would not have stood a chance; this one floated along under Sylvia.

Good thing two -- when we got to the park there was a lot of ice in the grass under the snow. As it turned out the lightweight sled could move quite a distance on that thin layer of snow and ice. Sylvia was hesitant but once she took the leap, she was loving it. And no-one else had come out to go sledding -- I guess it did not seem worth-while with so little snow; so we had the big hill all to ourselves. This afternoon we will go ice-skating.

posted morning of January 15th, 2006: Respond
➳ More posts about Sylvia

Friday, January 13th, 2006

🦋 Sum of 2 different squares, 3 different ways

Over at Unfogged, Frederick suggests that 325 is the smallest number which can be expressed as a sum of two perfect squares three different ways. I just wrote a program to check this which confirms Frederick's suspicion; here it is if you want to check my logic.

 #include 
 
 int perfect[] = {
     1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 
     11 * 11, 12 * 12, 13 * 13,
     14 * 14, 15 * 15, 16 * 16, 17 * 17, 
     18 * 18, 19 * 19, 20 * 20
     };
 
 bool IsSumOfSq(int s, int &a, int &b, int x1, int x2)
 {
     for (int i = a + 1; i < 20; ++i)
     {
         if (s < perfect[i])
             return false;
         int diff = s - perfect[i];
         for (int j = 0; j < 20; ++j)
             if (j == x1 || j == x2)
                 continue;
             else if (perfect[j] == diff)
             {
                 a = i;
                 b = j;
                 return true;
             }
     }
 }
 
 int main()
 {
     int i;
     for (i = 0; i < 400; ++i)
     {
         int a = -1, b;
         if (IsSumOfSq(i, a, b, -1, -1))
         {
             int c = a, d;
             if (IsSumOfSq(i, c, d, a, -1))
             {
                 int e = c, f;
                 if (IsSumOfSq(i, e, f, a, c))
                 {
                     printf("%d = %d^2 + %d^2\n"
                           "    = %d^2 + %d^2\n"
                           "    = %d^2 + %d^2", 
                         i, a + 1, b + 1, c + 1, 
                         d + 1, e + 1, f + 1);
                     break;
                 }
             }
         }
     }
     return 0;
 }
 

Output:

325 = 1^2 + 18^2
    = 6^2 + 17^2
    = 10^2 + 15^2

posted evening of January 13th, 2006: Respond
➳ More posts about Programming

Wednesday, January 11th, 2006

At the beginning of Voyage of the Dawn Treader, the narrator introduces Lucy and says that she had already gotten to visit her magical country twice (referring to The Lion, the Witch, and the Wardrobe and Prince Caspian). Sylvia thinks about this for a while and points out that it was actually three times, referring to the three separate visits in The Lion, the Witch, and the Wardrobe.

posted evening of January 11th, 2006: Respond
➳ More posts about The Chronicles of Narnia

My Proulx jag continues: last night I finished Postcards (loved it), this morning I started The Accordion Crimes -- I was thinking after Postcards almost anything would have to be a letdown, but it looks like I was wrong based on the beginning of The Accordion Crimes. Update: Er, just now I looked at the book and noticed the title is actually Accordion Crimes.

posted evening of January 11th, 2006: Respond
➳ More posts about Postcards

Monday, January 9th, 2006

Something else about Annie Proulx -- it is amazing to me the way time passes in her stories. I am 3/4 of the way through Postcards and the story has spanned about 30 or 40 years so far; but I have no sense that I have missed parts of the story skipped over, or that I have been rushed along. Instead I feel like I have been listening to the story for 30 or 40 years. (Which is not to say the story is dragging -- it's not, it's gripping -- it seems to me like a huge accomplishment for her to be able to hold my attention for virtual decades.)

posted afternoon of January 9th, 2006: Respond
➳ More posts about Annie Proulx

Saturday, January 7th, 2006

We went ice-skating again today -- Sylvia now a little more hip to the idea that she does not know how to do it, so more resistant to learning. But after sitting on the sidelines for about half an hour, she had a change of heart and tried it out. With Ellen in hand she made it around the rink (next to the wall, usually holding it) 3 times!

posted evening of January 7th, 2006: Respond

Tuesday, January third, 2006

Today I started reading another Annie Proulx book, Postcards -- this one is grabbing me right away, pulling me into the story. I'm really liking the way she leaves key bits of the story for you to fill in -- something I have found annoying elsewhere.

Something I have been thinking ever since reading Bad Dirt -- Proulx is incredibly versatile! In each story and each book, there is a new stylistic attribute.

posted evening of January third, 2006: Respond
➳ More posts about Readings

Monday, January second, 2006

Yay, recipe blogging! I came up with a new idea for dinner tonight and it tastes very good. I am not sure what to call it yet.

  • 3 strips of bacon. (more if it is lean)
  • 2 chicken breasts.
  • 1 small red onion.
  • 1 red bell pepper.
  • some broccoli.
  • 1 can of white beans.

Cut the bacon into bite-size pieces and fry it over a moderate flame until the fat starts coming out. Slice the chicken breasts into strips and add them to the pot with some salt, and fry until they are done, about 5 minutes, turning as necessary. While it is cooking cut up the onion, the pepper and the broccoli.

Spoon the chicken and bacon out of the pot and add the onion to the grease, with a little salt. Sauté it for a few seconds and then add the pepper, a few more seconds and add the broccoli. After about a minute, add the beans. Stir it around so the vegetables are not at the bottom of the pot, then add the meat back in and cover the pot. When it starts bubbling up, reduce the flame to a simmer. After about five minutes it will be ready to serve.

I served this over couscous tonight; I think it would also be good with rice or most any grain.

posted evening of January second, 2006: Respond

🦋 Dream blogging

Weird dream last night that I think was vaguely related to having read John Quiggin's post on terrorism and cancer* last night. Somebody I did not know except through blogs had ordered a prescription of epinephrine pseudoephedrine from an online prescription counter, and mistakenly had it delivered to my address. Then they realized the whole thing was a mistake since that combination of drugs is illegal. (I don't know if it actually is -- I remember a scandal about that drug combination a year or two ago but not the upshot of it -- in the dream it was definitely illegal.) So they contacted me and asked me to return the drugs, with complicated instructions I was to give to the online pharmacy about modifying the prescription and resending it to their address. I packaged it up and addressed it, but then left it by the front door and forgot about it until a few weeks later, when the other party contacted me with a very urgent message wondering what was going on.

Woke up singing "Ep,inEPHrine, pseudo,ephEDrine" to a square-dancy tune**, and thinking I should go to Crooked Timber and leave a tongue-in-cheek comment to John's post, to the effect that "If we ever needed a regulatory state apparatus like the FDA, that day is certainly past -- with the advent of the internet and world-wide web, the only tool the consumer really needs to find out whether a particular drug is safe and effective, is Google!" but decided against it.


*Just realized the connection may not be immediately clear: propertarians in the comments thread are putting down on the FDA, is why I thought there might be a connection. And for some cognitive dissonance, see this Making Light post, in which Teresa is angry at the FDA, or, well, at Public Citizen for its lobbying of the FDA.

**Aha! the tune was Roly Poly by Fred Rose. "Square-dancy" is probably a poor choice of adjectives, picked it in a hurry and it does not communicate much of relevance here.

posted morning of January second, 2006: Respond
➳ More posts about Dreams

Previous posts
Archives

Drop me a line! or, sign my Guestbook.
    •
Check out Ellen's writing at Patch.com.

Where to go from here...

Friends and Family
Programming
Texts
Music
Woodworking
Comix
Blogs
South Orange