about | help
CodingBat code practice

Code Help and Videos >

 MakeBricks Solution Code

Video

MakeBricks is a favorite problem I created for CodingBat, probably because it has more depth than it appears at first. Here I'll walk through one way to solve it.

See also: MakeBricks Introduction , Mod Introduction

Here's the live MakeBricks and the slightly more difficult MakeChocolate problems:
makeBricks  makeChocolate 

(in python: make_bricks  make_chocolate )

Fail #1: not enough bricks

Fail #2: not enough small bricks

Divide and Conquer

Sometimes a problem appears to be a baffling tangle. Often, if you slow down, you can break it down to 2 or 3 cases, and then solve them one at a time. "Divide and Conquer" as Caesar said, and that's what's going on here, focussing on one aspect of the problem at a time.

CodingBat.com code practice. Copyright 2013 Nick Parlante.