Thursday, October 15, 2015

river math problem

So a few days ago, my attention was brought to this article. It's a very straight-forward minimization problem. The crocodile/zebra spin is just fluff, the equation that needs minimized is given to the student. Find the derivative and evaluate it at zero. I can't imagine this being "too hard" for anyone who has taken Calculus 1.

I got to thinking about it, and decided to try to find a general solution. So I needed to set up the original equation. That wasn't too hard. Given width of the river, W; the distance along the bank to the target, L; and the relevant velocities (swimming, Vs; running, Vr; and flow speed, Vf (not considered in the given formula, but what the hell) the relationship is pretty easy to find. I decided to make it a function of the angle at which the crocodile swims (in my set up 0° is directly across the river, and the angle increases clockwise).

So: total time is the sum of swimming time and running time. Swimming time is easy. It is the distance across the river (at the given angle) divided by the swimming speed. Running time is a little trickier, but it works out to the absolute value of the horizontal distance to the target minus the horizontal distance covered by the swimming angle, plus drift distance. Drift distance is swimming time times flow speed. So, the total time as a function of angle is:

Taking the derivative and minimizing gives:

Check it out. It looks like the W and L don't matter. Just the ratio of velocities. But if the swimming speed is higher than the running speed plus flow speed, the result is meaningless. It turns out that even if it is close, the angle it gives is ridiculous. It isn't obvious from any of this but the function has a discontinuity cusp where
tan(θ) = L/W, and the minimization will only work to that point.

I was having a hard time showing this on paper, so I did what I always do in these situations: I wrote a program to do it for me. I used the browser-based Python interpreter at CodeSkulptor

Here it is. Use this one. Feel free to play with it.(The last I knew, CodeSkulptor doesn't work right in IE) You can change the distances and velocities. Note that negative W, Vr, and Vs are nonsense. The program can't handle negative L. Negative Vf is fine, though.

Here's a screen shot of the solution to the original problem:

Here's a screenshot of one of the weird results.

(FIX: there was a bug in my drift calculation when I took that. The minimum time will never have the crocodile landing upstream of the target. It is fixed in the final version)


UPDATE: I changed the color scheme for better contrast, and fiddled with the scale and offset to show that the discontinuity cusp is still there in the original problem

The discontinuity cusp is at θ = atan(L/W) if there is no drift. Adding drift changes the angle at which the crocodile would swim directly to the target. That is where the run time calculation (the absolute value term in the total time equation) is zero. I'm not sure I can simplify it to a relationship. I can see that Vr divides out, and the angle depends on W, L, Vs, and Vf. Maybe I'll work on it more this weekend.


UPDATE #2: Okay, I worked out the relationship that determines the angle where the discontinuity cusp is. It is a horribly messy quadratic:

The quadratic formula technically has '+ or -', but the '-' case can be discounted because that result is outside of the range the problem makes sense for, [0°,90°). If flow speed (Vf) is zero, this simplifies to cos(θ) = W/√W²+L², which equates to tan(θ) = (L/W).

Aside from the initial minimization that made me aware of the discontinuity cusp , this has all been algebra and trigonometry. Messy, sure, but not actually hard.

So here Use this one. is the final version of my program. Here is a screenshot of the original problem, showing the location of the discontinuity cusp:


UPDATE #(Again? WTF?): It occurred to me that I was using "discontinuity" wrong. The function is not discontinuous, it is continuous but not differentiable at the cusp. So, I have corrected the post.

Note to self: Do not use Blogger's "compose" mode. It adds a ton of weird, unnecessary html to the post.


UPDATE #(Seriously, what the hell is wrong with you?): I couldn't help thinking about the cases where the minimization doesn't apply. It really isn't that mysterious. As Vs approaches (or equals) Vr+Vf, the resulting θ would be beyond the cusp. which means that it doesn't apply. The total time function follows a different curve to the right and left of the cusp. There is actually a discontinuity in the curve. 1/cos(θ) → infinity as θ → 90°. Of course, the cusp usually comes before you get close to the discontinuity, so the minimum time will always be between 0° and the cusp. Well, if the flow speed is high, the cusp calculation can be outside the (-90°, 90°) range. but in that case the function is differentiable across that entire range, and the minimization applies. This got me wondering why my program didn't work for L < 0. It should have been obvious. I was only evaluating the equation for θ in [0°, 90°). If L < 0, θ < 0°. Once I fixed that to (-90°, 90°), I had to put an absolute value on the cos(θ) in the swim time evaluation (even if the angle at which the crocodile swims across the river is negative, the time it takes is still positive). I changed my graphics to reflect the change. So, once again, here is the actual, final version Use this one.
And the obligatory screenshot:


UPDATE #(Holy Shit! You're still on about this?): I couldn't stop fiddling with the program. I added Try-Except statements to the input handlers so that entering bad values wouldn't crash the program. Try it. I also made some corrections to the graph display. So here is the latest 'final' version.
And a screenshot:


Sunday, August 23, 2015

Cherry Marshamallows

This is the sort of thing that happens when I get bored:

The pink mess in the bowl is a previous batch that I left too close to a hot oven, and melted into a gooey pile.  Jac suggests making Rice Krispy treats with it.  I'll probably do that.

The plate on the right has the finished marshmallows from the second batch.  They are dusted in powdered sugar to keep them from sticking together.  They are actually purple, as can be seen on the exposed half-marshmallow.  These are awesome in hot chocolate or s'mores.

The plate on the left has the Frankensteinian remnants, and a few salvaged pieces from the first batch, dipped in chocolate.

The reason the first batch is pink, and the second purple is a change in the recipe. The original recipe called for cherry extract and a few drops of red food coloring.  I used the last of my cherry extract making it.  When I decided to make another batch, I went to the store to get more, but there wasn't any.  So I got cherry juice and substituted it for the water in the original.  I wasn't sure it would work, but I'm pretty happy with the results.  Next time I'll add some extract, too, though.  The cherry flavor is pretty subtle with just the juice.

So here's my (revised) recipe for Cherry Marshmallows.

   Electric mixer
   Rubber scraper
   Heavy-bottomed 2-qt saucepan
   Candy thermometer
   Medium mixing bowl (I prefer one with straight sides)
   Small microwave-safe bowl
   Baking dish (I used an 11"x7" brownie pan)
   Cling wrap
   Chef's knife

   2 lg. egg whites, at room temperature
   1 c. cherry juice (I used black-cherry juice, I think that's why they're purple)
   3 envelopes unflavored gelatin
   2 c. granulated sugar
   1/2 c. light corn syrup
   1/4 t. salt
   1 t. cherry extract (or more for a stronger flavor)
   powdered sugar
   non-stick spray

   Line the baking dish with cling wrap and spray with non-stick spray.
   Mix gelatin and 1/2 c cherry juice in microwave safe bowl and set aside.
   Put egg whites in mixing bowl and set aside.
   Mix remaining 1/2 c juice, granulated sugar, corn syrup, and salt in saucepan.
   Heat on med-high.  Stir until sugar is dissolved.  Insert thermometer.
   Heat to 260°F.  Note - when it starts to boil, it will make a mess if the saucepan is
   too small.
   Watch the thermometer.  When the sugar mixture gets to about 240°F, start 
   beating the egg whites.
   They should form stiff peaks about the time the sugar gets to 260°.
   Microwave gelatin on high for 20 seconds.  Stir to fully liquefy.
   Whisk gelatin into sugar mixture.  Note - this will cause a lot of steam.  Be careful.
   Slowly pour sugar/gelatin mixture into egg whites while beating on low.  Not too
   slowly, if the sugar cools it will harden.
   Add cherry extract and gradually increase speed to med-high.
   Beat until very thick and glossy, 8 to 10 minutes.
   Pour into prepared dish.  Let sit at least 8 hours to allow gelatin to set.
   Dust (liberally) a cutting board with powdered sugar.  Flip marshmallow onto
   board and remove pan and cling wrap.  Dust marshmallow with powdered sugar.
   Cut into strips (then cubes) with chef's knife.  Dust knife with powdered sugar as it
   gets sticky. And it will.  
   Dust cubes with powdered sugar, then brush off excess.


Saturday, May 16, 2015

Quote button

A long time ago, shortly after I added the "new quote" button on my random quote generator, Tom said it would be better to have the button above the quote so that it didn't move every time the quote length changed.  I didn't really care, so I never bothered.  Until just now.


Saturday, March 14, 2015

Happy Pi Day! Key Lime edition

Preheat oven to 350°F

    1+1/4 c. graham cracker crumbs
    2 T. sugar
    1/3 c. melted butter (unsalted)

    mix together and press into pie plate.
    bake 10 minutes, let cool

    3 egg yolks
    1+1/2 t. freshly grated key lime zest
    1 can (12oz) sweetened condensed milk
    2/3 c. freshly squeezed key lime juice

   Beat yolks and zest on high for 5 min
   Add condensed milk and continue to beat 4 more minutes
   Reduce speed to minimum.  Slowly pour in lime juice.  Stop when just combined

Pour filling into pie shell.  Bake 10 minutes.
 (if, like me, you made the shell too deep, and there isn't enough filling, make another batch, pour that into shell (pour any excess filling into a ramekin for a key-lime custard).  Bake another 10 minutes. )

Sunday, April 06, 2014

Manhattan clam chowder

I felt like making some Manhattan clam chowder for lunch, but I didn't want a lot of leftovers, so I cut the recipe back to make two servings.

I made an incredibly fortuitous mistake.  I wasn't paying attention at the store (big surprise) and grabbed a can of diced tomatoes with habaneros instead of plain.

It was awesomely spicy.

So, for posterity, here's my recipe for Manhattan clam chowder

Manhattan clam chowder
   - 2 fairly big servings. (You could reasonably call this 3 servings, 4 would be
          pushing it)

2 strips thick sliced bacon
1/4 c onion, chopped
1/4 c red bell pepper, chopped
1/4 c carrots, chopped
1/4 c celery chopped
2 cloves garlic, chopped or pressed
1 T Italian seasoning (just oregano would probably be fine)
1/4 c dry white wine (I use Chardonnay)
1/2 c clam juice
1 T fish sauce (you might need to visit an Asian market for this)
1 bay leaf
1 small potato, cubed (about 1/2 c)
1 can (10 oz) diced tomatoes with habaneros (do not drain)
1 can (6.5 oz) chopped clams in clam juice (do not drain)
salt and pepper to taste
fresh parsley, chopped

Fry bacon in heavy skillet until crisp.  Remove, drain, and crumble.
Add onions, bell pepper, carrots, and celery to bacon fat.  Reduce heat to low,
     cover, and cook until tender (about five minutes)
Turn heat to medium, add garlic and Italian seasoning.  Sauté about 2 minutes
Add wine and cook, stirring occasionally, until liquid is reduced about half
Transfer to a 2 qt saucepan, add clam juice, fish sauce, bay leaf, potatoes, and
Bring to a simmer, reduce heat to low, cover and let simmer for 30 min.
Add clams and bacon, continue to simmer for about 10 more minutes.
Add salt and pepper to taste.
Garnish with parsley and serve.

I ended up eating both servings.

Friday, July 19, 2013

Today's rant:

Okay. Listen to this:

That's "Hail to the Geek" by Deaf Pedestrians. Funny song. Here's the problem: There is one verse that applies to me. And they get it way wrong.

I play Dungeons and Dragons
I got a 13th level halfling fighter-thief
Got seven hit die on the backstab
Sometimes you know it's good to be a geek.
"Fighter-thief" and "backstab" indicate that he's playing 1st or 2nd edition AD&D. But backstab was a damage multiplier. A 13th level thief would have a backstab multiplier of x5. When Wizards of the Coast acquired D&D and released 3rd edition, "Thief" became "Rogue", "backstab" became "sneak attack", and the damage multiplier became extra dice.

But it get's worse.

1st and 2nd edition were kind of vague on multiclassing, but even so, the classes were treated separately and most DM's just made players split xp between classes, which, given the different xp requirements (thieves gained levels much faster than any other class), normally resulted in a staggered advancement. "13th level fighter-thief" is pretty much meaningless. In 3rd edition all classes used the same xp table for level progression, and the concepts of character level and class level were specified. So "13th level fighter/rogue" would indicate a character level of thirteen, but says nothing about the level of each class. The character would be listed as (for example) a "3/10 fighter/rogue" instead. However, given the "Got seven hit die on the backstab" line, the character would need 13 rogue levels to have a sneak attack of +7d6, and would have no fighter levels.

Which brings me to my last point:

"Die" is singular. "Dice" is plural. No D&D geek would say "seven hit die", and many might become violent upon hearing it. "Seven hit dice" is correct.

As Jac said once: "You're going to have to try a lot harder than that if you want to be a geek at this table."


Saturday, August 25, 2012

RPG Test (from Dragon Magazine, December 1987)

I used to subscribe to Dragon, back in the mid-80s. I do remember this test.

Take this exam and join the adventuring horde! 

Dragon Magazine DECEMBER 1987
by Lawrence R. Raimonda Times are hard, and adventures promising wealth and fame are few and far between. How can you make sure that you are right for the adventurer's life? How? It's easy! Here at the Greyhawk Institute for Adventurous Neophyte Training, we have come up with the sure-fire solution: the Superior Personality Under Development course. That's right! Personality is the key to conquest! It's the real reason one fighter is chosen over the other when adventuring groups are formed. Are you too sophisticated for hack-n-slash? Do friends call you "stupid" as a compliment? Do rabid orcish marauders think of you as being too aggressive? No problem! At the Greyhawk Institute for Adventurous Neophyte Training, we'll put you through an intense program of classroom instruction and on-the-job training. Also, at no extra cost, you will receive our Superior Personality Under Development study guide. Just take a few minutes and fill out the following application. You can't afford to pass this opportunity by! 1. You've just arrived in a new town. You immediately: a. sigh in relief. b. find the nearest tavern. c. strip down to your underwear. d. do all of the above, to start with.
2. Wizards are: a. snappy dressers. b. valuable allies. c. awful darn cute. d. awful darn cute on the end of a spear.
3. What's the best way to test for trapdoors? a. With eyes shut. b. Make the half-ogre go first. c. Jump up and down a lot. d. Burn the place to the ground.
4. It's late at night, the moon is full, and you notice that your partner is turning hairy. What do you do? a. Compliment him on his coiffure. b. Whip out the scissors and wolves-bane. c. Check your pack for doggie chow. d. Join him.
5. A portable hole: a. a day keeps the ogre away. b. comes in handy in the king's treasury. c. What? d. holds a lot of beer
6. Given the choice, you'd rather have: a. Lint-free chain mail. b. 1,000,000 gold pieces. c. A chocolate-chip cookie. d. A sword and a major land war.
7. Describe a hill giant. a. A large, smelly Muppet. b. Big, hairy, ugly, and strong. c. Your last blind date. d. All of the above.
8. You are in a cave when your torch goes out. You: a. scream. b. cannot see. c. hit your head. d. throw the torch away and continue on ahead.
9. Your deity tells you to walk on hot coals. You promptly: a. practice shouting"Ouch! Ouch! Ouch!" b. get a new deity. c. invite your friends to a cook-out. d. attack him.
10. You find out that the ship you are on is manned by vicious, savage buccaneers. You: a. double-check the travel brochure. b. swim for shore. c. taunt them. d. join them.
11. What makes your mouth water? a. Vichyssoise. b. A leg of mutton and a jug of mead. c. A burger and fries. d. A dead brontosaurus.
12. What is a bard? a. A sophisticated, wandering musician. b. My DM doesn't allow them. c. A piece of lumber. d. The hair on your face.
13. What scares you the most? a. Gross, icky, crawly things. b. A tribe of bloodthirsty primitives on your doorstep. c. An umber hulk in leotards. d. Mom.
14. Which would you take as your share of the loot? a. Gems and jewelry. b. A treasure map. c. A wooden nickel. d. The loot.
15. Someone in your party is a thief. It's probably: a. that mysterious, cloaked stranger. b. the dwarf with his hand in your pocket. c. your horse. d. all of the above. [e. You -- added for accuracy in my case]
16. You are trapped by a cave-in. You immediately: a. scream again. b. try to dig your way out. c. choose the best position to be found in. d. kill the fool who knocked over the support beam.
17. Your favorite choice for a pet would be: a. a gerbil. b. a war dog. c. a dung beetle. d. a mammoth.
18. How can you detect for evil alignment among your henchmen? a. Look for bad penmanship. b. Cast a spell. c. Flip a coin. d. Use torture.
19. What is the first thing you should say when you spot a bugbear? a. "So, how does my leg taste?" b. "Don't come any closer! I've got a sword! " c. "Nice ears" d. "Yo! Ugly! Let's party!"
20. If there's anything you hate, it's: a. mismatched armor. b. being drawn and quartered. c. the letter"c." d. not got long to live.
21. Witches: a. make great gingerbread. b. aren't allowed in my DM's campaign either. c. Where? d. don't wear underwear.
22. There's nothing more exciting than: a. the full moon at midnight. b. the thrill of victory. c. answering this question. d. hand-to-hand combat with a thousand cannibals.
23. What heals all wounds? a. Thyme. b. Time. c. Tyme. d. A week in a harem.
24. Select a title for yourself. a. Gerard the Thoughtful. b. Lars the Mighty. c. Fred. d. The Terror of Morovia.
25. Keep an eye on your fellow traveler. He might be: a. a barbarian. b. a thief. c. a Democrat. d. Demogorgon.
26. A princess is trapped in a dragon's cave. You should: a. ask someone to help her out. b. rescue the princess. c. rescue the dragon. d. rob them both.
27. What's the most important thing about making camp? a. Keep the marshmallows in a clean, dry place. b. Keep the fire low and post guards. c. Have appropriate party games. d. Have the others do all the work.
28. The best kind of partner is one with: a. a warm personality. b. a good sword-arm. c. a game of checkers. d. a keg of ale.
29. If you had to choose one of four doors before you, which would it be? a. The door out. b. The treasure-room door. c. That one. d. The booby-trapped door.
30. In matters of life and death, you should: a. choose life. b. avoid death. c. dress warmly. d. Loot and kill and pillage and burn.
31. You find the thief who stole your horse, money bag, and provisions. You then: a. count from 1 to 10 before speaking. b. demand your belongings back, or else. c. give him the rest of your things. d. turn him into lasagne.
32. Before you'd ever abandon your friends, you'd rather: a. kiss a goat. b. slap a sunburned frost giant on the back. c. get permission first. d. get all of their money first.
33. "Halt!" means: a. "Surrender! " b. "Stop! " c. "Hello! " d. "Attack!"
34. If asked what your price is for a dirty adventuring job, what do you say? a. "Lunch at the Bulette Cafe." b. "The going rate." c. "I'll pay anything!" d. "How much have you got? Your family, then how much have they got? Mmm. Got any sisters?"
35. You find yourself alone and unarmed in a cave with 100 hungry carnivorous apes. What is your next move? a. Hide. b. Hide. c. Hide. d. Fight.
36. You must never forget: a. to clean up afterward. b. your spells. c. the . . . the, uh . . . uh . . . d. to check for treasure.
37. The best way to handle a poisonous spider is: a. from afar. b. with a glove. c. by blackmail. d. with a hammer of thunderbolts.
38. An ogre invites you to dinner. You should: a. check his references. b. decline. c. accept. d. show up wearing your best ogreslayer
39. You find a dwarf chained in a cell. He says that he'll lead you to lots of treasure if you release him. You should: a. think about it. b. insist that he reveal the whereabouts of the treasure first. c. attack. d. release him.
40. There is a disguised dragon in the room. It must be: a. the terrier in love with your leg. b. the cow breathing fire. c. disguised. d. ready to die.
41. Your castle has been overrun by hobgoblins. You've been fighting and running from them all day, and have finally managed to hide from them. Then, your henchman knocks over a vase. You then: a. soil your pants. b. grit your teeth and ready your weapon. c. fix the vase. d. throw the henchman out into the hall.
42. You are trapped in a 10' x 10' room, and the walls are closing in. What do you do? a. Yell for help. b. Use a dagger to jam a wall. c. Leave. d. Wait for the hangover to pass.
43. What's the best way to catch a golem? a. Set out a saucer of milk. b. Dig a humongously deep pit. c. Is that a disease? d. Wrestle him down and hog-tie him.
44. What's a good sign that you've had too much to drink? a. The room is spinning. b. A wench is leaving the room with your money and your clothes, and you are smiling. c. You're out of milk. d. Your boots are covered with your dinner.
45. What's a druid good for? a. Flower arrangments. b. Nature spells. c. Beats me. d. Calling forest creatures for target practice.
46. If you were told that a treasure lay in a hole in the wall, would you stick your hand inside? a. No. b. Maybe. c. Inside what? d. Yes.
47. How strong are you? a. Not very. b. Above average. c. Not very; just had a bath. d. Damn strong.
48. Do you think there should be rights for orcs? a. Yes. b. No. c. Maybe. d. Sure: rights, lefts, right crosses, left jabs, right uppercuts....
49. Describe a daring deed. a. Inviting a goblin to a tupperware party. b. Facing a tribal chieftain in single combat. c. Housebreaking a hell hound. d. Leaping off a burning battlement into a crocodile-infested moat in front of an army of orcish archers.
50. What is the best thing you can say about skeletons? a. They make great tap dancers. b. They don't have many hit points. c. They don't eat much. d. Some of my best friends are skeletons.
"In just seven days, I can make a man out of you, unless of course you're a woman, which might make this all rather problematic." -- Rogar of Mooria, GIANT faculty member, Evaluation If you answered 30 or more questions with the same letter, then it is likely that you fall into a particular category of adventuring types. These are listed below: Type A: You're perhaps a little too civilized for most adventuring groups, but not beyond hope. You are certainly in need of personality development before being considered ready for any serious undertaking. Practice going without bathing for short periods of time, grimacing in a mirror, and not fainting at the sight of blood. Type B: You're probably referred to as dependable," "practical," "an OK guy," etc. There is not much wrong with you, and you should do well in the adventuring life. We recommend that you take our accelerated S.P.U.D. program. Type C: My, my. We are having a rough day, aren't we? This exam was probably tiring, but take a few minutes to rest and relax. When you're feeling better, take out all of your money and mail it to us, right away. That's right: every copper piece. Good, good. We're proud of you. Type D: Well, it appears that you have probably done more than your share of adventuring, and there's not much more we can add to your training. In fact, if you have some free time, we'd like you to join our teaching staff. Sure, others may call you a bloodthirsty maniac, but hey, who cares? We'll give you a portable hole full of beer and a major land war. Where can you beat that? You're darn right. Remember: Time is limited! Join the ranks of the G.I.A.N.T. graduates, and stand tall! Get out your crystal ball and call today for your first class! Sorcerers are standing by.