Solution to words problem