How does one prevent cheating in homeworks?

I was thinking of somehow creating a procedurally generated homeworks, but (1) that's not very easy and (2) the generated homeworks might not contain an equal amount of learning potential. Is there a way to design homeworks so that people will be motivated not to cheat? Then I was thinking of the game The Witness. It's a puzzle game, and does not contain any instructions. In the game, some puzzles took a lot of time for me to solve, but I never considered looking at the solution and I think this is not because of me but because of the game's design. You gain nothing by simply cheating and looking at a solution. On the contrary, you would probably feel bad if you look at a solution. But in real life, even if you assign completing The Witness as a homework, I think students would be still motivated to cheat to get good GPA. Though, if you take your time and design an interesting homework that would not take so much time of the students, and at the same time it would be educational enough to serve the purpose, I think people would be unwilling to share their work with others.