Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)M
Posts
9
Comments
37
Joined
2 yr. ago

  • Thank you. Not sure why in the link the arithmetic in green results in 7.

  • Thank you for breaking it down.

    I'm just now sure when it is appropriate to use '|'. If bitwise operators can only be used with integers (and not floats), what's an example where I can use it.

  • Yes I did eventually think of that as well but just wanted to understand why '|' wasn't producing the results I expected.

  • I did come across that link but didn't quite understand it. If looking only at 25 | 10, does the code not run as expected because 25 is 5 digits long and 10 is 4 digits long? Is that what's meant by "two equivalent length bit designs"?

    Also, I can't tell if 10 | 4 = 7 or 10 | 4 = 14.

  • Yes, that helps. Thanks. I see now how n goes from 1 to 2 to 3...etc. Now not so sure how i = 1 when the for loop starts.

  • Yes - I finally caught that part about n as it's just moving in reverse so it gets decremented. Now I'm not sure about i. In the debugger when the program gets to the for loop both n and i are equal to 1. The n I understand but i?

  • Gotcha. Thanks for the explanation.

  • I see. I guess my understanding was that the recursion was over after the recursive call, but it's actually for all the code in draw().

  • Thanks. I did see that. I have a general understanding of how recursion works I think where the function calls itself again and again but I don't get why the code (for loop) below the draw(n - 1) is recursive.

  • Right. I was aware it was recursion as stated in the title of my post. I had two questions specific to where the for loop returns after printing #.

  • Why does the for loop return when it hits the end of the function? Isn't the recursive portion already completed in draw(n - 1)? The rest of it is just normal non-recursive code if I understand it correctly.

  • Yep

  • It's supposed to be a pyramid but not my code. It's an example of a recursive function from a CS50 lecture and I'm just trying to understand how the code works line by line.

  • Good point!

  • Ah ha! Yes, I did check the docs but I think I just glanced over that portion. Be more careful next time. The < is a less than sign but it seems it doesn't render correctly on Lemmy.

  • Sorry. It's in C. Updated post. Yes those are titles. I just included the relevant portions rather than the entire code.

  • Ah I see. I had a bad habit of using else if statements instead of else statements because I thought else if could be better in seeing the condition it's testing for so it was clearer. I get the logic is actually different now.