Numberphile - Josephus Problem Explanation

Josephus problem can be solved using the power of 2. Given that there are total of 2^n people standing in a circle, the start position is 1 and skip is 1, then person at position 1 would always be the winner.

in other words: if we write n such that `n = 2^a + l` where l is smaller than 2a, and 2^a is the biggest power of n; then the winner will be `(2l + 1)`.

Theorem n = 2^a + l, where l < 2a W(n) = 2l + 1

Example:

``````  n = 100
n = 64 + 36  (64 is the biggest power of n, and 36 is the reminder)
w(n) = 2 * 36 + 1 = 73

so the answer will be 73
``````

### writing a technical design documentation

A design doc is simply a description of how a problem should be solved. Design Doc is also known as Technical Spec.

what to include in a design doc

• title and people: title of the design doc, author(s), reviewer(s) and date when the doc was last updated
• overview: a high-level summary. should be around 3 para at max. people should be able to decide whether to read the full tech spec or skip it just by reading this section
• context: description of the problem at hand.
• goals and non-goals
• user-driven impact of the project (user could be another engineering team or event another technical system)
• specify how to measure success using matricsa
• problems that won't be solved must also be mentioned
• milestones: a list of measurable checkpointsa
• existing solution: high-level walk-through of the existing solutions
• proposed solution (technical architecture):
• walk through a user story to concretize the solution
• use sub-sections
• use diagrams
• provide a big picture, then fill in lots of details.
• in short: this section should be written in a way that even is the author takes a vacation, any team member should be able to implement the solution just by reading it as it is described
• alternate solutions: include other solutions you could think of, along with its pros and cons.
• cross-team impact: how this solution will impact the other teams
• how will this increase the on-call and devOps burden
• how much money it will cost
• …etc
• open questions: anything that the author is not sure about
• detailed scoping and timeline: for the engineering team only. hence, at last of the doc. resources on timeline and detailed scoping

how to write it

• write in the most simplest way possible
• simple words
• short sentance
• bulleted lists and/or numbered lists
• concrete examples, like “User Alice connects her bank account, then …”
• add lots of charts and diagrams. (Google Drawing can be used)
• add editable link at the bottom of the diagrams and charts. this will make it easier to edit on a later date
• include numbers. for example; # of DB rows, latency etc. people just love numbers.
• try to be funny for higher engagement
• do the skeptic test. ask yourself questions regarding the design doc. just pretend to be a reviewer for a while
• do the vacation test.

interesting articles

spent time on redesigning this site. I hope to post more here. [note to self: add RSS feed]

Starting up at 22 — Reflections - Rahul Mathur

nice tool for visualizing SQL tables: https://drawsql.app

learnt how to make list-items reveal on scroll. demo

resources: suelan.github.io

linking error messages to filename: simply log error message in this format: `file:///<PATH>/<FILENAME>:<LINE?>:<COLUMN?>` - source

really interesting article on how to ship ES2015+ code to browser: read here

takeaways:

• don't transpile code to ES5 when not needed
• generate separate bundles for ES5 and ES2015+ using webpack
• trick to ship ES6 bundles conditionally:
• use `<script type="module" src="script.mjs"></script>` for ES6+ bundle
• use `<script nomodule src="script.es5.js"></script>` for ES5 bundle

browser with exec ES5 version if there's no `module` support available. note that having availablity of `module` means browser have support for `async/await`, `promise` and bunch of other ES2015+ goodies

YAYAYYAYYA!!! FIRST DAY AT WORK! From now on, I will be working for Algorisys Technologies

• worked with react-native

• tail call optimization: an optimization technique in which a recursive function is converted into iterative function. why this optimization is useful? it's possible that a recursive function would fill-up all available spaces in stack. to prevent that, a recursive function can be converted into iterative codeblock, which would take constant stack space.

a tail call optimization can be done only when the function returns itself…and nothing else. for example:

``````  function factorial(num, a = 1) {
if (num === 1) return a;
return factorial(num - 1, num * a);
}

factorial(10);
``````
• set-up vim to insert file-header via a plug-in

nothing much for the day. gotta resume solving problems on leetcode.

## mongoose in serverless

when defining a Model, first check if the model already exists with `mongoose.models.ModelName`. otherwise an overwrite error will be thrown

• rejected from Hackerrank
• another interview for a start-up went well

in an interview, it hurts when people judge my skills based on an assignment and happily ignore whatever project I built at past.

• worked on an open-source project
• rejected from a job `FrontEnd Developer(React) - Wharf Street Strategies`. Reason is probably becuase I didn't put much effort on the assignment they asked me to do (could be anything … really. IDK)
• Initial Screening Test for BackEnd Developer - Hackerrank. Solved one problem(string compression). could not solve the other one(prison break)
• had an interview with Wharf Street Strategies
• worked on a webapp which is basically about sharing Spotify Playlists of developers with each other

Nothing Much today. Just some React coding.

• wrote scripts for automating some stuffs
• build two projects (small CLI quiz app)

learnt about `readline.emitKeypressEvents`. this listens for `keypress` on terminal. it also accepts an `interface` which can be used to terminate an event listener.

``````const iface = readline.createInterface({ input: process.stdin });

process.stdin.setRawMode(true);

process.stdin.on("keypress", (key, e) => {
if (e.ctrl && e.name === "c") {
process.exit(0);
}

if (key && !e.ctrl) {
resolve(key.toLowerCase());
process.stdin.setRawMode(false);
iface.close();
}
});
``````

Something awesome happened. I revived my throw-away and (kind-of) incative twitter account, all thanks to Tanay Pratap and his discord server. (quite sure he hated me for not reading the channel chat history before posting)

No DSA for today :(

No Algorithms Problems today

Open-Source Contributions:

Made a new LinkedIn Post - Detect whether a Request is XMLHttpRequest or not

How to Communicate Better - Clément Mihailescu

• it's pointless to use programming acronyms while communicating with a person who does not have a programming background.
• Similarly, when the other person is holding the same(or more) experience as you in Programming, it's better to use acronyms than to elaborate everything. chances are they would get bored.
• When you have a huge audience to address, OverCommunicate. OverCommunicating essentially means that Explain everything as clear as possible for more than once, twice or as many times required, so that everybody is on the same page by the end of the session.
• Follow a Structure while communicating, much like an Essay.
• Using Intonation in non-verbal communication. Maybe use Emojis, Punctuation marks etc to express yourself better. just use whatever works better, you know.

No DSA problems today. Went through the problems I solved in last week.

PR and Code Review:

DSA problems solved:

Started a new Project: A Project Management Webapp

• put in a huge amount of time in designing it (not finished yet)

Project Idea: What if we mix a Kanban board and an Email client? would not it be awesome as people would be able to manage emails in slightly better way?

• Sliding Window Technique
• How to make a system highly available (check below)
• done few DSA problems

NOTES ON SYSTEM AVAILABLITY - Backend Engineering Concept

availablity of a system = uptime / total time

redundency: having multiple identical replica of a system up and running to make the said system highly available

total downtime of the system can be calculated by multiplying the probability of downtime of all identical replica. example:

sys1's downtime probability is 0.2, sys2's downtime probability is 0.15 and sys3's downtime probability is 1.0. so the combained downtime probability would be `0.2 x 0.15 x 1.0`, which is `0.03`(i.e. 3%).

load balancing is the technique to reduce downtime of a system. a load-balancer is simply a reverse proxy server which sits in-front of a group of servers and distributes incoming request to servers which are up and running.

Importance of a Proxy Server

• protects client IP address by hiding it
• acts as a first-level firewall
• protects client from visiting malicious sites
• caching
• encrypt client's data and decrypt them on demand

Some beautiful fonts:

Computer Science Basics to Learn

• Data Structures and Algorithms
• Parsers
• Networking and Socket Programming
• Basic Math
• Theory of Computation
• Basic Statistics
• Linux
• Design Pattern
• API and REST
• Source Control and Git
• Communication

Languages to Learn(any one of the following)

• Java
• Python
• C#
• C++
• Ruby

Projects to Build

• Create a console/terminal app
• Create a Desktop App
• Create many web apps(along with payment integration)
• Build Video Streaming App
• Create PWA
• Create Hybrid Mobile Apps

Math Resources:

Changed this LogBook workflow a bit. Now, the dairy content is managed by VimWiki. And pushed regularly using a Cronjob.

I am planning to publish my vimwiki as a live site. I can still do it out-of-the-box, but I don't want to bother with VimWiki templates. Guess I will write a small script for converting markdown to HTML.

Some useful VimWiki shortcuts:

• `<Leader>wi` - Go to Diary Index
• `<Leader>w<Leader>i` - Generate a new Diary Entry(must be in Diary Index)

Some Vim Commands:

• `vip` - Visually Select Around the Paragraph
• `cap` - Change Around Paragraph
• `va{` - Select around Braces
• `ci"` - Change Inside double quotes
• `cit` - Change Inside Tags

Data Structure and Algorithms Resources

• Abdul Bari - YouTube and Udemy
• Hackerrank - For Beginner
• LeetCode - For Interview-Focused Prep
• HackerEarth
• CS50, By Harvard - For Basics

YouTube channels to learn basic Computer Science stuffs: