Writing

Answering How Many with Software

How many? is a typical question that comes up when programming. I use a variety of software for projects and there are subtly different ways to answer that question depending on the context.

Here is an alphabetical list of ways I’ve recently answered that question. A more detailed comparison of programming languages can be found on Wikipedia.

Command Line

# How many rows are in this file?
wc -l < file

Golang

// How many elements are in this array?
len(array)

JavaScript

// How many elements are in this array?
array.length

// How many elements in this array are greater than 5?
d3.count(array, (d) => d > 5)

// How many rows are in this Apache Arrow table?
table.numRows

Liquid Tags in Jekyll

<!-- How many elements are in this array? -->
array | size

Python

# How many elements are in this list?
len(list)

# How many elements are in this pandas dataframe?
df.size # including missing values
df.count() # excluding missing values

# How many elements are in this numpy array?
ndarray.size

Ruby

# How many elements are in this array?
array.length
array.count
array.size

# How many rows are in this Active Record table?
table.count

SQL

-- How many elements are in this PostgreSQL array?
array_length(array, 1)

-- How many elements are in this DuckDB list?
len(list)

-- How many rows are in this table?
select count(*) from table

Terraform

# How many elements are in this list?
length(list)

Make Flickr shapes JSON parsable

Update: Flickr has released version 2.0.1 so this is no longer necessary. Thanks Flickr :D

read more »

Internal Type Juggling in PHP 5.2 vs PHP 5.3

There is an undocumented case where the output of an internal function is different in PHP 5.2 vs PHP 5.3 when you pass it an invalid argument.

read more »

Load-bearing Code

The term 'load-bearing code' can be used to refer to software that exhibits the following attributes.

Jerry, these are load-bearing walls, they're not gonna come down!

Cosmo Kramer in the Seinfeld episode "The Chicken Roaster"

I have encountered load-bearing code in legacy open source applications, inherited projects, or debugging production software.

Calculating Different Mii Combinations

How many different Mii designs are possible? I started counting the options, did the math, and here are the results.

AttributeOptions
1Genders2
2Clothing Colors12
3Heights10
4Weights10
5Face Shapes8
6Makeup Types12
7Skin Colors6
8Hair Styles72
9Hair Parts2
10Hair Colors8
11Eyebrows24
12Eyebrow Colors8
13Eyebrow Vertical Steps16
14Eyebrow Size Steps9
15Eyebrow Rotation Steps12
16Eyebrow Horizontal Steps13
17Eye Types42
18Eye Colors6
19Eye Vertical Steps19
20Eye Size Steps8
21Eye Rotation Steps8
22Eye Horizontal Steps13
23Noses12
24Nose Vertical Steps19
25Nose Sizes9
26Lips24
27Lips Colors3
28Lips Vertical Steps19
29Lips Sizes9
30Glasses9
31Glasses Colors6
32Glasses Vertical Steps21
33Glasses Sizes8
34Mustaches4
35Mustache Colors8
36Mustache Vertical Steps17
37Mustache Sizes9
38Moles2
39Mole Vertical Steps31
40Mole Sizes9
41Mole Horizontal Steps17
42Goatee Types4
43Goatee Colors8
Total568

Exceptions

  • 1 hair style (bald) has no color or part
  • 49 hair styles have no part
  • 1 eyebrow style(none) has no color, vertical step, size, rotation or horizontal step
  • 7 eye types have no color
  • 17 lips have no color
  • 1 glasses type (none) has no color, vertical step, or size
  • 1 mustache type (none) has no color, vertical step, or size
  • 1 mole (none) has no vertical step, size, or horizontal step
  • 1 goatee type (none) has no color

Combinations

To determine the number of distinct combinations I used the formula: 568! / (43! * (568-43)!)

Result

Using Wolfram Alpha to solve 568! / (43! * (568-43)!), we can see that there are 88 vigintillion, 613 novemdecillion, 583 octodecillion, 674 septendecillion, 758 sexdecillion, 947 quindecillion, 813 quattuordecillion, 475 tredecillion, 143 duodecillion, 744 undecillion, 24 decillion, 970 nonillion, 165 octillion, 692 septillion, 788 sextillion, 754 quintillion, 421 quadrillion, 531 trillion, 161 billion, 395 million, 650 thousand and 32 Mii Combinations.