no iterations
-
public static string[] RubeGoldberg(int n)
{
...
}Named after, ofcourse, Rube Goldberg[^].
hmm. Not quite, Binet's formula would give better performance than any loop or recursion once n goes up. And please don't think of doing these things recursively (unless you cache intermediate results), it would take very long as it has exponential behavior. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
well, a recursion is also a loop, as it executes the same code over and over again; luckily all he really asked to get rid of was a for loop, so a simple while could have sufficed. PS: yeah, I don't mind freaking out a teacher once in a while. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
To me, it just sounded like there was a bit of confusion on his part as to what he was really aiming for. Hence, my observation.
-
hmm. Not quite, Binet's formula would give better performance than any loop or recursion once n goes up. And please don't think of doing these things recursively (unless you cache intermediate results), it would take very long as it has exponential behavior. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
NetQuestions wrote:
I want to initialize a string array with "*".
That part and the subsequent responses regarding that from you and Ennis just confused me over what he actually wants. </spam>
-
Can you come up with an appropriate name for this method:
public static string[] xyz(int n) {
if (n<1) throw new ArgumentException("n must be greater than zero");
return new string('*', (int)Math.Round((Math.Pow(0.5+Math.Sqrt(1.25), n)-Math.Pow(0.5-Math.Sqrt(1.25), n))/Math.Sqrt(5))).Replace("*", ".*").Substring(1).Split('.');
}PS: triggered by an actual programming question (which looked like homework). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
MyGodItsFullOfStars
-
MyGodItsFullOfStars
BestSoFar :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
Sorry, rejected by at least a dozen FxCop rules. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
MyGodItsFullOfStars
:laugh: Got my vote.
-
Can you come up with an appropriate name for this method:
public static string[] xyz(int n) {
if (n<1) throw new ArgumentException("n must be greater than zero");
return new string('*', (int)Math.Round((Math.Pow(0.5+Math.Sqrt(1.25), n)-Math.Pow(0.5-Math.Sqrt(1.25), n))/Math.Sqrt(5))).Replace("*", ".*").Substring(1).Split('.');
}PS: triggered by an actual programming question (which looked like homework). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
Can you come up with an appropriate name for this method:
public static string[] xyz(int n) {
if (n<1) throw new ArgumentException("n must be greater than zero");
return new string('*', (int)Math.Round((Math.Pow(0.5+Math.Sqrt(1.25), n)-Math.Pow(0.5-Math.Sqrt(1.25), n))/Math.Sqrt(5))).Replace("*", ".*").Substring(1).Split('.');
}PS: triggered by an actual programming question (which looked like homework). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
HereBeDragons(n)
;P Or even better:uβerπ(n)
:laugh: EDIT: If you can't read that, it says uBer(pi) -
Can you come up with an appropriate name for this method:
public static string[] xyz(int n) {
if (n<1) throw new ArgumentException("n must be greater than zero");
return new string('*', (int)Math.Round((Math.Pow(0.5+Math.Sqrt(1.25), n)-Math.Pow(0.5-Math.Sqrt(1.25), n))/Math.Sqrt(5))).Replace("*", ".*").Substring(1).Split('.');
}PS: triggered by an actual programming question (which looked like homework). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
How about:
private static readonly double WhatDoesThisMean = 0.5 + Math.Sqrt(5); private static readonly double WhatDoesThisMean2 = 0.5 - Math.Sqrt(1.25); public static string\[\] **DesparatelyNeedsRefactoring**(int n) { if (n < 1) throw new ArgumentException("n must be greater than zero"); double d = Math.Pow(WhatDoesThisMean, n) - Math.Pow(WhatDoesThisMean2, n); var stringLength = (int) Math.Round(d / WhatDoesThisMean); return new string('\*', stringLength).Replace("\*", ".\*").Substring(1).Split('.'); }
Note that I would refactor the variable 'stringLength' out as well - I put that in there to try and figure out what was going on, before I gave up and Googled.
Before .NET 4.0, object Universe = NULL;
-
How about:
private static readonly double WhatDoesThisMean = 0.5 + Math.Sqrt(5); private static readonly double WhatDoesThisMean2 = 0.5 - Math.Sqrt(1.25); public static string\[\] **DesparatelyNeedsRefactoring**(int n) { if (n < 1) throw new ArgumentException("n must be greater than zero"); double d = Math.Pow(WhatDoesThisMean, n) - Math.Pow(WhatDoesThisMean2, n); var stringLength = (int) Math.Round(d / WhatDoesThisMean); return new string('\*', stringLength).Replace("\*", ".\*").Substring(1).Split('.'); }
Note that I would refactor the variable 'stringLength' out as well - I put that in there to try and figure out what was going on, before I gave up and Googled.
Before .NET 4.0, object Universe = NULL;
Hired Mind wrote:
I gave up and Googled
and? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hired Mind wrote:
I gave up and Googled
and? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Got distracted by productive work, and then you gave a the answer in another post. Fibonacci sequence right?
Before .NET 4.0, object Universe = NULL;
-
Got distracted by productive work, and then you gave a the answer in another post. Fibonacci sequence right?
Before .NET 4.0, object Universe = NULL;
I must say I was rather pleased with myself at having worked out the correct answer before reading this post (and another) with the correct answer in. Of course if anybody actually implemented this in production code they would be told off. Reminds me of the pointer trickery fun we used to do in C "for performance reasons" :)