My Brain Hurts: recursion with factorials

With pencil and paper in hand, I have no problem with recursive patterns. Fibonacci schmibbo-hotsytotsy. Factorials schmacks-Oreos.

“Write a recursive function to …” blah mork loopy loo let me leave the interview now so you can continue with someone better, and I can drown my sorrows in two scoops of ImNotWorthy. 

I know this because it was not until I was asked to demonstrate recursion in a mock interview (I requested this topic), that I saw that my comprehension was passive. I understood it when I saw it. … ish. Understood-ish. But there was absolutely no active comprehension. I could not do it on my own. No ish. Nuthin. Fear? Nerves? A pebble in my shoe?

It is that whole “snake eating it’s tail” that was throwing me. I could not recreate what was going on. There is no stack with pencil and paper. I can write it out and do them in my head until I needed a calculator, but even with a calculator, all I needed was a line:

5! = 5 x 4 x 3 x 2 x 1

I understood stacks in other terms (callbacks, pancakes), but the recursion was hurting my brain, until I made it a literal stack in my head. I was treating the part of the code block after the base case as a spiral when (for me) thinking about it as slapping 3×5 cards down. No wonder I didn’t understand the stack; I wasn’t treating it like one.

I’ve been playing with recursion and different tasks as I plow through books on algorithms and tech interview skills. Factorials and Fibonacci are the easier ones to grasp. Not easy. EasIER. Comparative. Like farts smell better than decomposing bodies. They don’t smell good, just better.

I wouldn’t say that I could whip out recursion any time, and I know that I wouldn’t want to with factorials (O(n2) and all that), but I’m getting there. I spent some time on JSFiddle and with my markers to play.

factorial_recursion

The code is old news.

const factorial = n => {
if(n===1){
return 1; //my base case
}
return n * factorial(n - 1); //my nut case
}

I did not set include checking to see that n is a non-negative integer. That was not the point of my doodling because checking for that was not the hard part. This post isn’t about a fully-tested function to return the factorial of a number; this is about me getting the recursive part.

Pure CSS Images: Now what

Here I am so far. (I am using screenshots because my version is not responsive.)

mid-century modern prints
Original by Kerry Beary and my wip. (I believe she spells it -mellows and not -mallows because she’s punny.)

In terms of what is left to do that is furniture or furnishings, I have the lamp and interior of the pod. I can do those and stay pretty true to the original; however, when it’s time to do the cats …

What do I do? Do I make CSS cats that are not much like the original? There are limits with CSS. Do I make them in SVGs? I think if I do that, it feels too much like plagiarising. SVSs are a last resort. Or maybe just put a cat in the back and a person on the bench? Change it enough? I have no idea. Thankfully, I still have that lamp to do. I might animate that.

I’m exhausted.

Checkers did my head in

My current Pure CSS Image attempt is this gem from Kerry Beary.

I cannot tab in my code snippet, so just deal with it. (It even hurts my own eyes.)

@for $i from 1 through 7{
.#{rectangle-band}-#{$i}{
margin-left: 0px;
@if $i % 2 == 0 {
@for $i from 0 through 3{
.#{square}-#{$i}{
margin-left: $i*60px;
@if $i % 2 == 1 {
background: $evenband;
}
}
}
}
@if $i % 2 == 1 {
@for $i from 0 through 3{
.#{square}-#{$i}{
margin-left: $i*60px;
@if $i % 2 == 0 {
background: $evenband;
}
}
}
}
}
}

Iterating in Pug. Iterating in Sass. Nesting them. Checking for odd or even. ERMAGERD! But I did it.

Screen Shot 2018-05-07 at 1.38.12 PM

For now. But looking at it above, I see that the chair is too big. No. I’m not going to fuss. There are times to let it go. This is one of those times.

I have to get circles or semi-circles in there. That’ll be a new set of curse words. Let me just admire this for a second!

Ok. Done. Now I have to dry heave.

750Words d3: Ideas (picture books)

Whoo hoo! I’m three for three in the goal of forever! I’ll take it. I won’t publish them all. The purpose of 750Words.com is to just write. It is not to write to you. Sometimes I’m too whiny, sad, or mad. Enough yuck out there without my adding to it.

This topic came to me as I work through a VueJS tutorial by Maximilian Schwarzmüller. I like to have a plan build as I learn. I find it especially helpful as I’m getting smaller chunks in with an instructor like Big Max. Because his tutorial is organised into small chunks, I have little breathers that allow me to think to myself, “How would I use this?”. I could say that after an hour, but then the “this” would be more about a larger concept instead of smaller tools. It’s harder for me to think “How will I use Vue” or “What will I build with Node” than to ask myself how I could use changing the style dynamically with Vue and a method.

I have more time now to think, plan, and write. Not much more time, though, so let me just publish this and move on to my next lesson. (today’s stats)


When I taught math to 4th graders, I loved reading aloud from picture books. People can blather on about chapter books as though a child must graduate from picture books to chapter books completely. Books are no classrooms; however, you learn plenty from them. I believe that a good picture book offers so much more to the reader than what a chapter book can. Mind you, I love fiction and wish I had unlimited funds so that I could sit home and read and not apply for jobs. I am not here to compare the two as though one is better. There’s enough of that bullshit between childless-by-choice and parents, stay-at-home moms and “working” moms (“”s of sarcasm as we know that SaHMs work plenty).
Although I was a math teacher, I read to the children plenty. One group could handle “Flatlands” even. Expurgated. I’m not a fool. The kids were 9 and 10. There were some things they weren’t going to hear for the first time in their math class! I also read “Where the Red Fern Grows”—not once without snotty tears. But what I absolutely loved the most was finding a beautiful picture book. I loved a good story and the complementary pictures. Read, show, read and show. A good story does not have to be a long one. For me, length is how it stays with me.
Mostly the stories I read were what you might think about when you think of a picture book: an adventure, a lesson learned, a special someone, cute animals, etc. That’s what I thought of when I started teaching, but we had excellent librarians when I taught. They pointed me in the direction of picture books that explained math concepts: multiplication, exponents, geometry, etc. How awesome was that? I still refer to those books when I tell people that math and art are not separated. Proportion? Ratio? Geometry? Symmetry? Have you not heard of daVinci, Michaelangelo, Mondrian?
When I stopped teaching, I remember wanting to write children’s books to make math less frightening or to supplement a math concept. Wanting to write is much easier than deciding to write. Deciding to write is different from having the story and concept down.
It goes without saying that I have not written a book, but in the years since leaving the classroom one never leaves teaching), I have discovered my love of coding, specifically HTML/CSS, JavaScript and its libraries. I am currently getting my VueJS and NodeJS on, and while I’m learning them, my mind keeps returning to writing a picture book. I can’t draw. I can. Everyone can. I am not an artist one pays to draw. How is that? Clearer? Especially as I work through VueJS, I think about making a picture book with my words and my SVG illustrations.
Until I get skilled enough, I need a place to store ideas. I’ll start with a few here.
ABC BOOKS
I love ABC books. Edward Gorey is wonderful and a reminder that picture books and ABC books do not have to be cutesy. Why not one for math or narrow it down to geometry? If geometry, less about ABCs and more about just terms? I’m teaching coding to children (middle schoolers). What about the ABCs of dev. Or keep it to language or basics? What about a build-your-own ABC book? Let the student choose the theme, letter (no need to build ABCs in order), and supply their own images? The program could scale the images to the appropriate size. The child just needs to make the SVG on her own. I don’t know. Work with me here! What made me think of that one is that so many city- or town-specific books aren’t about the town the child hails from. Why not have Clare from Pooperville build an ABC book of her town? Andrew from Fartzburg might build the ABCs about what the people in his village do. Why not? ABCs of good deeds? Seriously, ABC books are unlimited as all they have to be is in alphabetical order. How is that for a scope?
I’m too new of a dev to have that be a theme for me, so I’d have to return to that.
RESCUE ANIMALS
I have greyhounds and have fostered them for years. I’m deeply concerned about their treatment by handlers and the industry. I know that some handlers and greyhound owners who race them truly do love their dogs, but the industry is not friendly. You, Mr Gentle Owner, may keep your hound long after she’s stopped winning and until a ripe age of 16, but we all know that is not the norm. Unfortunately, there are a lot of people who do not know a lot about the greyhound and don’t think of them as an option for a pet. “They must need a lot of space.” “They must want to run all day.” “They’re so big, and I have an apartment.” All myths. Greyhounds and other sighthounds won’t be for everyone—same with any breed—but the more literature that is out there, the more people will read and consider. Maybe a book will help a greyhound find its forever home, and maybe it will keep the wrong person from adopting and surrendering. No. Do not adopt a greyhound for you to do your 10k runs with. Usain Bolt is not a marathoner, right?
MATH (of course)
I specifically think of 4th graders as they’re at that cusp of going from concrete-sequential to abstract. I used to have a car covered in bumper stickers. Covered! All over. Not just on the bumper. In the middle of the back was one that read “I hate bumper stickers!”. Students who thought that was hilarious were ready for fractions. Those who were stumped and confused? Well, perhaps this year wouldn’t be the year they got fractions. There are so many ways to show math in a picture book: ratio, fractions (but please leave the cliché pizzas out), division, multiplication, factorials, … Of course, addition and subtraction, but that’s getting to an age I’m not aiming at.
AWFUL TOPICS
Huh? What? How hard is it to parent and bring up awful topics? I’m thinking about pet death, a parent’s job loss, bullying, body changes. There are many topics here, but to just write and include images without researching the topic and how to address it to kids? This is heavy. I’d have to be careful. I should be careful with any topic, but obviously these have an edge to them.

I hope to add more when I think of them. I should also probably quit adding and start planning, but that is another post!

750Words d1: Fitbit, Dancing, and the benefit of boredom

I’m done with my Daily CSS Images challenge and have found that I have missed writing. Following a link from a Medium post, I came across 750words.com and wrote my first piece. They tell you not to edit, so I didn’t. One thing I learned is that I did this in under 30 minutes. I can afford 30 minutes. I had assumed daily writing challenges would take longer. I love math; I love to write. This is perfect for me because of stats: Pretty graphs and yummy pie charts



750words Day 1

I know that some people look at my wrist and see the Fitbit and roll their eyes. I don’t care too much about counting my steps; I walk my dogs nearly every day and run every other day. I also do not care about opinions of others for the most part. What my Fitbit does for me is to remind me to get up and out of my 90-degree angles. While I’m underemployed and looking for a job, I am at my laptop coding, learning more about code, applying, and regretting. At 10 before the hour, my Fitbit rattles me to inform me to dance. Yup. If I’ve not done enough, I get reminded. I shout to Alexa to play 80s pop, and then I dance. I get more steps in with 5 – 10 minutes of dancing than I do walking around the block, AND I get to do this in an air-conditioned house. Sorry, Mme Ozone.
Where are the places to dance for the length of a normal song? I don’t want anything extended or remixed. I want the living room I danced in when I was a kid before I could go out. Where are those places? I do not have the attention span for a long dance-remix. I also want to hear the lyrics. I don’t mind remixes found in dance places; however, for me, those are better in spin classes when I need the distraction for 10 minutes. What I want is to dance for 3 minutes one way and change it up for another. Remixes are just hell for me. I’M DONE WITH THIS BEAT!
It’s not fun to dance alone, but I’m not. I have the unappreciative and wary audience of pets. I figure they look at me like a toy that is too big to kill the squeak. They track me, though. I see it in their eyes. They are entertained. No. I’m not anthropomorphising. They watch. They wag. When I’m done, they come up for attention. It’s change; it’s movement; it’s always different.
The other side of this Fitbit exercise is a graph I have kept in my head. I have become curious as to what songs get more steps in per minute. These are my steps and my moods. Obviously, this is not scientific in any way, but it’s fun. I’d be curious to compare the songs against others but also against each other and see if there are large variations.
I have found another benefit to the dancing: it clears my Etch-a-Sketch head. I am often following a tutorial or trying to apply what I’ve learned from the tutorial to my own code or following a daily challenge. With so many rules to follow, I don’t get to clear my head to just let the mind wander. Since I often choose 80s pop, new wave, or alternative playlists, my mind goes back to being a teen or young adult. I think about anything and everything that is not JavaScript, VueJS, NodeJs. Once I shake the code out, my mind wanders to other things. I come up with the ideas I can bring to life with code. I am a firm believer that getting bored is important. Most of the things we enjoy, need, and use came up while someone was staring off and let her or his mind wander and ask “What if …”. What is the point of learning to code if I can’t come up with ideas to solve problems? Even if I’m far too green to bring my ideas to life, coming up with them is more important to me. Who cares how great the dev team is if there are no fresh ideas coming to them? Get bored. It’s ok. It’s just not ok to “solve” the problem of being bored by whining about it. Get bored. Write. Wonder. And save. Even if it’s not about to happen, get it down and make like the English Beat and save it for later.
Did I mention save it? My grandpa was Paul Cassidy, a ghost writer for Superman in the late 30s. He left Supe for a better paying job as a teacher. I know. Don’t laugh. He also read history for fun and illustrated scenes he read. Where are those? Deep in a landfill. When he moved into his retirement home, he threw it all away. His right—I give him that—but what a loss for his family and others.
So while others may see another middle-aged woman with a Fitbit to count steps she thinks will counter what she eats, I know this buzzer reminds me to get up, dance, and let my mind wander. On that note, Cyndi Lauper is reminding me that girls still just want to have fun.