In [33]:
import forge
from puzzle.puzzlepedia import puzzlepedia

puzzle = puzzlepedia.parse("""
import functools

projects in range(1, 6+1)
vc in {Mako, Jaws, Killin, Barbara, Robert}

@functools.lru_cache()
def n_investors(p):
  return sum(v[p] for v in vc)

@functools.lru_cache()
def n_investments(v):
  return sum(v[p] for p in projects)

# FIXME: This should have been possible with sum((2**i) * p[v] for i, v in enumerate(vc))
@functools.lru_cache()
def invest_vector(p):
  return Mako[p] + 2 * Jaws[p] + 4 * Killin[p] + 8 * Barbara[p] + 16 * Robert[p]

model.disable_constraints()

#1. A project that Robert Hammerhead did not invest in was immediately after a project that only two sharks invested in.
any(
  (Robert != p) and
  (n_investors(p - 1) == 2) for p in range(2, 6+1)
)

# FIXME: This should have worked: n_investments(Jaws) == n_investments(Mako) * 2
#2. Daymond Jaws invested in twice as many projects as Mako Cuban...
n_investments(Jaws) == 4
n_investments(Mako) == 2
# ...They went in on exactly one project together.
sum(Jaws[p] and Mako[p] for p in projects) == 1

#3. There were exactly two projects neither Killin’ O’Leary or Barbara Cor-gorin’ invested in.
sum(not Killin[p] and not Barbara[p] for p in projects) == 2

#4. Only one shark invested in the second project.
n_investors(2) == 1

#5. The only project Barbara Cor-gorin invested in was one Robert Hammerhead invested in.
n_investments(Barbara) == 1
sum(Barbara[p] and Robert[p] for p in projects) == 1

#6. Mako Cuban and Killin’ O’Leary both invested in a project that immediately followed one that Daymond Jaws invested in.
any(
  (Mako[p] and Killin[p]) and Jaws[p-1] for p in range(2, 6+1)
)

#7. No two sharks invested in the same number of projects. Every shark invested in at least one project.
all_diff([n_investments(v) for v in vc])

#8. Either Robert Hammerhead said no to the fifth project or Daymond Jaws said no to the third project, or both.
(Robert != 5) | (Jaws != 3)

#9. No project had more than three sharks invest in it.
for p in projects:
  n_investors(p) <= 3

#10. Two consecutive projects (including project #4) were invested in by exactly the same set of sharks.
(invest_vector(3) == invest_vector(4)) or (invest_vector(4) == invest_vector(5))

model.grid()
""")


Default constraints disabled

 *	Mako	Jaws	Killin	Barbara	Robert	
1	0	0	0	1	1	
2	0	1	0	0	0	
3	1	0	1	0	1	
4	0	1	1	0	1	
5	0	1	1	0	1	
6	1	1	0	0	1	


In [ ]: