The Captain’s Shuffle🔀

Mustafa gives his teeth a quick brush with the miswak and adjusts his fez before heading out excited to position himself near to the most illuminated man that day.

note:
If you haven't completed yesterday's puzzle, I'm not about to give away the answer 😁.

If you have completed the puzzle, well done. A new position has been arbitarily set to y34x52.

end note


Mustafa positions himself in position y34x46. He will have a direct view of the illuminated man here.
No matter what happens, Mustafa does not move. As tarawih begins, he notices that not everyone stays for all 8 rakah. Some people leave the mosque earlier and may choose to complete the tarawih prayers at home.

In order for the ranks at the front rows to be filled first, brother Salih instructs brother, Abdi to usher people forward after people have left in an orderly manner.

What follows is a repeating, mechanical process.

Brother Abdi takes his role seriously. Proclaiming, "I'm the captain now!", he administers a well orchestrated shuffle with the following rules.

The rules

The mosque is arranged as rows of people.
- Tarawih consists of 8 rakah, prayed as 4 sets of 2
- After each set of 2 rakah, the following happens:

  1. People leave
    - 3 people leave from the left side
    - This happens in:
    - the front row (y0)
    - and every second row behind it
    - Meaning rows:
    - y0, y2, y4, y6, …

Only these rows lose people directly.

  1. Rows compact left
    - In any affected row:
    - remaining people slide left to fill gaps
    - Supporting columns (X) do not move
    - people slide past them
    - but may not occupy column positions

  2. Rows fill forward (cascade)
    - If a row now has empty spaces on the right:
    - it pulls people from the right end of the row behind
    - The pulled people:
    - join the right side of the row in front
    - This continues row by row
    - until no row can pull more people forward

  3. Repeat
    - Steps 1 → 3 repeat 4 times total
    - once after each set of 2 rakah

Important notes

  • Mustafa’s position is fixed (like a column X)
  • Only the congregation moves
  • Your task is to reason backwards from the final position of the illuminated man

Visual example:

Initial state - before anyone leaves

y0ABCDEF
y1GHIJKL
y2MNOPQR
y3STUVWX

Rows y0 and y2 will lose people.

After 2 rakah - (3 leave from the left)

y0DEF
y1GHIJKL
y2PQR
y3STUVWX

people shuffle left

y0DEF
y1GHIJKL
y2PQR
y3STUVWX

Rows fill forward

  • y0 pulls 3 from the right of y1
  • y2 pulls 3 from the right of y3
y0DEFJKL
y1GHI
y2PQRVWX
y3STU
y0DEFJKL
y1GHI
y2PQRVWX
y3STU

This cascading movement repeats row by row and prayer by prayer.

Rows fill forward again

This is done until there are no spaces left in front of rows with people behind.

y0DEFJKL
y1GHIVWX
y2PQR
y3STU
y0DEFJKL
y1GHIVWX
y2PQR
y3STU

Your task

Given the final observed position of the illuminated man:

From which row did the illuminated man originally start?

Return the row index (y), counting from 0.