no iterations
-
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.
I'd call it
public static string[] TheGreatBigMathPowSqrtFunctionThatNobodyKnowsWhatItDoes(int n);
Is there not a name for the algorithm that is being implemented? :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
-
I'd call it
public static string[] TheGreatBigMathPowSqrtFunctionThatNobodyKnowsWhatItDoes(int n);
Is there not a name for the algorithm that is being implemented? :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
Sampling the function for a couple of small values should tell you exactly what it does. If you want to apply Google Fu, there is a formula by Binet, which I gave a little twist... :)
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.
-
Luc Pattyn wrote:
Can you come up with an appropriate name for this method:
supercalifragilisticexpialidocious? :)
Quidquid latine dictum sit, altum videtur.
Whatever is said in Latin sounds profound.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.
-
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.
public static string[] RubeGoldberg(int n)
{
...
}Named after, ofcourse, Rube Goldberg[^].
-
public static string[] RubeGoldberg(int n)
{
...
}Named after, ofcourse, Rube Goldberg[^].
Btw, I hope the OP does realize that you haven't infact removed the loop, but just hidden it inside a method call. I can just see the teacher looking at this and going...you know...I really just wanted a recursive method.
-
Btw, I hope the OP does realize that you haven't infact removed the loop, but just hidden it inside a method call. I can just see the teacher looking at this and going...you know...I really just wanted a recursive method.
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.
-
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.