### Recent Posts

# Math

## Fun with integers

php > print 1100690227200 / 1099511627776;

1.0010719299316

```
```

`php > print 1100690227200 % 1099511627776;`

PHP Warning: Division by zero in php shell code on line 1

?

php > print PHP_INT_MAX;

2147483647

```
```

`php > print gettype(1100690227200);`

double

!

There is no integer division operator in PHP.

Operands of modulus are converted to integers (by stripping the decimal part) before processing.

*facepalm*

## Prebeaten Basketball

In bowling, you can pre-beat your opponent. If you're leading by more than 30 pins in the 9th frame, there's no way you can lose in the 10th, etc.

Watching my one NBA game of the year tonight, I realized that the same is true for basketball.

Assuming perfect play by the losing team, and passive play by the leading team (letting the shot clock run out), the losers can only close the gap by 3 points every 24 seconds.

## A sequencing problem

I had to implement a function the other day to abbreviate a set of days of the week, taking every sequence of adjacent days and replacing them with a hyphenated range. Comma-separating non-adjacent items.

So, {Mon, Tue, Wed, Fri} would become "Mon - Wed, Fri"

I came up with a really ugly, mishmashy recursive solution for it.

Bigokro suggested a non-recursive, linear-time algorithm which is not terrible.

But I still feel like there's something more elegant out there.

Does anyone know if this kind of algorithm has a name and if there's a canonical solution?

## Zero

Muslim mathematicians invented the concept of zero. So it's ironic that people are opposed to building a mosque on ground zero. Even though it's not on ground zero. And it's not a mosque. Without the Muslims it would be "ground one" or something.

## Multiplication Tables

I've always had a mental hiccup at 7*8. It takes me an extra millisecond to remember that it's 56, or if I remember I have to take an extra second to confirm it - to count up from 49 or something.

It's so ingrained that I apparently have taken for granted for my entire life that other people have the same problem. As it turns out (you already know this :) that's not that case.

## A 4K in the hand is worth 1.88

On the second roll of a play, I had 4 sixes and a five.

4K and Yahtzee were both open.

Obviously, the play would be worth 29 points in 4K, and Yahtzee is only a 1 in 6 chance, with a 2 in 3 chance of getting less than 29 on the next roll.

My heuristic is to *always* roll for Yahtzee on 4K if Yahtzee is open (and sometimes if Yahtzee is closed and Large Straight is open).

Expected outcome in this case is the average of all the possible outcomes: avg(50, 29, 28, 27, 26, 25) = 30.88. Go heuristics.

## Natural 3 of a kind Yahtzee chances

Typically what happens is that on your first roll you get 3 ones, and maybe a potentially useful singleton.

And you've already used the ones box.

So the question is, should you go for Yahtzee here? Or should you try to build off the singleton or just re-roll all five dice?

I suspect that if the probability is reasonably close to 1 in 6, it's probably your best chance at a Yahtzee in the game, and thus worth risking the Yahtzee box on.

There are 3 ways to get to Yahtzee from here, and we can sum their individual probabilities to get the overall chances.

Powered by Drupal - Design by Artinet - Amazon Affiliate

## Recent comments

3 years 4 weeks ago

3 years 9 weeks ago

3 years 16 weeks ago

3 years 16 weeks ago

3 years 38 weeks ago

3 years 41 weeks ago

3 years 44 weeks ago

3 years 44 weeks ago

3 years 44 weeks ago

3 years 44 weeks ago