Oscar Merida

twitter: @omerida

Articles

Prepare for Launch

By Oscar Merida

Welcome to the PHP Foundry. My focus for this column will be to explore the tools and libraries available to augment regular, daily tasks as we work on bug fixes and new features. I want to focus on practical advice for tools that streamline development. We’ll explore how to structure a project, use tools to automate mundane tasks, assess code quality and adherence to standards, and more. To focus our efforts, we’ll work on building a PHP client for SpaceTraders.io. by Oscar Merida

Published in World Community, March 2024

Five Card Stud

By Oscar Merida

Last month, we solved how to model and shuffle a deck of cards. In this article, we’ll look at how to identify the poker hands we deal out. by Oscar Merida

Published in The PHP Gambit: Winning Strategies in Code, February 2024

Playing Cards

By Oscar Merida

For my 28th installment, we turn back to games after our tour through sorting algorithms. We’ll look at a direct way to represent playing cards and contrast it with an object-oriented approach to leverage PHP’s built-in features. by Oscar Merida

Published in Bad Bug Bounties, January 2024

Quicksort

By Oscar Merida

Quicksort is a popular sorting algorithm first published in 1961. It works quicker than most other algorithms with randomized data. It uses a “divide-and-conquer” approach to sort an array recursively. Let’s look at how to use it in PHP and learn why this could be a very short article. by Oscar Merida

Published in Generating Efficient PHP, December 2023

Shellsort

By Oscar Merida

Much like Comb Sort improved on the Bubble Sort, Shellsort also improves the execution of the Insertion Sort. Again, the improvements come from comparing items that are far apart in the array in early iterations until we are comparing adjacent items again. by Oscar Merida

Published in Command Line Picasso, November 2023

Insertion Sort

By Oscar Merida

There’s more than one way to sort things? We’ve looked at two basic sorting algorithms and will continue that exploration this month. Instead of comparing pairs of values in our unsorted arrays, we’ll take a different approach and use an insertion sort. by Oscar Merida

Published in Software Archeology, October 2023

Comb Sort

By Oscar Merida

The Bubble Sort is an easy-to-understand algorithm to order array elements from smallest to largest. One drawback of the bubble sort is that we compare one element to an adjacent element. We’ll see how the Comb sort addresses the limitation and compare its performance with the Bubble sort.
by Oscar Merida

Published in The Spectrum of PHP, September 2023

Bubble Sorting

By Oscar Merida

We’ve escaped the maze(s)! On to new subjects, lets explore sorting and the different ways we have to put things in order. We’ll start with the first one I remember writing in Turbo Pascal.
by Oscar Merida

Published in Packing Up PHP, August 2023

PHP Puzzles: Maze Directions

By Oscar Merida

We know how to plot a course through a maze. Next, we’re tasked with
translating the maze solution into a list of directions to escape the
labyrinth. We’ll study the problem, come up with a solution, and throw
in some unit testing for good measure. by Oscar Merida

Published in Be Barrier Free, July 2023

PHP Puzzles: Maze Rats, Part Three

By Oscar Merida

In the prior two installments, we’ve explored maze-generating
algorithms. Once you’re in the labyrinth, you’ll want a way to find the
exit. In this final installment, we figure out how to get from the
maze’s entrance to the exit. by Oscar Merida

Published in Evolving PHP, June 2023

PHP Puzzles: Maze Rats, Part Two

By Oscar Merida

Last month, we solved how to represent a maze by storing the
configuration of walls for each grid square within. Now, we’ve been
tasked with generating a solvable maze at random. by Oscar
Merida

Published in HTTP Burritos, May 2023

PHP Puzzles: Maze Rats

By Oscar Merida

Back in the January 2021 installment for PHP Puzzles, Sherri Wheeler
looked at drawing a path through a grid. In this first part, we delve
into the work of maze generation. by Oscar Merida

Published in Getting TEKnical, April 2023

PHP Puzzles: Grade Deviations

By Oscar Merida

We’re continuing with grades and statistics by calculating statistics for Grade Point Averages. In the educational system in the United States, it’s a way to boil down the grades across the multiple courses taken by a student. It involves translating a letter grade back to a numeric value and then calculating a weighted average. At the end of all this, we’re left with a singular number we can use for a rough comparison between students. by Oscar Merida

Published in Box of PHP, March 2023

PHP Puzzles: Stats 101 Grade Book

By Oscar Merida

Let’s go back to basics and look at some different ways to measure the average value in a list of numbers. More specifically, they’re ways of measuring central tendency. These handy techniques to identify “the middle” of a set prove useful when analyzing sales, traffic, or other frequency counts. by Oscar Merida

Published in Knowledge Crunching, February 2023

PHP Puzzles: Any Two Birthdays

By Oscar Merida

Working with dates and times is fraught with peril, so it helps to practice manipulating such data. We’ll have to be wary of how to calculate differences between dates, potentially deal with leap days, and other irregularities. by Oscar Merida

Published in PHP is Standing Tall, January 2023

PHP Puzzles: Sticker Swapping

By Oscar Merida

The FIFA World Cup wraps up this month. One thing many fans worldwide do in the months leading up to the tournament is to fill out sticker albums with each team’s roster. Completing an album, short of spending a ton of excess money, involves trading with other collectors. A common technical interview question is to find the common characters in a string or the common elements in multiple arrays. Let’s take a look at how to approach such a problem. by Oscar Merida

Published in Owning The Web, December 2022

PHP Puzzles: World Cup Draws

By Oscar Merida

A random draw is straightforward, but we usually have business rules to implement and consider in any solution. With the World Cup kicking off this month, we get a chance to look at one scenario. Can you draw the teams into proper groups before the tournament starts? by Oscar Merida

Published in The Value of the AST, November 2022

PHP Puzzles: Converting Float Strings

By Oscar Merida

Converting data is never as straightforward as we’d initially expect. Users can enter data incorrectly or in the wrong format. On the other hand, computers may not have trouble working with some data. For this article, we look again at floating-point values. by Oscar Merida

Published in The State of PHP, October 2022

PHP Puzzles: Fractional Math

By Oscar Merida

We’ve seen how working with floating-point values can be problematic. What if we had a class that worked with fractions directly by tracking the numerator and denominator as integers? Let’s see if it’s possible. by Oscar Merida

Published in Making Code, September 2022

PHP Puzzles: Decimals to Fractions

By Oscar Merida

In this installment, we look again at working with floating-point values. We approach how to take a decimal number and represent it as a fraction. by Oscar Merida

Published in PHP Blueprint, August 2022

PHP Puzzles: The Birthday Paradox

By Oscar Merida

We look at a solution to a problem that is not intuitive at first glance—the birthday paradox. Instead of calculating probabilities directly, we’ll use a simple simulation to solve the problem. by Oscar Merida

Published in Database Freedom, July 2022

PHP Puzzles: Clues for Hues

By Oscar Merida

In the last two months, we saw how to control randomness. This month, we let users guess the random sequence created by the program.

Published in Another Bright Idea, June 2022

PHP Puzzles: Controlled Randomness

By Oscar Merida

PHP Puzzles: Controlled Randomness

Published in One Last Slice, May 2022

PHP Puzzles: Making Some Change

By Oscar Merida

This article looks at a practical math problem most developers are likely to run into at some point. We’re given some amount of money and asked to figure out how to distribute it. Did you remember that computers are not very good at floating-point math?

Published in Testing The Core, April 2022

PHP Puzzles: Finding Prime Factors

By Oscar Merida

We’re building on a previous puzzle for finding integer factors. In this article, we look at how to find prime factors before turning to one more puzzle involving integer division.

Published in World Backup Day, March 2022

PHP Puzzles: Finding Integer Factors

By Oscar Merida

This article looks at solutions for finding integer factors for a given integer. Another way to put this problem is to decompose an integer into a multiple of two smaller integers. Besides hearkening back to Algebra classes of yore, we’ll discuss applications of this technique. by Oscar Merida

Published in Parallelize Your Code, February 2022

PHP Puzzles: Infamous Fizz Buzz

By Oscar Merida

Let’s start the year looking at a classic interview question—Fizz Buzz. It’s misused to screen applicants and may not be testing for what it thinks it is. Nonetheless, it doesn’t hurt to be prepared if you encounter it. We’ll look at various approaches to solve it. by Oscar Merida

Published in Domain-Driven Resolutions, January 2022

PHP Puzzles: Breakeven Point

By Oscar Merida

This month we are moving on from shifting money around time to focusing on costs at a specific moment in time. Join me as we tackle the break-even problem from last month. But first, we’ll step through it, analyzing it algorithmically to design our solution. by Oscar Merida

Published in The Zen of Mindful Programming, December 2021

PHP Puzzles: Compounding Interest

By Oscar Merida

Last month, we looked at how to output an amortization table to see how compounding interest affects some amount of money. Printing out such a table assumes we have a certain set of inputs. Moreover, it’s tedious, even simple for a computer to do. Let’s look at other ways to calculate the time value of money. by Oscar Merida

Published in The Art of Data, November 2021 —Available for Free

PHP Puzzles: Time Value of Money

By Oscar Merida

Is it better to get $100 today or $110 in one years time? The answer’s not straightforward because you could use $100 today to potentially earn more than $10 over 12 months. How do you know what to do? For that, you need to know how to calculate a rate of return or use it to compare amounts of money at different times. Hold on for a bit, we’re bending the time—space (money?) continuum.

Published in Decrypting Cryptography, October 2021

PHP Puzzles: Sending and Receiving Polybius Ciphers

By Oscar Merida

Ciphers come in many different forms and have been used since ancient times to encode and decode vital messages. Today, we use complicated mathematics to encrypt and decrypt messages. Typically, we depend on shared and secret keys to ensure the message is only readable by the intended recipients. What if you don’t have the computing power of a modern device at your disposal? This month, let’s look at using Polybius Squares to share secret messages.

Published in Testing Assumptions, May 2021

Streamlining Behat

By Oscar Merida

Behat, and feature tests overall, are crucial for giving you confidence that when you refactor code, you don’t change how an application works and for helping you understand how an application behaves in practice. Investing in integration and functional tests is worth it in the long term, and in this article, we’ll see how I also updated my Behat setup to run browser tests in Chrome.

Published in Testing Assumptions, May 2021 —Available for Free