#import "@local/handout:0.1.0": *
#import "@preview/cetz:0.4.2"

#show: handout.with(
  title: [Warm-Up: Passing Balls],
  by: "Mark",
)

#problem()
Twelve people are standing in a circle. Each is assigned a number between 1 and 12. \
Participants numbered 1, 2, 3, and 4 hold red, green, yellow, and black balls, respectively. \
Everyone else is empty-handed.

#v(2mm)

Each participant can pass their ball to any student that is exactly 5 positions away. \
Balls cannot be passed to someone who has one in hand.

#v(2mm)

After a number of passes, the first four participants again hold all the balls. \
Participant 1 has a black ball. Which balls are held by participants 2, 3, and 4?

#solution([
  The graph of possible moves is isomorphic to a circle (since 5 and 12 are coprime), \
  so the order of the balls cannot be changed as they are passed around.

  #v(2mm)

  Therefore, the balls will stay in their initial (cyclic) order:

  #v(2mm)

  #{
    let s = 0.7 // scale
    let t = 12pt * s // text size
    let radius = 0.35

    let pts = (
      (0 * s, 3 * s),
      (1 * s, 2 * s),
      (2 * s, 1 * s),
      (3 * s, 0 * s),
      (2 * s, -1 * s),
      (1 * s, -2 * s),
      (0 * s, -3 * s),
      (-1 * s, -2 * s),
      (-2 * s, -1 * s),
      (-3 * s, 0 * s),
      (-2 * s, 1 * s),
      (-1 * s, 2 * s),
    )

    let pts_shuf = (
      (0 * s, 3 * s), // 1
      (1 * s, -2 * s), // 6
      (-2 * s, 1 * s), // 11
      (3 * s, 0 * s), // 4
      (-2 * s, -1 * s), // 9
      (1 * s, 2 * s), // 2
      (0 * s, -3 * s), // 7
      (-1 * s, 2 * s), // 12
      (2 * s, -1 * s), // 5
      (-3 * s, 0 * s), // 10
      (2 * s, 1 * s), // 3
      (-1 * s, -2 * s), // 8
    )

    table(
      stroke: none,
      align: center,
      columns: (1fr, 1fr, 1fr),
      cetz.canvas({
        import cetz.draw: *

        set-style(stroke: (thickness: 0.4mm, paint: black))
        line(..pts_shuf, close: true)

        let i = 1
        for p in pts {
          circle(p, radius: radius * s, fill: if i == 1 {
            ored
          } else if i == 2 {
            ogreen
          } else if i == 3 {
            oorange
          } else if i == 4 {
            oblue
          } else { white })

          content(p, text(
            fill: if i <= 4 {
              white
            } else {
              black
            },
            size: t,
            [*#i*],
          ))
          i = i + 1
        }
      }),
      cetz.canvas({
        import cetz.draw: *

        set-style(stroke: (thickness: 0.4mm, paint: black))
        line(..pts, close: true)

        let i = 1
        for p in pts {
          let l = calc.rem(((i - 1) * 5), 12) + 1


          circle(p, radius: radius * s, fill: if l == 1 {
            ored
          } else if l == 2 {
            ogreen
          } else if l == 3 {
            oorange
          } else if l == 4 {
            oblue
          } else { white })

          content(p, text(
            fill: if l <= 4 {
              white
            } else {
              black
            },
            size: t,
            [*#l*],
          ))
          i = i + 1
        }
      }),
      cetz.canvas({
        import cetz.draw: *

        set-style(stroke: (thickness: 0.4mm, paint: black))
        line(..pts, close: true)

        let i = 1
        for p in pts {
          let l = calc.rem(((i - 1) * 5), 12) + 1


          circle(p, radius: radius * s, fill: if l == 1 {
            oblue
          } else if l == 2 {
            oorange
          } else if l == 3 {
            ored
          } else if l == 4 {
            ogreen
          } else { white })

          content(p, text(
            fill: if l <= 4 {
              white
            } else {
              black
            },
            size: t,
            [*#l*],
          ))
          i = i + 1
        }
      }),
    )
  }
])
