Friday, January 8, 2016

Dealing with Black Uncles

The Rules:

1. a node is red or black
2. root is black
3. all leaves are black (null pointers count as leaves)
4. red nodes can only have black children
5. every path from node to leaves must have same # of black nodes (i.e. "black height")

The rules that matter:

4.  red nodes can only have black children
5. every path from any node to the leaves must have the same # of black nodes (black-height)
*.  (make a new node start out red)


x = the new node (or the node you recursed on)
p = new node's parent
u = new node's uncle, sibling of p
g = new node's grandparent



Root
Make it black.


Any Black Parent
You are done.


Red Parent, Red Uncle
Recolor, recurse on g



Red Parent, Black Uncle, Left-Left
R-Rotate(g)
recolor p, g



Red Parent, Black Uncle, Right-Right

L-Rotate(g)
recolor p,g



Red Parent, Black Uncle, Left-Right
L-Rotate(p)
Follow Left-Left procedure...



Red Parent, Black Uncle, Right-Left
R-Rotate(p)
Follow Right-Right procedure




Tips

You only need to get involved when the parent is red, and that is only difficult when you have a red parent AND a black uncle.  In that case there are four cases, but two of them (the ones with both 'right' and 'left' in the title are just an extra step on top of the others).

Now as far as remembering this shit for longer than a week...I have no idea.















Saturday, December 19, 2015

TIFU

Vodka and I are no longer best friends.

Thursday, December 10, 2015

[fiction] Eve's Sacrimony (alternate ending)

"I fight for my country, not it's government."
--Biff


"We are gathered here today-"

"Snow, stop," said Lawrence.

"What?"

"You're not doing this with that hat.  You're just not."

"You wanna do this?"

"Yes."

"Oh...ok."  Snow stepped down from the podium.

Lawrence stood up, glared at Snow, and then looked out at the few people clustered just inside the walls of Ravenhead castle.

"I am sorry for all of the secrecy..." Lawrence trailed off.  "Wow I don't know how to even begin."

"I was doing way better," said Snow.

"SHUT THE FUCK UP" Nikka shouted directly into Snow's ear, and kicked him in the balls for good measure.

Lawrence sighed.  "A few days ago, a teenage woman was pulled out of the line at the airport by TSA agents and raped.  There wasn't anything particularly abnormal about it, except that they failed to close the soundproof doors and Biff heard her screams.  He manually disabled about fifty TSA personnel and one police dog before being gunned down by airport cops.  Sadly, both Biff, and the woman he was trying to aid, were killed.   I'm sorry for all the secrecy;  obviously we aren't supposed to have the body, so this had to be a little clandestine...."

Lawrence turned around to raise the lid of the casket and jumped when he saw the woman standing there, just inches away.  She was dressed head to toe in black:  black boots, black dress, black corset, black hood, black gloves.  And she looked amazing.  Also she was crying.  Lawrence decided maybe not to open the casket.




Sometime later, when almost everyone had left, Snow and Nikka were watching the casket, waiting for the woman to leave.

"It seems so sad," said Nikka, "to go out like this.  Remembered briefly in the dark, and then gone."

Snow looked at the woman standing next to the casket.  "I don't know," he said.  "I think having just one person stand there like that means it was all worth it."



Lawrence approached the woman.  "You must be Eve."

"Yes."

"Snow and I need to lower him into the ground," said Lawrence.  "Normally people don't stay for that."

"There is a legend," said Eve, "about the water tunnels under this place.  Are you familiar with them?"

"What, you mean 'The Knight and the Widow' ?  Of course.  Why...wait.  No.  Really?  No."

"I'd like to do it."

"I don't uh..."  Lawrence started to protest by Eve turned her head and looked at him.  For a second it felt like her eyes were drilling through his skull, and piercing his soul like a tank round in concrete.  Lawrence suddenly felt an uncontrollable urge to shiver.  "Let me talk to Snow."



"What exactly is this ritual?" asked Nikka.  Her eyes were drawn towards Eve, who was in the middle of the courtyard, shamelessly stripping down to her underwear to and putting on the pink riding suit.

"Oh are you sure you don't want Lee to explain it?"

"Shut up and tell me," said Nikka.

"Well there was this guy, right?  He was a pretty cool dude.  He was like a knight and shit.  And he was doing some knighty shit when he got killed.  But there was this woman...wife or girlfriend or lover or something.  Oh wait, back up.  So the knights here had a tradition that they would be floated out to the ocean when they died.  I don't know why.  Ok, back to the girlfriend.  She was still alive, but she went with him."

"And then?" asked Nikka.

"I don't know.  I guess stuff happened.  All the stuff at the end was just a bunch of bullshit about peoples' feelings, so I never paid attention."

"What?"

"I mean the guy's already dead, so there couldn't have been any fighting.  Who cares what happens?"

"I care!"

"Well go read the legend yourself, bitch."

Nikka punched Snow in the throat.  "Don't call me bitch, bitch!"




Thirty minutes later, Snow, Lawrence and Eve met for the last time in the caverns below the castle, at the underground dock.  There was a barge with a mattress in it and a candle at each corner.  Eve took her sword and laid it on Biff, wrapping his arms around it.

"Now isn't that sweet," said Snow.

"Has anyone ever told you that you're an asshole?" asked Eve.

"All the fucking time," said Lawrence.

Eve got in the barge.  They started floating with the current.

"We'll send someone down river to pick you up," called Lawrence.

"Don't bother," called Eve.

"Wait what?"

"I won't be there."

Snow and Lawrence looked at each other, and then back at barge as it rounded a corner.

"Sooo..." said Snow.

"Is she..." asked Lawrence.

"Yes," said Snow.  "I like her."




Eve tied her laces around each arm, and then pulled her switchblade from her boot and flicked it open.  She had never really thought about ending her life--never really considered it an option.  I mean what is the point?  But after everything that had happened recently, she couldn't help but feel lost and alone.  And now she really was alone.  Even in the most crowded of places, she was alone, watching all of the people who weren't alone as if she was looking in a store window.  She looked down at Biff's face.  "Well, here goes, sugar."  She made a big ass vertical slice from her armpit to her wrist, following the exposed veins as best she could.  The pain was...well, she had felt much worse.  Once her right arm was done, though, she found she couldn't bring herself to hold the knife in her right hand, so she held it in her mouth and did the best she could to her left forearm and wrist.

Her biggest fear was failing to do it right, and to be found alive with blood pouring out of her arms like an idiot.  That worry soon gave way to peace as she grew colder and colder, and then lightheaded.  She lay down next to Biff, one hand touching his arm.  He was cold.  Just like she was.

Eve closed her eyes.

She was dimly aware of the motion of the boat, still, bobbing ever so slightly in the water.  It wasn't a particularly flattering passage.  She had assumed things would proceed roughly like a ride at a waterpark, but they weren't exactly always going "forward" because boat kept rotating randomly in the water.  At one point it felt like it was going backwards, and somewhere in the back of her mind Even thought they had gone down the wrong passage.

The sense of being in the wrong place, of being lost, magnified more and more until Eve opened her eyes.  When she did so, she found that they were enveloped in mist.  There did still seem to be an echo but she couldn't see the walls.  And she didn't feel cold anymore.

The boat continue for what seemed like an eternity.  Then something began to take shape in the fog. And everything seemed to get brighter.  She saw it;  it was a beach.  The boat continued to float lazily, then seemed to magically beach itself on the sand.  Someone approached out of the mist.

She was tall, blonde, and most importantly, was wearing a pink riding suit exactly like the one Eve wore.  And she was smiling.

"Welcome," said the woman.  "I'm Christine."  She held out her hand.

Eve's mouth dropped open as she took Christine's hand.

"Yes, I know.  It's a little disorienting."

Eve heard something move in the boat.  She turned and saw Biff standing up.  She jumped and tackled him, holding on as if for dear life.

"Woah there!" said Biff.  They held each other for a few moments, until they each felt Christine's hand.

"It's ok," said Christine.

They stood up.  "So we're dead?" asked Biff.

"From a certain point of view...to everyone who isn't yet, yes you are dead.  But obviously not gone."

Eve asked "So we're in..."

"The gathering," said Christine.  "Come on, I'll show you."

They walked up the beach.

"I don't feel dead," said Biff.

Christine laughed and pinched his ass.  Eve felt a surge of jealousy, but then paused to wonder why it was possible to feel jealousy in the afterlife.

They reached the top of a hill.

"I can see dead people!" announced Biff.

"How can you joke at a time like this?" asked Eve.

"This," waved Christine, "is the gathering.  It is where we wait."

"For what?" asked Biff.

"To enter the Timeless Halls, when the world is unmade," said Christine.  "Don't worry; it's not a long wait.  Time works differently here."

"They're going to let me in?" asked Biff.

"It can't be that classy if I'm going there," said Eve.

Christine smiled and hooked both of their arms with hers.  "Actually, there are several angels who are just dying to meet you--both of you."

Sunday, December 6, 2015

[fiction] Eve Takes Command (alternate ending)

I don't want to live in a place where the cops are the only assholes with guns.
--Snow Monkey



The stadium floodlights were light at the their brightest setting, shining down on the thousands of people sitting on the field, all facing raise podium at the center.  In front of the podium, 13 holes and been dug, 13 men chained in those holes, and 13 piles of sand had been back filled into those holes so that only the men's heads were above ground.

Two men stood at the podium.  One spoke.  "Good evening, ladies and gentleman.  I would like to formally welcome you to another co-ceremony by Comcast," the speaker smiled at the man at his right, "and Time Warner.  The people before you here today were all part of a terrorist plot to undermine the safety of this nation by creating an unsanctioned, unauthorized computer network that bypassed our data caps and traffic filtering.  Make no mistake, this was not the only dark web pocket in this country, and it is not the last.  But we are getting better and better at finding them and," the speaker looked to stage right, where the police chief was sitting on an industrial sized riding mower, "punishing those responsible."

The crowd sat still, very still, with the exception of some children who were crying.  Most of them couldn't actually see the men mostly buried in sand, and didn't really want to either.

"Please remember," said the speaker, "that attendance of this ceremony is mandatory, as per your internet end user license agreement.  If any of you should try to leave, these officers," the speaker motioned to the 60 cops surrounding the crowd, "will shoot you and five people next to you."  It is likely that the speaker mentioned that fact out of cruelty, since every member of the audience was handcuffed--both wrists and ankles--to their chairs.

"Also please be advised that we have borrowed 3 kill teams from Monsanto who are camped out in the upper stands, so there is no need to worry about any vigilante--I mean terrorist, attack interrupting the proceedings."



Somewhere under the stands, under a tarp covered in dirt, a tiny radio squawked:  "Night Witch, you're up."   Eve opened her eyes.  After 36 hours of lying absolutely still, consuming a disgusting food paste out of a straw and peeing into a bottle, she slowly slid out from under the tarp and stretched.

Less than a minute later the Monsanto goon in section 37 looked down to find a sword sticking out through his chest.  He tried to grunt but there was a gloved hand over his mouth.  Eve lowered him to the ground slowly and moved on to her next victim.


Back in the stadium, the speaker had finished his short speech, and the Chief of police started the lawn mower.  Just as he turned the key there was a large cracking sound, as if the mower had backfired.  However one of the cops doing crowd control suddenly fell down without his head.  The Chief urged the mower forward, over the terrified head of its first victim.  There was a loud crunch, and suddenly the dismembered head flew out of leaf trap and into the crowd, knocking an old woman unconscious.  Somewhere in the back another cop fell.

The impact of the head had no effect on the speed of the mower, which continued towards the second sand victim.   At the other end of the field, a black muscle car appeared.  The speaker and most of the cops started shouting, but the mower was too loud for the chief to hear.  The chief mowed over the second "terrorist" as the black muscle car shot across the field.  Gun flashes lit up the outer stadium seating like fireflies as hundreds of well-aimed bullets pummeled through the bullet resistant glass, ripping everything in the driver position to shreds.  But the car didn't stop.

The car t-boned the mower at 90 miles power hour just as the third head was flying out of the leaf trap.  Both vehicles tumbled into a corner of the crowd, killing tens and injuring hundreds of people still handcuffed to their chairs.  When the car came to rest the cops surrounded it, all firing their sidearms into the car.  When their clips were empty, one of them walked up to the car and looked inside.

"There's no one in here!" As the cop spoke those words, a 50 caliber bullet tore apart his entire upper body.  A smaller rifle killed another cop.  The remain cops then turned and saw the growing body count thanks to the unknown snipers.  Atop the announcers box, Lawrence and Jason lay prone, reloaded.  A bullet stuck near them, showering them in splinters.  Lawrence clicked his radio and screamed:  "God dammit Night Witch move your fucking ass!"




Eve raced along the upper seating, running as fast as she could, barely slowing to decapitate each sniper with her sword.  She had watched carefuly for the muzzle flashes when they had fired on the car, memorizing every position, but it was still the hardest sprint she had ever done.  Her lungs were on fire, her legs felt like rubber, and the bones of her arms ached from every sword thrust.  When she reached the home stretch, with only the end zone to go, the sword got stuck in one of their necks, and she had to resort to her sidearm.  As soon as she killed the next one the muzzle flashes were pointed at her.  She dodged up and down the seats, jumping and ducking, until she ran out of bullets and was pinned down on the floor of the last section.  There were three men left.  She threw a grenade.  Actually she threw all of her grenades.  The shrapnel was still falling when her watch beeped, signaling that her time window had expired.

She stood up, looked towards the crowd of people, and screamed.



In the middle of the field, the Comcast rep lay clutching a stomach wound, but the Time Warner rep stood, unscathed.  He pulled his sidearm off his belt, and, as the carnage rained around him, calmly sent one bullet into each of the 10 remaining "terrorists."   Just after he killed the last one, Eve tackled him, snapping his neck before he hit the ground.



Eve fell to her knees when she reached Aaron, one of the last few sand victims.  Her body shook violently with sobs, her tears streaming down like a river as she stroked his hair.  The life was already gone from his body;  his entire left eye and a good chunk of his face was missing.  Yet still she cradled him, careful not to cause any more pain.

Soft footsteps approached but Eve didn't look up.  Snow stood there, ten feet away.  He didn't say anything.  Words at a time like this were for crybaby extroverts.  Instead, he observed, and shared, her grief.

Behind him, Jason and Lawrence and the others were busy un-handcuffing the hostage audience, loading them wounded-first into whatever vehicles had been procured at such short notice.

Much, much later, when the work was done they came to the sand line to interrupt Snow's Zen.

"Foul deeds," said Lawrence.  "And all 13...with everything we had we didn't save a single one."

"We failed," said Jason.  He looked behind him, at the shocking number of dead.  "We were supposed to stand between the cops and the people.  If we had done nothing.."  he saw Eve's shoulders tense, and stopped talking.

Snow looked at Lawrence.  "What's the plan, boss man?"

"We did very well," Lawrence said.  "It just wasn't enough.  We keep going like this; its like betting against the house.  No one ever won a war with ninjas--not in the 5th century; not now.  Muscle cars and true grit aren't enough to stop a State that can control what you see, what you hear, listen to every phone call, text, and tweet you make.  If Biff really is still alive..."  Lawrence trailed off when Eve looked up.

Her eyes were red.  Bright red.  Like a demon.  And her voice was horse and guttural.  "I am going to tear this city apart," she said,  "until I find him."  She stood up.

Snow looked at Lawrence, then at Jason, and then back at Eve.  He hoisted the 50 cal onto his shoulder and said:  "Where do you want us?"


Saturday, December 5, 2015

[fiction] Eve's Commitment (one possible ending)

Snow: This suite has been booked for three weeks.  There's two thousand in cash in the dresser, and a credit card with a really, really high limit.

Eve:  This is a little...I can't accept all this.

Snow shrugs.

Snow:  It's Dave's money.  Spend as much as you can.

Eve:  I can't just sit here mooching off of someone

Snow:  Yeah I know its not like the best plan, or whatever.  But everyone is coming together for this.  Everyone had their own job.  Dave's was funding this whole operation.  Lawrence tracked the final book to this city--he'd stake his life (and mine) on it--and Jason...well Jason's too pussywhipped to really do anything useful.

Eve:  Oh?  And what was your "job" ?

Snow:  Finding you.

Eve gets a knowing look on her face.

Eve:  Because my job is...

Snow:  Finding Biff.  You're the only one who can.

Eve:  What?  I've never even been here.  What the hell am I supposed to do?

Snow:  I don't know.  Use that magic girl intuition of yours.  Or post flyers.  Or go to every shitty bar in the city, every night.  Whatever it takes.  You know Biff needs to regularly hang around smoky dive bars so he can sip lite beer and be a sad panda about Christine.

Eve:  Takes a lot of nerve for you to bring her up again.

Snow:  Hey, she's dead but she's not going away.

Eve: And I don't want to just be sloppy seconds!  To have him constantly comparing me to her...oh God why did I come here?

Snow:  Let me let you in on a little secret about Christine.  Christine was an average, ordinary, scared little girl hiding behind the shadow of her legend.  That's not an insult.  She was a friend.  Like I wasn't even trying to fuck her--that's how much friends we were.

Eve rolls her eyes.

Snow:  But all that shit about the pink rider...sure she mostly did some version of most of those things, but when we were sitting around talking shit about what we'd do, she was the first one to roll her eyes.  The fact that she played hard to get on that motorcycle and accidentally had Biff out there searching for her like a horny dog is really what got the legend going.  But that wasn't her.  She wasn't made of steel.  She was just a normal girl that liked to ride a little and was infatuated with Biff.  You, though....

Snow looks her up and down.

Snow:  I don't know what happened you, but something made you the badass road witch that people thought she was.  And I'm 90% sure that you're in love with Biff.  So you are going to find him, even if you spend every waking moment searching.

Eve looks out the window.

Snow:  Ok good talk.

Snow gets up to leave

Eve:  How do you know?

Snow:  Hmm?

Eve:  That I love him?

Snow:  Cause you're still wearing that suit.




----------------------------------------------------

Jason follows Lawrence into Wilson's Tire and Garage.

Lawrence:  This.

Jason:  Holy fuck!

There are hats everywhere.  Silly or otherwise unusual hats of every kind.  Pirate hats, pope hats, pimp hats, tircolour hats, cowboy hats, costume hats, helmets,  fedoras, sombreros, bowlers....

Jason:  This is like his entire collection.

Lawrence:  And its in my garage!

Jason:  I'm going to try calling him again.

Jason dials.

Moments later a phone rings.

Lawrence:  I hear ringing.

Jason:  His phone's here.

Together they move through the garage, listening, converging on a hat in the middle.  Its a red and yellow "jester" hat that looks like it was pulled from a medieval cartoon.

Jason lifts the jester hat.  Lawrence grabs the phone.

Lawrence:  there's nothing in here.  His phone is like empty.  No contacts, to texts, no history, nothing.

Jason:  Well....I guess he's sending a message?

Lawrence:  I guess....

Jason:  Well I gotta be getting back.  Tonight is movie night...

Lawrence:  I know, I know.  I think I'll take the night off.

Lawrence switches off the light as they leave.

Jason's little brother meets them in the parking lot.

Little bro:  You guys aren't hanging out?

Jason:  Not tonight.

Lawrence:  Hey

Lawrence tosses little bro the keys to the shop.

Lawrence:  take some cars out and get into trouble.

Little bro grins



-------------------------------------------------------------

Eve sat at the desk in her hotel room, half ignoring a police scanner.  A projector on the bed was plastering a news station onto the window curtains.  Uneventful.  All of it.

On the table was a map of the city.  Every dive bar was circled in red, every whorehouse in purple.  Eve had no particular reason to think that Biff would hire a hooker, but hell, he was a man.  With Nikka's help she had befriended as many hookers and strippers as she could, but none had seem him.  This motherfucking bastard was a fucking ghost.

But he was still here.  The last book was here, and he would be here until he found it.  And he hadn't found it yet because there had been no breaking news story about a major shootout or a car chase or a "terrorist plot" or some other big nonsense.

The other option was that he was dead.  He could be dead.  He wasn't invincible.

Eve sighed and looked at her bag of weed.  She had only bought it in case she needed some wild, out of the box ideas.  Tried it once hoping that her mind would be opened and think of some super creative, crazy idea for finding him, but instead she had just eaten 2 and a half pizzas and fallen asleep, waking only to the sound of her own farts.

Eve shrugged.  She had no other ideas.  She would try the weed again.

She rolled a fresh joint and went out to the balcony to light it.  That's when she heard it.  That engine.  It was a four-stroke, but too high to be a car.  And it was that four stroke.  She knew the bike that made that sound.  She knew every inch of that bike.

The rational part of her mind suggested that it might not be Biff, but the rational part was not in control...was more of an unwilling passenger to the person who barreled through people in the hallway and ran through the hotel's kitchen knocking several people over before setting off the fire alarm by going through an emergency exit.  It was the quickest way out.

She was on her own bike now, racing through the street.  Her Aprilia had a much deeper roar, but despite the lower pitch it was still drowning out the faint sound of her quarry.  She had to follow a maddening pattern of racing along a street, stopping, and turning her engine off.  On the bright side, she had spent weeks driving all over this fucking city.  She knew the roads.  And when she heard that familiar high pitched wine somewhere near River Drive, she knew exactly where that bike was.

Eve started her bike, gunned it, spun in place, and rocketed off heading south to accelerate so fast that she popped an unintentional wheelie.  When the bike was under control again it was a hard left, some scary shit on the wrong side of the road, then some crazy shit through an active intersection.  Thankfully there were apparently no cops there.

Then she was in a deserted section of town.  It figured he'd have a hideout in a place like that.

Eve saw the other bike when it was a mile away.  She braked hard, then did a hard left and straightened at the last second to pop over the median.  She stopped her bike and got out.

Snow was dead right, but he had missed something.  Yes, she was made of steel.  More importantly, Biff was the scared one.  He wasn't scared of people, or even of dying, but he was scared for everyone, and running around alone trying to fix the world.  And that, really, was the key.

Eve took her helmet off and stood in the road, legs apart, hands on her hips, staring at the oncoming rider, the way a cowboy stares at stampeding cattle.  The rider should have been able to evade her easily but he was riding with one hand.  He shifted his weight to go around her but she stepped just as he went for it.  He braked and skidded to a stop.

The man who got off the bike was the right height and build.  Maybe a bit thinner than she remembered.  His suit was torn and a few pieces of armor were broken, and he was favoring his left leg.  In one arm was a large black book.  He took his helmet off.

It was Biff.

Bleeding and dirty, with a cut lip and messed up hair, but it was him.  He stared at her widly, his eyes partly unfocused, like he was still in battle mode.  Whatever the hell he had just done was probably just hitting the news now.  Adrenaline was probably still in his bloodstream, his heart probably racing, his mind probably still switching gears to figure out how to corral her.  Not this time.

Eve had no adrenaline rush and her heartbeat had barely flinched.   "Biff Becker!"  she said as he stepped forward.  "Is that the last one?" she asked, pointing to the book.

"Yeah," said Biff.

"Then you're mine," snapped Eve.  She lunged forward, grabbed him by the collar, and kissed him.

Monday, November 30, 2015

Sunday, November 29, 2015

Operation Shelf Life: Part 3

Prototype #2 is a success!  Mostly.

I made two units.  This picture shows them stacked in "shelf mode" with the lids in between the fucking shelves.



This is a top down view of the units separated and rotated on their backs for trunk mode.  One of them has the lid in place, the other has the lid laying over the opening:



As I expected the fit is extremely tight because the pieces are design to fit perfectly and its a vertical drop.  So for the next version I will probably need to introduce a slope to the piece edges that go inside each other.

As simple as this looks this design is actually incredibly complicated--there are a ton of edges and, as I discovered with my first prototype, a surprising number of them need to be matched perfectly.  Oh, you know what?  According to wikipedia these little ridges are called flanges.  Honestly that might be the first time I heard that word used correctly.

In addition to the sloping I need to also figure out how the trunk lids will be secure.  It kind of defeats the point if you have to get the packing tape out.  Deciding how to secure depends on first deciding whether to make it out of wood, plastic or metal.  Which brings us to the part that I know almost nothing about.

Oh shit...AND it needs handles.  Each side of each unit will need two:   one facing up in shelf mode, and one facing up in trunk mode.  They should probably be recessed for better stacking.  And we might want something even fancier to facilitate turning them sideways while the contents are still inside (since that is the whole point of this).




[Update]
Adding slopes has been more difficult than I thought.  So now I'm really just working my way down this list.

TinkerCAD doesn't seem to have a crop feature, so that's out.

I tried OpenSCAD which is cool because it is based on a language that says where to place things, except it has hardly any primitives to work with and its other functions (e.g. linear_extrude) are so sparse that I would have to hand-program even basic 3d shapes (like wedge, or flat pyramid).  So that's gonna be a last resort.  OpenSCAD links:



Currently trying FreeCAD.