Skip to content

Instantly share code, notes, and snippets.

View diegovgsilva95's full-sized avatar

Diego Silva diegovgsilva95

View GitHub Profile
@diegovgsilva95
diegovgsilva95 / README.md
Last active December 8, 2024 04:42
JS - Math experimentation: (potentially-)infinitely nested triangular sums

Notes

So far I could identify the sequences up to the level 3 (from 0 to 3):

  • Level 0: {1, 1, 1, 1, 1, ...} it's a boring sequence of 1s, nothing new (it has even an OEIS sequence: A000012)
  • Level 1: {1, 2, 3, 4, 5, ...} the natural numbers (n ÷ 1), also nothing new (OEIS A000027)
  • Level 2: {1, 5, 15, 34, 65, ...} a third-level polynomial, n × (n² + 1) ÷ 2 (A006003)
  • Level 3: {1, 20, 210, 1309, 5720, ...} n × (n² + 1)((n² + 2)² - n²) ÷ 16 (A094311)
  • Level 4: {1, 230, 26565, 1159774, 25170860, ...} doesn't exist on OEIS.
  • Level 5 and above: also don't exist on OEIS.
@diegovgsilva95
diegovgsilva95 / index.mjs
Created December 5, 2024 22:01
JS - Multiple ways to solve the same problem: suffixing an ordinal number
// In a nutshell, there are three ways to solve this problem: the "naive" one, the "normal" one, and the "crazy" one.
// What a novice and naive programmer, not so well-familiarized with mathematics, would probably achieve:
const naiveStndth = n => {
if((n <= -10 && n > -14) || (n >= 10 && n < 14))
return "th"
let lastDigit = Math.trunc(n % 10) // Welp... Is this really the approach from a novice programmer? I'm not so sure.
if(lastDigit == 1 || lastDigit == -1)
@diegovgsilva95
diegovgsilva95 / README.md
Created December 5, 2024 06:00
JS + HTML: Artistic rendering of the octets of a Champernowne-like binary sequence

Contextualization

See A030190 and the section Champernowne sequence from Wikipedia for mathematical details.

Usage

  1. Simply create index.htm, style.css and index.mjs and open in any browser.
  2. Watch the artistic emergence of a glitched-like pattern.
  3. Try to change values for W and H (avoid using too large numbers because it can lead to JS memory issues due to an enormous JS array for octets ; I tried up to a maximum of 512x512)
@diegovgsilva95
diegovgsilva95 / README.md
Created November 3, 2024 16:56
Conversion/Normalization of a large dataset to a binary file as 32-bit LE Floating Points

Purpose

People like me loves crunching big sets of numbers. The more multifaceted these numbers are, the more we like them. In modern times, it became so easy to compute really big sets of numbers, even your fridge can do it nowadays (good thing they got a free cooling system that any personal computers would envy)! I'm talking about GBs of numbers, really lots of them. Numbers are everywhere, look around you: air pressure (you probably know it as "sound") and temp differences can be discretized to numbers, electromagnetic fields resonating a specific frequency (you'll know it as "radio station" or "ham radio station") can induce electriical currents which, in turn, can be measured and discretized as numbers (a time-series of volts). A whole terrain can be discretized in such a detailed way by its elevation height for each squared mm (LIDAR and satellite imagery). Even our genes can be discretized to numbers, mapping ATGC to 4-base number system. Very complex yet simple interations (as paradoxical as they a

@diegovgsilva95
diegovgsilva95 / index.mjs
Created November 2, 2024 04:30
JS - Comparison of different approaches on generating prime numbers
import {clear, log} from "console"
import { readFile } from "fs/promises"
import { stdout } from "process"
const sleep = ms => new Promise(r => setTimeout(r, ms))
stdout.write("\x9bH\x9b2J\x9b3J")
let tests = []
let existentPrimes = []
let current = 0
const WAIT_TIME = 10_000_000
@diegovgsilva95
diegovgsilva95 / example.html
Created October 28, 2024 01:21
CSS + HTML: Properly containing a canvas/img/media to whole page using aspect-ratio
<body>
<main>
<canvas width="640" height="360"></canvas>
</main>
</body>
@diegovgsilva95
diegovgsilva95 / weightedRandomChoose.mjs
Created October 27, 2024 18:50
Weighted Random Choose using binary search
const weightedRandomChoose = function(weightedChoices){
let choiceKeys = Object.keys(weightedChoices)
let cumulative = []
let sum = 0
if(choiceKeys.length == 0)
return null
for(let key of choiceKeys){
sum += Math.abs(Number(weightedChoices[key])||1)
@diegovgsilva95
diegovgsilva95 / index.mjs
Created August 16, 2024 06:08
Simple Natural Language Processing - Finding/Classifying words by the least maximum offset between their letters
import {clear, log} from "console"
import { readFile } from "fs/promises"
var sleep = ms => new Promise(r => setTimeout(r, ms))
let dict = (await readFile("english_words_alpha.txt", "utf-8")).split("\r\n")
for(let i in dict){
let word = dict[i]
let letters = [...word]
let chars = letters.map(v=>v.charCodeAt())
@diegovgsilva95
diegovgsilva95 / index.mjs
Created August 13, 2024 04:30
Proof-of-concept: QWERTY Shift Cipher
var keyboard = "qwertyuiop|asdfghjkl|zxcvbnm".split("|") // The grand-old QWERTY keyboard we all love and h8...
var editor = document.querySelector("textarea") // Of couse you'll need some HTML skeleton with a textarea...
var preview = document.querySelector("pre") // ... a pre...
var key = document.querySelector("input") // and a numeric input (e.g. input:number or input:range)
var refreshPreview = function(){
let out = ""
for(let char of editor.value){
if(!char.match(/[a-zA-Z]/)){
out += char
continue
@diegovgsilva95
diegovgsilva95 / index.p5.js
Created August 10, 2024 22:44
P5.js - Vesica Piscis and recursive shapes
function setup() {
createCanvas(700, 600);
background(220);
iterationSlider = createSlider(0, 20, 1,0.01);
iterationSlider.position(10, 10);
iterationSlider.size(200, 10);
angleSlider = createSlider(0, 360, 0,15);
angleSlider.position(280, 10);
angleSlider.size(200, 10);