|
-
July 1st, 2018, 10:54 AM
#17
Re: How exactly does recursion work with iterators?
 Originally Posted by Kingdominth4
When you talk about "urns", what's the story behind your naming convention?
I used the term "urn" because this problem reminded me of the so called Urn problems I struggled with when studying basic probability theory a long time ago,
https://en.wikipedia.org/wiki/Urn_problem
The first version in my post #10 is a straightforward implementation of my solution strategy from #4. I always try to get something up and working as quickly as possible and then usually spend quite some time refining that solution so it becomes as simple and fast as possible. The result this time is in #15. It's nothing special but a fairly typical example of modern C++, at least that's what I hope. And I'm glad to hear it seems to be working correctly.
Is there a kind of general or abstract way of tackling this problem that I can read up about.
I always go about problem solving in the same manner. First I try to reduce the problem to a standard problem because then there's often a known best solution (algorithm) available. In this case there were two standard problems "finding all connected components of a graph" and "generating all 2-subsets of an n-set".
Second I try to implement the solution using features at the highest abstraction level available in the language. In C++ it means selecting data structures and algorithms from the standard library but also using things like lambda expressions, foreach loops and smart pointers.
When it comes to large scale organization of programs I apply object orientation and increasingly functional programming concepts (like say preferring immutability).
I think problem solving on a computer is very fun and that's why I stole your problem instead of helping you. But maybe it turned out right because now you have a working solution to look at.
Last edited by wolle; July 2nd, 2018 at 02:34 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|