Learning to code. Page 3

  • Page

    of 7 First / Last

  • monkehhh 17 Mar 2012 15:39:39 3,298 posts
    Seen 9 hours ago
    Registered 6 years ago
    Post deleted
  • monkehhh 17 Mar 2012 15:40:08 3,298 posts
    Seen 9 hours ago
    Registered 6 years ago
    Forum's eating mah posts!
  • Mr-Brett 17 Mar 2012 15:45:22 12,777 posts
    Seen 9 hours ago
    Registered 8 years ago
    That one is a bitch, I was struggling with it yesterday :)
    The point of the for loop is to keep iterating until the condition is met, remember: initialization; condition; increment.

    Portable view - Never forget.

  • RedSparrows 17 Mar 2012 16:07:08 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    I
    Phattso wrote:
    @RedSparrows

    Step 1: remind yourself what raising a number to a power does. Think through how you would write it mathematically rather than code. Given the inputs (2,2) do it by hand to work out what you expect the result to be. This will help you understand what this code is trying to achieve.

    Step 2: remind yourself that the 'for' loop executes the code between the braces {} according to its limits (in this case, from 0 to exponent-1).

    Step 3: write out the value of 'results' for each step in the loop. i.e. what is the value of 'result' after the first pass through the loop, then what is it after the second? Hopefully this will look a little like what you learned in Step 1.

    Important concepts these - important that you grasp them rather than get given the answer in an explanation*. Good luck!

    * no doubt someone will take pity if you continue to have trouble. ;)
    Thanks man. You are quite right. Need to understand. My brain is attuned to rhetoric and discourse, not maths! Time to dig in. Having a lot of fun :D

    Edit: I can kind of see what it is doing. If we wanted 3topowerof5, it has to 'add' a three to multiply until it reaches 5, I.e = to exponent. But still confused! More work.

    Edited by RedSparrows at 16:32:09 17-03-2012
  • RedSparrows 17 Mar 2012 17:00:57 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    Right.
    Let's use 3to5.

    If first result is 1, as defined, then 1 x 3 = 3.

    3 is new result. 3x3 = 9.

    And so on, until we have the FIFTH result, I.e the same number as the exponent.

    Correct? So the loop adds another sum until has done a number of sums = to the exponent. Correct?
  • [maven] 17 Mar 2012 17:04:46 5,152 posts
    Seen 17 hours ago
    Registered 10 years ago
    There are no sums (other than the loop-counter).
  • monkehhh 17 Mar 2012 17:06:59 3,298 posts
    Seen 9 hours ago
    Registered 6 years ago
    Yep, when 'i' isn't less than the exponent anymore it stops looping and returns the result.

    Another way to do this would be to initially set result to the base and loop one less time - if that makes sense :)
  • RedSparrows 17 Mar 2012 17:08:49 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    Yeah I see. Maven I was describing it how I saw it in my head. Not up on the lingo ;) it's doing it all at once I know.
  • RedSparrows 17 Mar 2012 17:55:58 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    Recursion makes me gooey in head.
  • mal 18 Mar 2012 02:41:44 22,473 posts
    Seen 4 hours ago
    Registered 13 years ago
    Edit: This is not the forum to post code on.

    Edited by mal at 02:43:09 18-03-2012

    Cubby didn't know how to turn off sigs!

  • Phattso Moderator 18 Mar 2012 15:30:56 13,304 posts
    Seen 15 minutes ago
    Registered 10 years ago
    RedSparrows wrote:
    Recursion makes me gooey in head.
    Be careful - in programming recursion has a very different meaning (methods that call themselves in-line). What you have here is simply a function that returns a result, and the function happens to contain a loop.

    Unless I've read the code snippet wrongly.
  • mal 18 Mar 2012 15:50:50 22,473 posts
    Seen 4 hours ago
    Registered 13 years ago
    Yeah, I reimplemented that power code using recursion, but unfortunately the forum ate my code.

    Hmm, wonder if I can do it in pseudocode?

    Edit: Nope, forum eats that too.

    Edited by mal at 15:51:51 18-03-2012

    Cubby didn't know how to turn off sigs!

  • Phattso Moderator 18 Mar 2012 16:00:04 13,304 posts
    Seen 15 minutes ago
    Registered 10 years ago
    It's interesting watching you guys get to grips with this stuff. I had to delve deeeeep into the past to remember a time when I didn't implicitly understanding all this. I think I can trace my "Eureka!" moment with this back to 1992 or so. I'd been doing assembler for a few years, but getting to grips with a higher level language was a real effort.

    It's very rewarding when it all clicks into place in your brain - I'm slightly envious that you're all getting that. Been a while for me now. :)
  • RedSparrows 18 Mar 2012 17:54:29 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    I'm on some recursion now, is why I said it.

    Finally clicked that the computer wad viewing what I was in a totally different way. It's cooked my noggin', but I really enjoy it!
  • RedSparrows 20 Mar 2012 15:55:43 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    Omnonomnom ternary operators omnomnom I like you best omnomnom

    In other news, I have been watching some MIT CS lectures - REALLY useful for getting into the right way of thinking.
  • monkehhh 20 Mar 2012 19:56:45 3,298 posts
    Seen 9 hours ago
    Registered 6 years ago
    It is fun learning new stuff - I'm currently delving in to the deep, dark corners of our GIS systems at work in preparation for starting my masters.

    For a game that gives that similar feeling of "what is this?!" / "fuck me, I'm clever" - play SpaceChem :)
  • Mr-Brett 20 Mar 2012 20:33:20 12,777 posts
    Seen 9 hours ago
    Registered 8 years ago
    @Red, got a link for those lectures?

    Portable view - Never forget.

  • mal 21 Mar 2012 00:34:12 22,473 posts
    Seen 4 hours ago
    Registered 13 years ago
    RedSparrows wrote:
    Omnonomnom ternary operators omnomnom I like you best omnomnom
    What a strange strange man. Go learn some Forth if you like those.

    Cubby didn't know how to turn off sigs!

  • RedSparrows 21 Mar 2012 17:13:02 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    Mr-Brett wrote:
    @Red, got a link for those lectures?
    Is the one I am using!

    @mal - I like them as they make my brain happier than lots of if/else stuff! Not sure why.

    Edited by RedSparrows at 17:13:33 21-03-2012
  • Mr-Brett 21 Mar 2012 17:36:47 12,777 posts
    Seen 9 hours ago
    Registered 8 years ago
    Cheers Red. I've not got to ternary operators yet, hopefully they don't hurt my brain as much as loops do.

    Portable view - Never forget.

  • RedSparrows 21 Mar 2012 18:59:51 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    I like them because they simplify, at least visually, conditional statements.

    Loops are the biggy for me too.

    The MIT lectures are great simply at explaining how to think - that's the whole point of them. They're taught by and too people with far more technical ability than me, but I still understand them.

    Lecture 1 is largely admin for the course, as you'd expect, but it gets going.
  • Mr-Brett 22 Mar 2012 20:37:23 12,777 posts
    Seen 9 hours ago
    Registered 8 years ago
    Done the first ternary operators section, I have to agree, much nicer than 'if else'.

    Just starting the second lecture video :)

    Portable view - Never forget.

  • BravoGolf Moderator 22 Mar 2012 21:34:11 12,740 posts
    Seen 12 hours ago
    Registered 11 years ago
    Hello World!

    ....

    /leaves
  • mal 22 Mar 2012 23:51:50 22,473 posts
    Seen 4 hours ago
    Registered 13 years ago
    God, I hate ternary operators. Too terse, too hard to remember unless you use them a lot (I should probably learn a mnemonic for condition?if_true:if_false). But on the other hand I love list comprehension and lambda functions, so maybe I've no leg to stand on.

    Cubby didn't know how to turn off sigs!

  • Mr-Brett 23 Mar 2012 12:59:48 12,777 posts
    Seen 9 hours ago
    Registered 8 years ago
    Oh god I hate the FizzBuzz++ project, it's like it was written by a robot.

    Portable view - Never forget.

  • RedSparrows 23 Mar 2012 17:28:30 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    Yeah the fizzbuz++ one is not written that well.

    It's kind of annoying the whole thing isn't by one person. I feel like I have covered the same thing twice at times, but written in different ways.

    Still, good practise.
  • Mr-Brett 23 Mar 2012 17:49:14 12,777 posts
    Seen 9 hours ago
    Registered 8 years ago
    Yeah I'm happy for the practice, so I don't mind much about that kinda thing and sometimes they aren't brilliantly written but you get the jist. With FizzBuzz++ though you're working with some concepts which can be pretty hard to get your head around so it'd be nice if a bit more care was taken with writing it. Oh well, onwards and upwards!

    Portable view - Never forget.

  • RedSparrows 23 Mar 2012 18:19:43 22,332 posts
    Seen 10 hours ago
    Registered 7 years ago
    Yeah, that one just decides to introduce Objects and another key word, not to mention a really odd set of values.
  • Mr-Brett 27 Mar 2012 11:51:59 12,777 posts
    Seen 9 hours ago
    Registered 8 years ago
    I wonder if someone here might be able to help me with one of the codecademy exercises, it's Primitives in JavaScript Section 4 Boolean in the wild #2.
    I can't figure out why my code doesn't work, I've put it here.

    Portable view - Never forget.

  • Phattso Moderator 27 Mar 2012 11:54:12 13,304 posts
    Seen 15 minutes ago
    Registered 10 years ago
    i & 3 <
    Do you not mean i % 3?
  • Page

    of 7 First / Last

Log in or register to reply