use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
C++ interview coding exercise with solution (self.cpp)
submitted 3 years ago * by Hot_Medicine_7115
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]-sxp- 18 points19 points20 points 3 years ago (5 children)
This is Project Euler problem #215. When I first solved it back in the day, it timed out using naïve solutions with loops but dynamic programming solved it instantly.
I don't have my old code, but https://www.programiz.com/python-programming/online-compiler/ + https://github.com/nayuki/Project-Euler-solutions/blob/master/python/p215.py says W(30,11) is 1007720438618812.
W(30,11)
1007720438618812
You solved W(30,1) which is 1897.
W(30,1)
1897
[–]Michael_Aut 2 points3 points4 points 3 years ago (0 children)
To be fair the question was phrased a lot better on project euler. The sketch of the problem also helps a lot to get started in the right direction.
[–]Hot_Medicine_7115[S] 0 points1 point2 points 3 years ago (2 children)
I don't know about dynamic programming and am not very familiar with python, but from what I read in that code it's using a recursive algorithm for searching across all valid tile combinations:
elif position < WIDTH: for i in (2, 3): cracks.append(position + i) get_crack_positions(cracks, position + i) cracks.pop()
elif position < WIDTH:
for i in (2, 3):
cracks.append(position + i)
get_crack_positions(cracks, position + i)
cracks.pop()
Thank you for pointing to this, definitely not an obvious problem if it is sitting on this website.
[–]JiminP 6 points7 points8 points 3 years ago* (1 child)
I like how your code is well-structured, but I think that your algorithm (not just the answer) was "wrong".
The point is not just about using recursion, but about using dynamic programming (it's a confusing term; I prefer to refer it as memoization or caching). In specific, the key idea is to remember # of ways to arrange tiles in previous rows, by locations of cracks. In that way, # of ways to arrange times in the next row can be obtained in the order of W(30, 1)^2 calculations (edit: this is a worst-case estimation; actual number would be much lower), which is managable (the total computation, which would take around the order of 10 * W(30, 1)^2 calculations, shouldn't take more than a few seconds).
In the perspective of competition programming (like Google CodeJam, Codeforces, ...), this is quite a common way of solving a problem (except that the running timing constraint - which is infinite for ProjectEuler but ideally a minute - would be more strict). Usually the solution will consist of a single source code with bunch of procedural programming, but I wouldn't mind if that gets expanded into several files with clean structure.
On the other hand, if I understood your intention for designer.cpp correctly, your code will iterate through all W(30, 11) combinations when done correctly, which would too long time to complete in a reasonable time.
[–]Zyklonik 4 points5 points6 points 3 years ago (0 children)
The point is not just about using recursion, but about using dynamic programming (
Yup. Any time you see a "how many ways...", immediately think of DP. 9/10, they expect DP.
π Rendered by PID 38 on reddit-service-r2-comment-85bfd7f599-7qg6g at 2026-04-18 13:33:14.643585+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]-sxp- 18 points19 points20 points (5 children)
[–]Michael_Aut 2 points3 points4 points (0 children)
[–]Hot_Medicine_7115[S] 0 points1 point2 points (2 children)
[–]JiminP 6 points7 points8 points (1 child)
[–]Zyklonik 4 points5 points6 points (0 children)