Working for 3, albeit very brute-forced. Definitely room for optimizations, and apparently gives the wrong answer for D(18)