Functional MIND | A piece of paper |

in writing •  last year


Photo originally by Rene Böhmer on Unsplash


It was 2 AM. Already ready for sleeping, I was browsing Steemit. But a call changed my plans: we need you right now at a crime scene, said my boss. I knew it's gonna be a really bad night, but it turned out to be even worse.



Photo by Sergey Zolkin on Unsplash


A piece of paper

My car is always ready for night rides. I got into the car, turned on my favorite music and started driving. The night was beautiful. Dark, full of stars sky. The destination of the ride, however, was horrible.

After maybe two or three hours I had finally arrived. Arrived in the middle of nowhere. Just a road, but no cars. Just cops, but no people. The victim was under one of the street lamps. I came closer - that was a woman, maybe 22 years old. She was shot in the head.

"What kind of person could do such a thing...", I said.

"Probably a mad programmer", said a cop.

"Why programmer?", I asked.

"Just look at the lamp", he answered.

I thought he was joking, but I looked at the light source that became the crime scene and... There was a piece of paper with the following text on it:

const nextTarget = (thisVictim) => 
    thisVictim
    .filter(x => x !== '02/01/1996')
    .map(x => x === 'Aleksandra' ? 'Adam' : x);

"What the...", I was surprised.

I had no idea what was that. I mean - I knew it was a code, but I have never programmed before. Anyway, there was something about victim there so I was kinda sure that it was the murderer who wrote this code.

"I need a person who can into programming", I said, but nobody responded.

Well, this code was the only characteristic object in this case, we didn't even know anything about this girl. I really had to understand it. There were two options - I learn to program or ask my old friend. Learning to program from scratch probably wouldn't be the most optimal choice, so I decided to contact with Max.



Photo by Matt Palmer on Unsplash


My old friend

We know each other since childhood. Max was just a normal guy who liked to code. Everything changed two years ago. He built a small house in the middle of nowhere without internet. This place didn't look like a perfect spot for a programmer, but the weirdest was the reason why he cut himself off from the world, he sent me a message:

"I'm done with this JavaScript frameworks nonsense. Everyday new framework. I'm tired. I mastered one - it doesn't matter because no one uses it anymore. I have to cut myself off from the world for some time and master plain JavaScript."

"I don't even know what a framework is, chill.", I replied.

"Why would you even want to know that..."

"I want to understand what are you saying."

"Well, in computer science a framework is some kind of schema to build software. It's the framework who is your master - the flow of control is dictated by it (inversion of control).", he tried to teach me some computer science. [1]

Since this message, I met him maybe three times. Three times in two years. Well, our friendship isn't as strong as it used to be. I couldn't let him know that I'm going to come to him because he didn't even have a phone. I had no choice, I got into the car and drive to him.

It was already the sunrise. I knocked on the door. Max was surprised that I came:

"Welcome, what are you doing here that early?", he asked.

"There is a problem to solve - a coding problem."

"Yea, it's never too early to code. Come in."

There wasn't much inside his house. A laptop, two monitors, a fridge, a stove, a bed and a lot of books. He didn't need more - he was only reading computer science related books and programming each day. I introduced him the situation and showed the code.

"Hmm, a murderer used a functional programming paradigm here...", he said.

"What?", I didn't know what a programming paradigm is.

"In programming, a paradigm is a way of thinking about a problem we need to solve. There are plenty of paradigms in computer science world, for example, object-oriented, imperative or functional programming in which this code is, I suppose, written." [2]

"Ok, but what does this code do?", I wanted to know.

"So yea, basically the murderer told you who is gonna be his next target. Look: nextTarget is a function that takes one argument - the victim data as an array (thisVictim) and returns another person data, probably the next target. At first, .filter(x => x !== '02/01/1996') creates new array with all elements from thisVictim array that pass the test x !== '02/01/1996', what is as I suppose the date of birth of the current victim. It means that next target wasn't born on the same day as the current victim. Then .map(x => x === 'Aleksandra' ? 'Adam' : x); again creates a new array with all elements from array already without the date of birth and changes one element from Aleksandra to Adam. His next target is Adam. This wasn't complex JavaScript tho, but the code requires you to know the personal data of murdered. Probably surname of his next target is the same as this girl's.", Max explained. [3] [4]

It seemed too easy. Murderer telling police who is gonna be the next victim? But a minute later my phone rang, it was my boss:

"We have another fatality. And another code..."

References

  1. Wikipedia
  2. cs.lmu.edu/~ray/notes/paradigms/
  3. developer.mozilla.org about .filter
  4. developer.mozilla.org about .map

Do you like this story? Follow me for more!

Do you like Science, Technology, Engineering or Mathematics? Check #steemSTEM!


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Wow! That was a clever one. I'd love to see you evolve into a criminal novel writer ;)

Jaki, that was a cool idea to teach programming. Great work.

Well... that was truly thrilling.

Wow, this is a very nice way to teach programming.

I upvoted you’re content I hope you check out my profile aswell that would make my day!!
Keep up the good work.