Moderators: phlip, Prelates, Moderators General
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.
int input[length]; // Gets filled with the input
int ratio = input[1]/input[0];
for (int i = 1; i < length; ++i) {
if (input[i] != input[i-1]*ratio)
return false;
}
return true;
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.
WarDaft wrote: I do feel better having had someone immediately post an even worse solution here though. (Sorry letterX! I mean that in the nicest possible way.)
From the course description, general content so far, and the fact that there are many other courses explicitly referred to as software engineering, I was sure it was the former. There was another gotcha in class today, a trend I'm not liking, but an easy 98 is almost as good as an easy 100 and it's way better than coding in say, Java. I will just pay more attention I guess.letterX wrote:I don't at all know the specifics of the course, but sometimes paying attention to small details like that are pointless (for instance, in a theoretical "algorithms" course, where you care more about the high-level design of the algorithm) but sometimes, they are absolutely essential (In a software-engineering type course or anything that aims at giving a feel for what production-level code is like).
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.
No, it's not. A sequence starting from an arbitrary number followed by all zeros is a bit closer though, it almost sounds like you forgot about it too. I actually checked for all zeros, just not some number X followed by all zeros. I'm also not saying it's unfair, as I do not believe there's such thing as fairness or lack thereof. My exact words were that it was frustrating.Second, a sequence of all zeros is hardly a gotcha.
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.
Proginoskes wrote:There's another nuance to this problem ... Since computers can't express 1/3 exactly (with floating point), [3, 1, 1/3] wouldn't turn out to be a geometric series, since 3 * (1/3) is highly unlikely to equal 1 exactly.
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.
(defun arithmetic-sequence (seq)
(cond ((zerop (second seq)) (when (every 'zerop (rest seq)) 0))
((some 'zerop seq) nil)
(t
(when (apply '= (mapcar '/ seq (rest seq)))
(/ (second seq) (first seq))))))
Yes, but all of the solutions or suggestions posted, at the time, all missed something somewhere in recognizing geometric sequences. Knowing that I missed this case, I can actually fix my solution trivially. (Actually, given the particular way the problem was presented, I can fix it by deleting a single character.)What? No, several solutions are around. People are just looking for one without a special case for 0, which doesn't exist. Here, have a solution in Lisp:
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.
WarDaft wrote:Yes, but all of the solutions or suggestions posted, at the time, all missed something somewhere in recognizing geometric sequences. Knowing that I missed this case, I can actually fix my solution trivially. (Actually, given the particular way the problem was presented, I can fix it by deleting a single character.)What? No, several solutions are around. People are just looking for one without a special case for 0, which doesn't exist. Here, have a solution in Lisp:
Oh, and, keeping with the trend of things, that really doesn't look like a function that will detect arithmetic sequences very well.
Like I said, let us never speak of this again.
jareds wrote:Of course, many people define geometric sequences not to have a common ratio of 0, and this seems like a point in favor of that.
WarDaft wrote:Oh, and, keeping with the trend of things, that really doesn't look like a function that will detect arithmetic sequences very well.
Xanthir, a second ago wrote:
- Code: Select all
(defun arithmetic-sequence (seq)
(cond ((zerop (second seq)) (when (every 'zerop (rest seq)) 0))
((some 'zerop seq) nil)
(t
(when (apply '= (mapcar '/ seq (rest seq)))
(/ (second seq) (first seq))))))
- Code: Select all
(defun arithmetic-sequence (seq)
- Code: Select all
arithmetic-sequence
Like I said, let us never speak of this again.
WarDaft wrote:Let us all never speak of this again.
jareds wrote:As originally posed, the problem is in Scheme, which has exact rationals.
Proginoskes wrote:jareds wrote:As originally posed, the problem is in Scheme, which has exact rationals.
Oh. Well, I was confused by the C code.
douglasm wrote:I'd say this sort of missed detail is exactly the sort of thing that really good programmers need to be good at spotting. Missing things like this - not this kind of math thing specifically, but weird special cases in general - is how a lot of bugs get made. Take it as a lesson that you need to think more about the ways your code could conceivably break, not a pointless "gotcha".
http://en.wikipedia.org/wiki/DSV_Alvin#Sinking wrote:Researchers found a cheese sandwich which exhibited no visible signs of decomposition, and was in fact eaten.
Users browsing this forum: No registered users and 4 guests