# 2019 to every day of the month

The grumpy professor looked at his class and said - ok so now it is 2019 can you use the four digits individually with *, +, -, /, ^ (raise to the power of) and ! to make each day of the month? You can also use the square root function he said, but if you want to use the cube root you will need to generate a 3 first from the numbers. You can use as many brackets ( ) as you want, but double triple etc. factorials are not allowed - so for example 5!! = 120! Note that you are not allowed to put 2 and 0 together to make 20 or 2 and 9 together to make 29. In each solutions every number must be used and used once only and used as 2, 1, 0 or 9.

He smiled at his class and said "I wonder if any of you will be up for this challenge". Then he narrowed his eyes and said "In time I believe I will have a complete solution for you".

Can you provide a solution. Do you think the professor really has a solution?

• I can't seem to find a solution for $29$, but I did find an approximation (that I will try making more accurate): $$\sqrt{\sqrt{2\times (9!-10)}}= 29.18739\ldots$$ This uses concatenation anyways. Jan 12 '19 at 11:31

# The best force is brute force

I decided to create a javascript program to find the solutions.

Here it is:

"use strict";
var MIN_RANGE = 1;
var MAX_RANGE = 31;
var MAX_ROOTS_AND_FACTORIALS = 4;

var tablef = [1];

for (var i = 1; i <= 20; i++) {
tablef[i] = tablef[i - 1] * i;
}

return isNaN(x) || !isFinite(x);
}

function fact(i) {
return tablef[i] || NaN;
}

function sqrt(i) {
return bad(i) || i < 0 ? NaN : Math.sqrt(i);
}

var funcsCom = [
function plus(a, b) { return {v: a.v + b.v, s: "(" + a.s + " + " + b.s + ")"}; },
function mult(a, b) { return {v: a.v * b.v, s: "(" + a.s + " * " + b.s + ")"}; }
];

var funcsNonCom = [
function sub(a, b) { return {v: a.v - b.v,        s: "(" + a.s + " - " + b.s + ")"};        },
function div(a, b) { return {v: a.v / b.v,        s: "(" + a.s + " / " + b.s + ")"};        },
function pow(a, b) { return {v: a.v ** b.v,       s: "(" + a.s + " ^ " + b.s + ")"};        },
function rad(a, b) { return {v: a.v ** (1 / b.v), s: "Root[" + a.s + "] of (" + b.s + ")"}; }
];

var funcs1 = [
function f(a) { return {v: fact(a.v), s: "(" + a.s + ")!"};    },
function s(a) { return {v: sqrt(a.v), s: "sqrt(" + a.s + ")"}; }
];

function rework1(op, array, a) {
var s = array.slice(0);
try {
s[a] = op(s[a]);
if (bad(s[a].v)) return [];
return s;
} catch (x) {
return [];
}
}

function rework2(op, array, a, b) {
try {
var k = op(array[a], array[b]);
if (bad(k.v)) return [];
var s = [k];
for (var i = 0; i < array.length; i++) {
if (i !== a && i !== b) s.push(array[i]);
}
return s;
} catch (x) {
return [];
}
}

function tryPermutation(array, others, target) {
if (array.length === 0) return "";
if (array.length === 1) {
try {
return target === array[0].v ? array[0].s : "";
} catch (x) {
return "";
}
}
for (var a = 0; a < array.length; a++) {
if (array.length >= 2) {
for (var b = a + 1; b < array.length; b++) {
for (var f in funcsCom) {
var z = tryPermutation(rework2(funcsCom[f], array, a, b), others, target);
if (z !== "") return z;
}
for (var f in funcsNonCom) {
z = tryPermutation(rework2(funcsNonCom[f], array, a, b), others, target);
if (z !== "") return z;
z = tryPermutation(rework2(funcsNonCom[f], array, b, a), others, target);
if (z !== "") return z;
}
}
}
if (others > 0) {
for (var f in funcs1) {
var z = tryPermutation(rework1(funcs1[f], array, a), others - 1, target);
if (z !== "") return z;
}
}
}
return "";
}

function tryPermutationAll(array, target) {
for (var s = 0; s <= MAX_ROOTS_AND_FACTORIALS; s++) {
var z = tryPermutation(array, s, target);
if (z !== "") return z;
}
return "";
}

function search(array, i) {
if (i > MAX_RANGE) return;
var z = tryPermutationAll(array, i);
if (z !== "") {
document.write("Found " + i + " = " + z + "<br>");
} else {
document.write("Dunno " + i + "<br>");
}
setTimeout(function() { search(array, i + 1); }, 10);
}

function format(a) {
var s = [];
for (var i = 0; i < a.length; i++) {
s[i] = {v: a[i], s: "" + a[i]};
}
return s;
}

setTimeout(function() {
search(format([0, 1, 2, 9]), MIN_RANGE);
}, 10);


That MAX_ROOTS_AND_FACTORIALS is the number of arbitrarily inserted square roots and factorials. You could make this number arbitrarily higher, but then the time that it will take to calculate will increase exponentially, so you would prefer to keep it as low as possible.

This is the output:

Found 1 = ((2 - (0 + 1)) ^ 9)
Found 2 = (((0 + 1) ^ 9) * 2)
Found 3 = (9 / ((0 + 1) + 2))
Found 4 = ((9 - (0 + 1)) / 2)
Found 5 = (((0 + 1) + 9) / 2)
Found 6 = (9 - ((0 + 1) + 2))
Found 7 = (9 - ((0 + 1) * 2))
Found 8 = (((0 + 1) - 2) + 9)
Found 9 = ((2 - (0 + 1)) * 9)
Found 10 = (9 - ((0 + 1) - 2))
Found 11 = (((0 + 1) * 2) + 9)
Found 12 = (((0 + 1) + 2) + 9)
Found 13 = ((((0)! + 1) + 2) + 9)
Found 14 = ((9 - ((0)! + 1)) * 2)
Found 15 = ((((0 + 1) + 2))! + 9)
Found 16 = ((9 - (0 + 1)) * 2)
Found 17 = ((2 * 9) - (0 + 1))
Found 18 = (((0 + 1) * 2) * 9)
Found 19 = ((2 * 9) + (0 + 1))
Found 20 = (((0 + 1) + 9) * 2)
Found 21 = ((((0)! + 9) * 2) + 1)
Found 22 = ((((0)! + 1) + 9) * 2)
Found 23 = ((((2 ^ 0) + sqrt(9)))! - 1)
Found 24 = ((9 - 1) * ((0)! + 2))
Found 25 = (((0 + 1) - (sqrt(9))!) ^ 2)
Found 26 = ((((0)! + 2) * 9) - 1)
Found 27 = (((0 + 1) + 2) * 9)
Found 28 = ((((0)! + 2) * 9) + 1)
Dunno 29
Found 30 = ((1 + 9) * ((0)! + 2))
Found 31 = (sqrt((2 ^ ((0)! + 9))) - 1)

So, what about 29?

The program takes some long time to complete, and > 99% of that time, it is trying to solve the number 29. For all the others, it can find a solution using MAX_ROOTS_AND_FACTORIALS = 2 in a few seconds. So, I'm pretty sure that 29 is unsolvable.

I'm using MAX_ROOTS_AND_FACTORIALS as 4 here. I tried it with 5 and it was taking a too long time, and I gave up waiting.

Does the professor have a solution?

Only if the current month is February, 2019!

• like the program approach +1 :) Jan 12 '19 at 2:06
• Very impressive .... You get my plus one ...
– tom
Jan 12 '19 at 12:34
• Do you think the professor has a solution?
– tom
Jan 12 '19 at 12:35
• @tom Edited the answer. Jan 12 '19 at 13:30

Complete (maybe?)

1

$$(\sqrt{9} - 2)*1 + 0$$

2

$$(\sqrt{9} - 2) + 1 + 0$$

3

$$(\sqrt{9}) + (2*0*1)$$

4

$$(\sqrt{9}) + 1 + (2*0)$$

5

$$(\sqrt{9}) + 2 + (1*0)$$

6

$$(\sqrt{9}) + 1 + 2 + 0$$

7

$$(\sqrt{9}) + 1 + 2 + 0!$$

8

$$9 - 1 + (0*2)$$

9

$$9 + (1*2*0)$$

10

$$9 + 1 + (0*2)$$

11

$$9 + 2 + (1*0)$$

12

$$9 + 2 + 1 + 0$$

13

$$9 + 2 + 1 + 0!$$

14

$$9 + (2+1)! - 0!$$

15

$$9 + (2+1)! + 0$$

16

$$9 + (2+1)! + 0!$$

17

$$\sqrt{9}! * (2+1) - 0!$$

18

$$\sqrt{9}! * (2+1) - 0$$

19

$$\sqrt{9}!* (2+1) + 0!$$

20

$$9*2 + 1 + 0!$$

21

$$(2+1+0!)! - \sqrt{9}$$ (this one took me a while)

22

$$(\sqrt{9}+1+0)! -2$$

23

$$(\sqrt{9}+2-0!)! -1$$

24

$$(9-1)(0!+2)$$

25

$$(\sqrt{9}+2-0!)! +1$$

26

$$(\sqrt{9}+1+0)! +2$$

27

$$(2+1+0!)! + \sqrt{9}$$

28

$$(9*(2+1)) + 0!$$

29

I can only find a solution to 29 with multifactorials, which are not the kind of double factorial the OP said was illegal in their post. The 29 version is $$(9-1)!!!! - 2 - 0!$$

30

$$(9+1)(2+0!)$$

31

$$\sqrt{2^{9+1}} - 0!$$ (thanks @VictorStafusa)

• $\sqrt{2^{9+1}} - 0!$ Jan 11 '19 at 18:02
• Surely OP does say your solution for 29 is out: "double triple etc. factorials are not allowed". Although OP is incorrect to say 5!! = 120! because 5!! = 15. Jan 11 '19 at 20:19
• @WeatherVane The OP could have meant what is normally (5!)! when they said 5!!. Multifactorials as they are defined have not been specifically disallowed; just things like (5!)! are. Jan 11 '19 at 20:36
• Great answer, but I'm afraid your solution for 29 is not allowed.... Plus one though
– tom
Jan 12 '19 at 12:25
• Good work, but do you think the professor has a solution?
– tom
Jan 12 '19 at 12:42

My take on 29

29 is a prime number so it isn't possible to simply obtain from multiplying two numbers together or dividing them. It also won't be possible using powers unless you make a power with infinite decimals. Factorials are out of the question as well. With this in mind it is only possible to make 29 by using addition or subtraction and this is what makes it so difficult to obtain 29. At least 1-2 digits will be used to make a number to add to or subtract from another number which will constrain the number of digits used to make both numbers. Saying this, it is clear to see that given how small all of the digits are, it is impossible to make 29. However it may be possible to make a number which closely resembles 29 by using some magic combination that works with an infinite trail of decimals... in time I believe we will know for sure!

This is how I got the answer

So (depending on how strict the rules are) it isn't possible to make 29 so there is no solution...

HOWEVER

The professor states "In time I believe I will have a complete solution for you" and the month of February in 2019 has 28 days so the professor does have a solution but on the condition that it is currently February!

• Great work.... Do you think the professor has a solution?
– tom
Jan 12 '19 at 12:37
• edited my answer to reflect this
Jan 12 '19 at 13:15
• Great job well done, you got it, but of all the answers I find it hard to give you the check marker to say it is solved because you haven't included the solution for relevant numbers.
– tom
Jan 12 '19 at 13:24
• Yea...im not going to provide those because it would be disingenuous since I seen everyone else do it without 29
Jan 12 '19 at 13:28
• each answer has its merits and it is impossible to share the correct tag... So I upvoted all the useful answers and had to make a choice. Sorry if you don't agree with it, thanks for your very useful contributions. The only other point I think relevant here is that computer methods were not excluded the way they are in some questions and a full program listing was provided....
– tom
Jan 12 '19 at 15:46

All answers except one:

29, which I gave an approximate answer for. I'm not sure it's actually possible to find, but I'll continue trying to find an answer.

1: $$1 + (2 * 9 * 0)$$
2: $$2 + (1 * 9 * 0)$$
3: $$1 + 2 + (9 * 0)$$
4: $$\sqrt9 + 1 + (2 * 0)$$
5: $$\sqrt9 + 2 + (1 * 0)$$
6: $$9 - 2 - 1 - 0$$
7: $$9 - 2 + (1 * 0)$$
8: $$9 - 1 + (2 * 0)$$
9: $$9 + (1 * 2 * 0)$$
10: $$9 + 1 + (2 * 0)$$
11: $$9 + 2 + (1 * 0)$$
12: $$9 + 2 + 1 + 0$$
13: $$9 + 2 + 1 + 0!$$
14: $$((\sqrt9)! * 2) + 1 + 0!$$
15: $$(2 + 1 + 0!)! - 9$$
16: $$(9 * 2) - 1 - 0!$$
17: $$(9 * 2) - 1 + 0$$
18: $$(9 * 2) + (1 * 0)$$
19: $$(9 * 2) + 1 + 0$$
20: $$(9 * 2) + 1 + 0!$$
21: $$(2 + 1 + 0!)! - \sqrt9$$
22: $$(9 + 1 + 0!) * 2$$
23: $$(\sqrt9 + 1)! - 2 + 0!$$
24: $$(\sqrt9)! * (2 + 1 + 0!)$$
25: $$((\sqrt9)! - 1 + 0)^2$$
26: $$(9 * (2 + 1)) - 0!$$
27: $$(9 * (2 + 1)) + 0$$
28: $$(9 * (2 + 1)) + 0!$$
29: $$\sqrt{((\sqrt9)!)! + ((2 + 1)! - 0!)!}$$ (approximately 28.983)
30: $$(2 + 1 + 0!)! + (\sqrt9)!$$
31: $$2^{(\sqrt9)! - 1} - 0!$$

• Great work, do you think the professor has a solution?
– tom
Jan 12 '19 at 12:41

With the exception of 29:

1 = (2 + 9) * 0 + 1
2 = (1 + 9) * 0 + 2
3 = 9 * 0 + 1 + 2
4 = (9 + 0 - 1) / 2
5 = (9 + 0 + 1) / 2
6 = 9 - 0 - 1 - 2
7 = 9 - 0 * 1 - 2
8 = 9 - 0 * 2 - 1
9 = 9 - 0 * 2 * 1
10 = 9 + 0 * 2 + 1
11 = 9 + 0 * 1 + 2
12 = 9 + 0 + 1 + 2
13 = 9 + 0! + 1 + 2
14 = (9 - 2) * (0! + 1)
15 = 9 + 0 + (1 + 2)!
16 = 9 * 2 - 0! - 1
17 = 9 * 2 - 0 - 1
18 = 9 * 2 + 0 * 1
19 = 9 * 2 + 0 + 1
20 = 9 * 2 + 0! + 1
21 = (0! + 1 + 2)! - sqrt(9)
22 = (9 + 2) * (0! + 1)
23 = ((9 - 0!) / 2)! - 1
24 = (9 - 1) * (0! + 2)
25 = (sqrt(9) + 0! + 1) ^ 2
26 = 9 * (1 + 2) - 0!
27 = 9 * (0 + 1 + 2)
28 = 9 * (1 + 2) + 0!
29 =
30 = (9 + 1) * (0! + 2)
31 = sqrt( 2 ^ (9 + 0!) ) - 1

Extra treatment of 29:

When we take the phrasing of the exercise literally, juxtaposition of digits has been interdicted only for the combination of 2 and 0 into 20, and 2 and 9 into 29. Assuming that every other combination would be legal ...

29 = 21 + 9 - 0!

• Great work, do you think the professor has a solution?
– tom
Jan 12 '19 at 12:38

2 0 1 9 + - / * ^ sqrt () !

1

1 = (sqrt(9) - (2 + 1)) + (0!)

2

2 = sqrt(9) - (2 - 1) + 0

3

3 = sqrt(9) + (2 + 1) * 0

4

4 = sqrt(9) + (2 - 1) + 0

5

5 = sqrt(9) + 2 + 0 * 1

6

6 = sqrt(9) + 2 + 1 + 0

7

7 = sqrt(9) + 2 + 1 + 0!

8

8 = 9 - (2 - 1) + 0

9

9 = 9 + (2 - (1 + 0!))

10

10 = 9 + (2 - 1 + 0)

11

11 = sqrt(9)^2 + 1 + 0!

12

12 = 9 + 1 + 2 + 0

13

13 = 9 + 2^(0! + 1)

14

14 = 9 + (2 + 1)! - 0!

15

15 = (2 + 1 + 0!)! - 9

16

16 = 9 + (2 + 1)! + 0!

17

17 = 9 * 2 - 1 + 0

18

18 = 9 * 2 + 1 * 0

19

19 = 9 * 2 + 1 + 0

20

20 = 9 * 2 + 1 + 0!

21

21 = (sqrt(9) + 1)! - (2 + 0!)

22

22 = (sqrt(9) + 1)! - 2 + 0

23

23 = (sqrt(9) + (2 - 1))! - 0!

24

24 = (sqrt(9) + (2 - 1))! + 0

25

25 = (sqrt(9) + (2 - 1))! + 0!

26

26 = 9 * (2 + 1) - 0!

27

27 = (2 + 1)! + sqrt(9) + 0

28

28 = sqrt(9)^(2 + 1) + 0!

29

29 = no

30

30 = (9 + 0!) * (2 + 1)

31

31 = sqrt(2^(9 + 1)) - 0!

The Current month would have to be february as far as I can tell, because I spent a solid hour on 29. I even started using a calculator but I wasn't able to find it, maybe there's some combination of roots and factorials that could do it but I don't want to take the time to find out since there's a huge possibility that there is not an answer.

• Hi Will, welcome to puzzle SE, hope you enjoyed the challenge. You seem to have the answer correct, though I did not check every box. Well done and plus one from me, but I am afraid that the problem was already solved.. see the green check mark above next to the answer listed at the top. Welcome again, best wishes tom
– tom
Jan 13 '19 at 10:08