# The Long Way to a Small, Angry Planet (Wayfarers, #1)

### Review:

Loved it. Re­mind­ed me a lit­tle of Mc­Mas­ter Bu­jold's Vorkosi­gan book­s, which is a very good thing.

# The Authorities™ (The Authorities #1)

### Review:

The au­thor's usu­al hu­mour, ap­plied to a sort of de­tec­tive mis­tery? Nice so­lu­tion to the puz­zle, BTW.

Fun, but a notch be­low the Mag­ic 2.0 se­ries or Mas­ter of For­mal­i­ties. Still ert­ty good.

# The Spears of Laconia (Purge of Babylon, #7)

### Review:

Even crack co­caine gets bor­ing af­ter you have had enough.

The se­ries is set­tling in­to a for­mu­la, and start­ing to drag.

# Blood of Tyrants (Temeraire, #8)

### Review:

Gack, I want the last one! I nev­er no­ticed it was not out yet! Ok, pre-ordered :-P

# Brute Force Works

Last night, Juan­jo Con­ti tweet­ed this:

Or, in en­glish: "Us­ing ex­act­ly once the dig­its 1,3,4 and 6, and any of the four ba­sic op­er­a­tions, ob­tain 24."

I first spent a cou­ple of min­utes think­ing about it and then it hit me: there is no point in think­ing this sort of prob­lem, be­cause:

1. Brute for­c­ing it will take less time

2. What you do while "think­ing" it is sort of lame, is­n't it?

So, here is a more-or-­less gen­er­al so­lu­tion for any of these prob­lem­s.

``````from __future__ import print_function, division
import itertools

numbers = ['1','3','4','6']
target = 24

# Having '' as an operation allows for solution (14-6)*3, which
# may or may not be valid depending on rule interpretation.
operations =  ['*','/','+','-','']

t1='(({0}{4}{1}){5}{2}){6}{3}'
t2='{0}{4}({1}{5}({2}{6}{3}))'

for nums in itertools.permutations(numbers):
for ops1 in itertools.combinations_with_replacement(operations, 3):
for ops2 in itertools.permutations(ops1):
for t in (t1, t2):
s = t.format(*(nums+ops2))
#print(repr(s))
try:
if eval(s) == target:
print(s)
except (ZeroDivisionError, SyntaxError, TypeError):
continue``````

Of course you can make it solve any problem of this class by adjusting numbers and target. There is also a possible extra solution if `eval(s) == -tar­get` where you just need to add a unary - to the expression, but who cares.

Did I miss some­thing? Is this re­al­ly a gen­er­al so­lu­tion?