[Kattis] Splat

Jackson Pollock, Red Composition (1946). Image courtesy Christie's.

Jackson Pollock, Red Composition (1946). Image courtesy Christie’s.


Programming is known as where logic intertwines with creativity, but this time logic actually meets art. The puzzle deals with Jackson Pollock’s famous painting style: dripping paint randomly on the canvas. You can find the puzzle here. Let’s solve it in Python!

This is the code for the solution:

# Youtube.com/@codedabacus
# Kattis - Splat

# libraries
from math import sqrt, pi

# total paintings
c = int(input())

# receive all painting descriptions
for _ in range(c):
  # total drops of paint for this painting 
  n = int(input())

  # storage for the drops
  drops = []

  # receive all drops
  for _ in range(n):
    x, y, v, col = input().split()
    r = sqrt(float(v) / pi) # compute the radius
    drops.append([float(x), float(y), r, col]) # update the container

  # reverse the drops
  drops = drops[::-1]

  # total queries 
  m = int(input())

  # receive all queries 
  for _ in range(m):
    # the coordinates of the query
    x, y = map(float, input().split())

    # check all drops
    for drop in drops:
      # drop's info
      d_x, d_y, d_r, d_color = drop 

      # compute the distance between this query and this drop
      dist = sqrt((x - d_x) ** 2 + (y - d_y) ** 2)

      if dist < d_r:



Here you can find more about the puzzle and its solution:




Related Images: