ruby

Comparing Performance of Ruby and Golang With a Benchmark

2 minute read Published:

I recently solved a coding challenge using Ruby. I’ve been curious for some time about coding using Golang, and so I decided to port it over, and see what the performance difference was. I made a small adaption for a better comparison. I’m now using a grid that has 100_000_000 squares on it. This is definitely a bit of work. The code package main import ( "encoding/json" "fmt" "io/ioutil" "os" ) var grid [][]int var gridDim [2]int var a = make(map[[2]int]bool) func main() { jsonFile, err := ioutil.

Proving the Monty Hall Problem

3 minute read Published:

Doors When I first heard of the Monty Hall problem, I read about it in Sam Harris’ The Moral Landscape, and it took me a few minutes to really wrap my brain around it. Talking about it with a few people since, I struggle to convince them that this really works this way. I think part of it is that I still don’t quite believe it.

Find Adjascent Squares for a Coding Challenge

3 minute read Published:

Random grid of numbers. I spotted a challenge that was something like this online, and I adapted it. There was something that I wanted to understand a little bit better. The interesting thing here is about the data structures used, to increase efficiency. Find Contiguous Squares Imagine you have a grid of n width and height, and it’s populated with random numbers. It could be represented something like this:

A Single Singleton in Ruby

4 minute read Published:

What is a singleton anyway? How do we use them to put large blocks of text in code.
The singleton design pattern I’m relatively new the the concept of the singleton, even though I’ve been programming for a number of years. I’ve run into several instances in which I new that this was exactly what I needed, but did not have a name for it. Here, I’m going to try to explain it to myself a year ago. There are a few questions I’ll try to address.

The Mysteries of the Ruby Heredoc

4 minute read Published:

A few tips on the ruby heredoc.
As of writing this, I’m running Ruby version 2.3.0. Not all of this, particularly the stripped heredoc, is available in plain ruby before 2.3.0. Heredoc Basics So, you need a string that’s longer than a line, and you’re sick of quotes and backslashes? And you might like to retain formatting? You want string interpolation too? Enter, heredoc. Here’s your basic, run of the mill, heredoc. You’ll notice we use the <<- operator, and our safe-word, which we will use to end the heredoc.