14,868,681 members
Home / Discussions / C#

# C#

 Re: Hacking Mycroft Holmes1-Mar-21 11:02 Mycroft Holmes 1-Mar-21 11:02
 Re: Hacking Pete O'Hanlon3-Mar-21 2:03 Pete O'Hanlon 3-Mar-21 2:03
 Re: Hacking Eddy Vluggen2-Mar-21 9:56 Eddy Vluggen 2-Mar-21 9:56
 Re: Hacking Gerry Schmitz2-Mar-21 18:29 Gerry Schmitz 2-Mar-21 18:29
 Knight's tour, recursion, dynamic programming, optimization Kari Trust28-Feb-21 14:30 Kari Trust 28-Feb-21 14:30
 Re: Knight's tour, recursion, dynamic programming, optimization trønderen28-Feb-21 15:59 trønderen 28-Feb-21 15:59
 Re: Knight's tour, recursion, dynamic programming, optimization Kari Trust2-Mar-21 2:04 Kari Trust 2-Mar-21 2:04
 Re: Knight's tour, recursion, dynamic programming, optimization trønderen2-Mar-21 8:53 trønderen 2-Mar-21 8:53
 Kari Trust wrote:I watched a lot of tutorials - on recursion and almost everyone has an example with FibonacciI can see a single reason for using fibonacci to illustrate recursion: To show that it isn't needed. The keyword is tail recursion. Certainly, a good compiler will detect tail recursion and save stack space and call overhead, generating a simple jump to the top of the function (after fixing up the parameter block, of course), changing the recursion to an iteration. You might as well do that yourself ... unless, of course, you are so deeply into recursive thinking that you find it hard to consider fibonacci anything but recursive. (I can imagine mathematicians that are that way, but not many programmers! To me, the obvious way to write a fibonacci-function would be (I consider the sequence to start with 0, labeled the 0th fibonacci number - some people argue details): Copy Code static int fib(int n) { if (n < 2) return n; int prev = 1; int fibn = 1; for (int iteration = 2; iteration < n; iteration++) { int fibnext = fibn + prev; prev = fibn; fibn = fibnext; } return fibn; } Bonus sidetrack (or is it?): If you want to make sure that you master recursion, terminating conditions in particular, try this little exercise: Make a console program with recursive function that for each call writes an output line on the console of RecursionDepth number of spaces, followed by an asterisk (and a newline). If the main program calls this function with arguments NumberOfTeeth, BladeWidth, ToothLength, the output should look like a sawblade; the recursion goes to the maximum recursion depth, ToothLength. Then it returns to BladeWidth recursion depth, before it again recurses to ToothLength depth a second time, and repeats this for at total of NumberOfTeeth dives into the maximum depth, before finally returning to the main program. If you are a seasoned recursioner, maybe you will find this problem trivial (in that case, forward it to your students or junior programmers!) I have never ever seen anyone getting this perfectly right on the first try, though! Most programmers give it a first try, then they curse before making the first correction, then they re-curse before making a second correction, ... The cursing often goes to the maximum depth of re-cursing before they get it right modified 2-Mar-21 15:00pm.
 Application crashes suddenly without any message [Solved] Alex Dunlop26-Feb-21 22:05 Alex Dunlop 26-Feb-21 22:05
 Re: Application crashes suddenly without any message BillWoodruff26-Feb-21 22:23 BillWoodruff 26-Feb-21 22:23
 Re: Application crashes suddenly without any message Alex Dunlop26-Feb-21 22:29 Alex Dunlop 26-Feb-21 22:29
 Re: Application crashes suddenly without any message OriginalGriff26-Feb-21 22:35 OriginalGriff 26-Feb-21 22:35
 Re: Application crashes suddenly without any message OriginalGriff26-Feb-21 22:32 OriginalGriff 26-Feb-21 22:32
 Re: Application crashes suddenly without any message Alex Dunlop26-Feb-21 23:01 Alex Dunlop 26-Feb-21 23:01
 How to reset TextBoxes at once? [Solved] Alex Dunlop25-Feb-21 7:06 Alex Dunlop 25-Feb-21 7:06
 Re: How to reset TextBoxes at once? Gerry Schmitz25-Feb-21 8:42 Gerry Schmitz 25-Feb-21 8:42
 Re: How to reset TextBoxes at once? OriginalGriff25-Feb-21 8:51 OriginalGriff 25-Feb-21 8:51
 Re: How to reset TextBoxes at once? Gerry Schmitz25-Feb-21 9:17 Gerry Schmitz 25-Feb-21 9:17
 Re: How to reset TextBoxes at once? OriginalGriff25-Feb-21 8:50 OriginalGriff 25-Feb-21 8:50
 Re: How to reset TextBoxes at once? Alex Dunlop25-Feb-21 19:10 Alex Dunlop 25-Feb-21 19:10
 Re: How to reset TextBoxes at once? Dave Kreskowiak25-Feb-21 19:44 Dave Kreskowiak 25-Feb-21 19:44
 Re: How to reset TextBoxes at once? OriginalGriff25-Feb-21 19:59 OriginalGriff 25-Feb-21 19:59
 Re: How to reset TextBoxes at once? Eddy Vluggen26-Feb-21 6:39 Eddy Vluggen 26-Feb-21 6:39
 Re: How to reset TextBoxes at once? BillWoodruff25-Feb-21 21:43 BillWoodruff 25-Feb-21 21:43
 Re: How to reset TextBoxes at once? Ralf Meier26-Feb-21 3:05 Ralf Meier 26-Feb-21 3:05
 Last Visit: 31-Dec-99 18:00     Last Update: 7-May-21 19:15 Refresh ᐊ Prev1...11121314151617181920 Next ᐅ