Multiplication Table Based Mandalas Generator

Inspired by Mathologer’s video Times Tables, Mandelbrot and the Heart of Mathematics I have done a lot of mandala-like drawings on my Axidraw A3/V3 plotter.

Almost all my pieces are generated using the Javascript tool below I created. The source code is on Github.

Play around with the sliders or try these configurations Wave, Lighthouse, Sunrise, Lotus Flower, Ring, Overlapping Cardioids, Flower, Flower II. Reset.

An Interactive Implementation of the Fire Effect in Doom

The fire effect in the Doom intro recently got renewed attention due to Fabien Sanglard’s excellent book Game Engine Black Book: DOOM and blog post How Doom Fire was Done.

After looking through a couple of implementations, and realizing that the effect is achieved using very little code I decided create my own.

The original algorithm can be used to create a lot of things if you feed it with different variables and have a bit of imagination.

Play around with the sliders or try these configurations Umbrella, Rain, Fire, Mona Lisa, Fireball, Beam me up, Matrix

The mask is a 256x256 gif image where bright pixels marks the source(s) of the effect. The fire, has just a line in the bottom and the rain is just a line in the top.

The source code is on Github.

Seven Segment Display - Riddle by FiveThirtyEight - Solved with JavaScript

The FiveThirtyEight riddle Tyler Barron’s Seven Segment Display is stated as follows.

Given a two-character, seven-segment display, like you might find on a microwave clock, how many numbers can you make that are not ambiguous if the display happens to be upside down?

For example, the number 81 on that display would not fit this criterion — if the display were upside down it’d appear like 18. The number 71, however, would be OK. It’d appear something like 1L — not a number.

// Rotates a single seven-segment display digit 180 degrees.
// Non number results are converted to NaN.. eg. 2 --> 2, 6 --> 9, 3 --> NaN
const rotateDigit = n => [0, 1, 2, NaN, NaN, 5, 9, NaN, 8, 6][n];

// Rotates a seven-segment display number 180 degrees.
// eg. 10 --> 01, 81 --> 18, 71 --> 1NaN.
const rotateNumber = n =>
    // Convert the number to a string.
    n.toString()
    // Split the string on every character.
    .split('')
    // Reverse the order of the characters
    .reverse()
    // Rotate the digits.
    .map(rotateDigit)
    // Convert the array back to a string.
    .join('');


const numbers =
    // Generate a range from 0 to 99.
    [...Array(100).keys()]
    // Rotate every number.
    .map(rotateNumber)
    // Filter every number that is not a number. :)
    .filter(isNaN)

const result = numbers.length;

New Year's Resolution 2019

This year I will consume 52 more books than I usually read or listen to a year; in other words, 52 books. Knowing myself, almost all books will be non-fiction, and that is OK.

Books

[X] Contact, Carl Sagan, 1985
[X] Bad Blood, John Carreyrou, 2018
[X] Educated, Tara Westover, 2018
[X] Skunk Works, Ben Rich, Leo Janos, 1994
[X] Siddhartha, Hermann Hesse, 1922
[X] Expeditionary Force - Columbus Day, Craig Alanson, 2016
[X] Expeditionary Force - SpecOps, Craig Alanson, 2016
[X] A Study in Scarlet, Arthur Conan Doyle, 1887
[X] Access, Andy Weir, 2010 (SS)
[X] Antihypoxiant, Andy Weir, 2014 (SS)
[X] Annie's Day, Andy Weir, 2011 (SS)
[X] The Real Deal, Andy Weir, 2012 (SS)
[X] Bored World, Andy Weir, 2013 (SS)
[X] The Midtown Butcher, Andy Weir, 2014 (SS)
[X] Meeting Sarah, Andy Weir, 2010 (SS)
[X] The Chef, Andy Weir, 2010 (SS)
[X] The Egg, Andy Weir, 2009 (SS)
[X] The History of the Future, Blake J. Harris, 2019
[X] The Alchemist, Paulo Coelho, 1988
[X] Fahrenheit 451, Ray Bradbury, 1953
[\] An Anonymous Girl, Greer Hendricks & Sarah Pekkanen, 2018
[ ] Humble Pi, Matt Parker, 2019
[ ] Snow Crash, Neal Stephenson, 1992
[ ] Neuromancer, William Gibson, 1984
[ ] The Dispatcher, John Scalzi, 2016

Project Euler 22 - Names Scores - Solved with JavaScript

The 22th Project Euler problem - Names Scores - is stated as follows.

Using names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.

What is the total of all the name scores in the file? Project Euler, Names Scores, Problem 22

const fs = require('fs');

// Read the textfile into a string.
const names = fs.readFileSync('p022_names.txt', 'utf8')
    // Split the string on every comma and remove the quotes
    .split(',').map(name => name.replace(/"/g, ''))
    // Sort the names.
    .sort();

// Get the alphabetical value by adding the chars position in
// the alphabet. A = Char Code 65 = Alphabet Position 1.
const getAlphabeticalValue = name => name.split('')
    .reduce((memo, item) => memo + item.charCodeAt(0) - 64, 0);

const result = names.reduce((memo, item, index) =>
    memo + getAlphabeticalValue(item) * (index + 1), 0);

Archive