Tuesday, September 27, 2022
HomePuzzlesarithmetic - Arrange ten cash in a bowling formation. Fewest pennies to...

# arithmetic – Arrange ten cash in a bowling formation. Fewest pennies to take away so no three pennies that stay have facilities that kind an equilateral triangle?

Not a proof, however if you happen to have a look at it as a satisfiability downside, Z3 (SMT solver) will be of some assist right here:

``````from z3 import *

o = Optimize()

# Let's quantity the pins from 0 to 9, it is a lot simpler that means
# A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, I = 8,
# J = 9
pins = [Bool("%d" % i) for i in range(0, 10)]

# Since there are 15 equilateral triangles, let's
# add them as constraints to be solved
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins),
Or(pins, pins, pins)))

# reduce takes a variable, so let's cross
# in sum since we won't cross all the listing
o.reduce(Sum(pins))

# examine for satisfiability and
# get the pins to be eliminated if it
# is satisfiable
if o.examine() == sat:
# Get the mannequin
m = o.mannequin()
# Print the variety of pins to be eliminated
print("The variety of pins to be eliminated is %s" % str((m.consider(Sum(pins)))))
# Print the pins to be eliminated
print("The pins to be eliminated are: ", finish="")
for i in vary(0, 10):
if m.consider(pins[i]) == True:
print("%d" % i, finish=" ")
print()
else:
print("The downside is unsatisfiable")

``````

This spits out:

``````The variety of pins to be eliminated is 4
The pins to be eliminated are: 0 4 7 8
``````

Which is similar as A, E, H, and I if you happen to map 0 to A, 1 to B, and so forth.

RELATED ARTICLES