De Mexico al Reino Unido

Ya tiene mucho, muchísimo (10 meses) que no escribo/tengo ganas de escribir acá. Me han preguntado si olvidé por completo del blog y del diminuto momentum que tuvo cuando lo estaba manteniendo, pero yo me cuestiono si fue uno de esos momentos de brillantez y dedicación completamente mal distribuida, como el que cualquier programador pasa: Debería registar mis pensamientos en algún lado… haré un blog ! O quizá debería enfocarme en artículos técnicos, con código y todo… reharé mi blog ! ...

March 2, 2020 · 4 min · oschvr

Merge Sort in Go and Javascript

Here’s my implementation of the Mergesort algorithm in Golang package main import ( "fmt" "io/ioutil" "math/rand" "strconv" "strings" "time" ) func main() { start := time.Now() arr := randArr(20) // Merge sort array fmt.Println("\n Sorted \n", mergeSort(arr)) fmt.Println("Sorted in: ", time.Since(start)) } // Function to generate random array func randArr(size int) []int { arr := make([]int, size, size) rand.Seed(time.Now().UnixNano()) for i := 0; i < size; i++ { arr[i] = rand.Intn(99) } return arr } // Merge sort accepts an array and recursively sorts it func mergeSort(arr []int) []int { if len(arr) < 2 { return arr } middle := (len(arr)) / 2 return merge(mergeSort(arr[:middle]), mergeSort(arr[middle:])) } // Merges two arrays into one func merge(left, right []int) []int { var sortedArr []int // Check for inversions while array for len(left) > 0 && len(right) > 0 { if left[0] <= right[0] { sortedArr = append(sortedArr, left[0]) left = left[1:] // Just like shift(), remove first and return slice } else { sortedArr = append(sortedArr, right[0]) right = right[1:] // Just like shift(), remove first and return slice } } // Append to sortedArr if no inversions and for len(left) > 0 { sortedArr = append(sortedArr, left[0]) left = left[1:] // Just like shift(), remove first and return slice } for len(right) > 0 { sortedArr = append(sortedArr, right[0]) right = right[1:] // Just like shift(), remove first and return slice } return sortedArr } and here’s in Javascript ...

May 26, 2019 · 2 min · oschvr

Understanding Recursion

Rather than using the popular joke about recursion (see bottom), I’ll reference a very peculiar adage which makes use of this particular mental model: The Hogstadter’s Law, states that: It always takes longer than you expect, even when you take into account Hofstadter’s Law. See what happened there? The law is a self-referential adage, that tries to describe the widely experienced difficulty of accuratelly estimate the time it will take to complete tasks of substancial complexity. ...

May 17, 2019 · 4 min · oschvr

Shortest Fibonacci

Here’s an incredibly short anonymous fibonacci function in Js. It takes a parameter n to calculate the fibonacci number at position n ((n) => (n <= 1 ? n : n - 1 + n - 2))(5);

May 15, 2019 · 1 min · oschvr

3 Meses sin Facebook

Última Actualización: 09/Junio/2018 A ver si se acuerdan de algún compañero del kinder/primaria primaria, cuyos padres neo-liberales, le prohibían ver televisión en favor de actividades diurnas al aire libre. Ese mismo compañerito que, forzado por la voluntad de sus padres, se quedaba fuera de las discusiones de quien era el ‘Chico del Pórtico’, episodio de Hey Arnold en Nickelodeon, o quien podía decir ‘Omelette du Fromage’ durante un día entero, como le pasó al Dexter en El Laboratorio de Dexter de Cartoon Network. ...

June 8, 2018 · 5 min · oschvr