How would you optimize this code without using recursion?

How would you optimize this code without using recursion?

Schizophrenic Conspiracy Theorist Shirt $21.68

Homeless People Are Sexy Shirt $21.68

Schizophrenic Conspiracy Theorist Shirt $21.68

  1. 3 weeks ago
    Anonymous

    delete it all and just use /dev/urandom

  2. 3 weeks ago
    Anonymous

    I'm not gonna help you with your dumbass coding homework.

  3. 3 weeks ago
    Anonymous

    If this is homework, drop the fricking class. Nobody writes code in the real world like this. It’s mental masturbation. Fricking academics…

    • 3 weeks ago
      Anonymous

      You fool. Try reading an Indian’s code before speaking such falsehood.

    • 3 weeks ago
      Anonymous

      Literally Indian code, they find the perfect blend of ugly, unreadable and slow.

      I couldn't do worse even if I tried and I'm an idiot.

      • 3 weeks ago
        Anonymous

        >I couldn't do worse even if I tried and I'm an idiot.
        It takes a moron to do moronic things, but it takes a genius to make things even more moronic.

    • 3 weeks ago
      Anonymous

      I've seen it. I had to unfrick it.

    • 3 weeks ago
      Anonymous

      Yes anon that's what studying is

  4. 3 weeks ago
    Anonymous

    I would use an RNG algorithm that didn't suck that hard.

  5. 3 weeks ago
    Anonymous

    stole it from where?

    • 3 weeks ago
      Anonymous

      > stole from
      from who?

      From whom, you troglodyte. Think about what the answer looks like:
      >I stole from ____
      The answer is in the objective case, which means the question uses 'whom'. And I can't even accuse you of being ESL, because an ESL would fricking know that. It's the native speakers who don't give a frick. I dislike you, anon.

      >r/ProgrammerHumor/comments/1ahbkb3/recursionisoverrated/
      Found it, OP stole this from the orange alien website. It's supposedly a seed generator, not an rng generator.

      • 3 weeks ago
        Anonymous

        >random number generator generator

        • 3 weeks ago
          Anonymous

          >generator generator
          It does sound a bit Javaish doesn't it? Like making a random number factory factory.

  6. 3 weeks ago
    Anonymous

    For frick sake combine all of the conditions into one big statement. That'll unfrick this nested bullshit.

    Also use a better RNG.

  7. 3 weeks ago
    Anonymous

    Start by combining all of the ifs for the success case into one in the simplest possible form.
    Then on unsuccessful cases, start looking for opportunities to skip iterations that will fail by manually manipulating the loop variables.

  8. 3 weeks ago
    Anonymous

    > stole from
    from who?

    • 3 weeks ago
      Anonymous

      From whom, you troglodyte. Think about what the answer looks like:
      >I stole from ____
      The answer is in the objective case, which means the question uses 'whom'. And I can't even accuse you of being ESL, because an ESL would fricking know that. It's the native speakers who don't give a frick. I dislike you, anon.

      • 3 weeks ago
        Anonymous

        > be esl
        > *critics*
        > be native
        > *critics*
        why the hell should anyone give a frick if it's 100% correct or not?
        > sorry sir for my broken english
        > i hope you can one day forgive me for my bad english
        the lazy (superior) english (aka USA one) won because of its simplicity and because you can be right even if wrong
        > I dislike you anon
        here have a pepe so we can be frens despite our differences

        • 3 weeks ago
          Anonymous
  9. 3 weeks ago
    Anonymous

    Semantically, you only need 2 loops (or 1 and projection): iterate the 16C8 value choices for a..h, and then iterate the 8! permutations of a..h.
    You can look up the algorithms from some combinatorics 101 book, though they'll usually be in recursive form.

  10. 3 weeks ago
    Anonymous

    I'd let the compiler (LLVM) optimize it for me

  11. 3 weeks ago
    Anonymous

    https://en.wikipedia.org/wiki/Heap%27s_algorithm

  12. 3 weeks ago
    Anonymous

    Wait a second.
    Is this a Random Number Generator
    or a RNG Generator as specified in pic title?

  13. 3 weeks ago
    Anonymous

    so from what I understand all of these numbers need to be different to anything else for the if statement in the center to work?
    anyway here's what I came up with in python(FOR JUST THE IF STATEMENT)
    a = 5
    b = 10
    c = 15
    d = 20
    e = 25
    f = 30
    g = 35
    h = 40

    variables = [a, b, c, d, e, f, g, h]
    no_duplicates = True

    for i in range(len(variables)):
    for j in range(i + 1, len(variables)):
    if variables[i] == variables[j]:
    no_duplicates = False
    break

    if no_duplicates:
    print("None of the variables are equal to each other.")
    else:
    print("At least two variables are equal.")

  14. 3 weeks ago
    Anonymous

    create an array of chars or bytes or whatever.
    Whenever you increment a variable, check the value at that array index and if it is 0 it is free and you can use it, so store the character value, or some other value to identify the variable in that array position. Before incrementing the variable again, set the value at the array index back to 0 if you were using it.

    Or just get a better RNG algorithm.

  15. 3 weeks ago
    Anonymous

    If this is supposed to be a pseudorandom number generator, it's a really bad one. It won't succeed the most basic statistical tests, and has an extremely short period. It doesn't even hit every 32 bit value, and the generated bits are 1 significantly more often than 0.

  16. 3 weeks ago
    Anonymous

    I would pick something else because that's just weirdly horrible.

  17. 3 weeks ago
    Anonymous

    just be sensible and realize that the code is doing:

    combinations 15 8 . map (map ((+) 1)) . filter(first . mod 2 . ((==) 1)) . map innerLoop

    I swear loop constructs are just made to fool juniors that programming is writing code instead of recognizing patterns and laying them out in a readable way. Anyway, in k this is just

    16/'1+(2!*:')_+:cmb[8;15]

  18. 3 weeks ago
    Anonymous

    like we wouldn't find out

  19. 3 weeks ago
    Anonymous

    Transpose the uniqueness checks, then move each of them to the most outward scope that can resolve it.
    If you want it to actually be efficient, then look up a formula for generating permutations directly.

  20. 3 weeks ago
    Anonymous

    Yanderedev is at it again?

  21. 3 weeks ago
    Anonymous

    type -O3 in compilation options

    otherwise you could 'binary and' a b c d e f g and h toegether into a number
    and 'binary or' them all toegether into another.
    then compare the two results. if the two results are the same all your numbers are the same

    not only instead of !n you resolve in 2n
    but also binary ops can be pipelined. compile with optimizations on or you might have to set the order of operations by hand, using parentheses

    • 3 weeks ago
      Anonymous

      (cont.)
      if you can change the algorythmics of it and focus on the result
      just go with one for loop
      and forgo all checks.

      just work with the same number everywhere so you know a == b == c == d etc
      but that would be an utterly pointless assignment

    • 3 weeks ago
      Anonymous

      https://i.imgur.com/9oYU8iE.png

      How would you optimize this code without using recursion?

      (cont.)
      you can also type #pragma unroll before each for loop so that your for loops are unrolled
      https://stackoverflow.com/questions/22278631/what-does-pragma-unroll-do-exactly-does-it-affect-the-number-of-threads
      this also hints to the cpu to pipeline your iterations if it can

Your email address will not be published. Required fields are marked *