Cut the eggs into 6 equal units (sixths). Broke = 1 unit, left = 1⁄2 = 3 units, so the 18 he gave away fill the other 2 units.
Plain numbers are given; italic underlined numbers are worked out.
He bought 54 eggs.
Check: broke 9 + gave 18 + left 27 = 54; 27 = 1⁄2 of 54. ✓