German tank problem

Sometimes science is applied in really amazing ways, one of examples is German tank problem. During World War II, the Allies observed that the Nazis created a new model of tank. Total number of manufactured units was unknown, but the Allies, know serial numbers of some tanks. In this case, the first produced tank has serial number starts = 1, the second has serial number = 2, etc. How the Allies could estimate total amount of manufactured tanks?

Answer may be estimated by using simple equitation. Let's assume that N = estimated total amount of enemy tanks, k = amount of observed tanks, m = maximum observed serial number. Then:

N = m - 1 + m/k

Example

We observed enemy tanks with serial numbers: 20, 23, 45, 47, 48. In this case, m=48, k=4, answer can be computed on calculator or for example in R language (I really like to use it as a powerful "calculator"):

> 48 - 1 + 48/4
[1] 59

Other use cases

The same as used for German tank problem was used to estimate amount of sold Apple's products. The customers were asked to upload their serial numbers.

Zapper built from NAND gates

Zapper, what's that?

The zapper is a simple device intended to fight against parasites that, if present in the human body, can do a lot of harm. As far as I know, it's not proved by any scientific source that it actually works, and despite time, it still stays in the zone of unproven/unscientific inventions. Personally, I think that it can work as described.

From a technical point of view, a zapper consists of a square wave generator, a resistor connected to its output that limits the power of the signal delivered to the body and two electrodes. One of the electrodes is connected to the mass of the circuit, second one is connected to mentioned resistor. Frequency can be adjusted from tens of Hz to tens of kHz.

Is it safe?

I don't claim that it is, but personally I think that it is if someone doesn't have cardiac problems. If you want to build it by yourself, you do this on your own risk.

Circuit of a zapper

Almost all Zippers are build from NE555, unfortunately I hadn't has it, so instead I used 4093 (2-input Schmitt NAND gates). The electrodes were made from aluminium foil.

The value of R1 should be 33k.

You can also visit this site to get more similar circuits including the original one.

Interesting way to check statuses returned by functions

If there is a set of bool functions, then sometimes below trick may be used to make the code that checks those values shorter:

bool status = true;
   
status &= foo_1();
status &= foo_2();
status &= foo_1();

printf(status ? "status: OK\n" : "status: NOK\n");

Injecting side effects by abusing comma operator

Comma operator can be used sometimes to inject side effects into expressions:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
    int max = 10;
    double x = 0;

    while (max--, printf("%d\n", max), max) {
        /* sth */
    }

    x = printf("x: %f", x), x = sqrt(x), printf(", sqrt(x): %f\n", x), x;

    return EXIT_SUCCESS;
}

Milionerzy: najlepsza kolejność wykorzystania kół ratunkowych

Grasz w milionerów, masz wszystkie koła ratunkowe i nagle dostajesz makabryczne pytanie. Nie wiesz. Bierzesz koła. Najpierw 50:50, a później publiczność, czy najpierw publiczność, a potem 50:50? Ta dyskusja rozgorzała na joemosterze, wiec i ja postanowiłem się temu przyjrzeć.

Warunki początkowe

Zakładam, że 10% osób zna odpowiedz na pytanie, a reszta zaznacza losową odpowiedz. Publiczność to około kilkadziesiąt osób, jest ich więc na tyle dużo, że można założyć, że odpowiedzi tych którzy strzelają rozłożą się równomiernie. Mamy zatem:

10% - osoby znające odpowiedz
90% - osoby zgadujące

Wariant I, najpierw 50:50

Jeśli weźniemy najpierw 50:50, to zostawimy publiczności wybór między dwiema opcjami, rozkład odpowiedzi będzie wyglądał następująco:

odpowiedz poprawna: 0.5 * 90% + 10% = 55%
odpowiedz błędna:   0.5 * 90% = 45%

Poprawną odpowiedz wskaże 55% głosujących.