There are 104 students at The School of Hat Design. There are 104 gerbils in a row out on the playfield. Shockingly, none of them is wearing a hat. So student 1 goes by and puts a hat on every gerbil. But student 2 goes by and slyly removes the hat from every other gerbil, starting with gerbil 2. Then student 3 goes by and changes the hat state of every third gerbil, starting with gerbil 3. (That is, if the gerbil is wearing a hat, he removes it. If the gerbil has no hat, he supplies a hat.) Student 4 goes by and changes the hat state of every fourth gerbil, starting with gerbil 4.

Imagine that this continues until all 104 students have followed the pattern of student N changing the hat state of every Nth gerbil, starting with gerbil N.

At the end, how many gerbils will be wearing a hat?

 Nov 22, 2020

This is also known as the "locker problem"


The number of  gerbils   who will  be wearing hats  at the  end will be number of perfect squares between 1 -104 inclusive =   10


To see this...let's suppose there are only 4  gerbils and  4  students


H = hat on     O  = hat off



Sudent 1        H H  H  H

Student 2       H O  H  O

Student 3       H O  O  O

Student 4       H  O O  H


Note  that after student 4  passes......the  number of gerbils wearing hats  are  just the  perfect squares from 1-4 inclusive =  2


This result can be generalized  to any N


cool cool cool

 Nov 22, 2020
edited by CPhill  Nov 22, 2020

75 Online Users