magic_lobster_party

  • 0 Posts
  • 136 Comments
Joined 4 months ago
cake
Cake day: March 4th, 2024

help-circle












  • So in your code you do the following for each permutation:

    for (int i = 0; i<n;i++) {

    You’re iterating through the entire list for each permutation, which yields an O(n x n!) time complexity. My idea was an attempt to avoid that extra factor n.

    I’m not sure how std implements permutations, but the way I want them is:

    1 2 3 4 5

    1 2 3 5 4

    1 2 4 3 5

    1 2 4 5 3

    1 2 5 3 4

    1 2 5 4 3

    1 3 2 4 5

    etc.

    Note that the last 2 numbers change every iteration, third last number change every 2 iterations, fourth last iteration change every 2 x 3 iterations. The first number in this example change every 2 x 3 x 4 iterations.

    This gives us an idea how often we need to calculate how often each hash need to be updated. We don’t need to calculate the hash for 1 2 3 between the first and second iteration for example.

    The first hash will be updated 5 times. Second hash 5 x 4 times. Third 5 x 4 x 3 times. Fourth 5 x 4 x 3 x 2 times. Fifth 5 x 4 x 3 x 2 x 1 times.

    So the time complexity should be the number of times we need to calculate the hash function, which is O(n + n (n - 1) + n (n - 1) (n - 2) + … + n!) = O(n!) times.

    EDIT: on a second afterthought, I’m not sure this is a legal simplification. It might be the case that it’s actually O(n x n!), as there are n growing number of terms. But in that case shouldn’t all permutation algorithms be O(n x n!)?

    EDIT 2: found this link https://stackoverflow.com/a/39126141

    The time complexity can be simplified as O(2.71828 x n!), which makes it O(n!), so it’s a legal simplification! (Although I thought wrong, but I arrived to the correct conclusion)

    END EDIT.

    We do the same for the second list (for each permission), which makes it O(n!^2).

    Finally we do the hamming distance, but this is done between constant length hashes, so it’s going to be constant time O(1) in this context.

    Maybe I can try my own implementation once I have access to a proper computer.


  • Time complexity is mostly useful in theoretical computer science. In practice it’s rare you need to accurately estimate time complexity. If it’s fast, then it’s fast. If it’s slow, then you should try to make it faster. Often it’s not about optimizing the time complexity to make the code faster.

    All you really need to know is:

    • Array lookup: O(1)
    • Single for loop: O(n)
    • Double nested for loop: O(n^2)
    • Triple nested for loop: O(n^3)
    • Sorting: O(n log n)

    There are exceptions, so don’t always follow these rules blindly.

    It’s hard to just “accidentally” write code that’s O(n!), so don’t worry about it too much.



  • By “certain distance function”, I mean a specific function that forces the problem to be O(n!^2).

    But fear not! I have an idea of such function.

    So the idea of such function is the hamming distance of a hash (like sha256). The hash is computed iterably by h[n] = hash(concat(h[n - 1], l[n])).

    This ensures:

    • We can save partial results of the hashing, so we don’t need to iterate through the entire lists for each permutation. Otherwise we would get another factor n in time complexity.
    • The cost of computing the hamming distance is O(1).
    • Order matters. We can’t cheat and come up with a way to exclude some permutations.

    No idea of the practical use of such algorithm. Probably completely useless.


  • I don’t understand why a company like Sony wouldn’t provide you a way to play ps1-3 games on your ps5. I would even be ready to pay for it.

    They want you to buy new games. Not to play your old games.

    PS5 doesn’t support CD, so popping in PS1 games (and a few early PS2 games) won’t work even if PS5 had a proper PS1 emulator. It’s only a matter of time until DVD support will be dropped for future consoles as well.

    Re-releasing old games digitally is also difficult. More from a legal aspect. They need the permission of the holder of the IP. If they want to release Crash Bandicoot again, they need permission from Microsoft, who’s the current IP holder.

    It’s also extra problematic if the game uses licensed music, which became common in the PS1 era. Then they need permission from all the involved artists. The Tony Hawk games are problematic in this regard for example.

    New releases of Sonic 3 doesn’t include some of the original tracks. Possibly due to the potential involvement of Michael Jackson.




  • Moore’s law is not a given. It has been slowing down recently.

    Current games are made for current day’s design of graphics cards. They are very dependent on pixel shaders for example.

    Let’s be hypothetical. Imagine that future graphics cards go all in on ray tracing. Pixel shaders have become a thing of the past and no new hardware support it natively anymore.

    Preservers have two options: either try their best to simulate pixel shaders effects through ray tracing, or emulate it through software.

    Simulating through ray tracing won’t be accurate. Many pixel shader effects can’t be properly translated to ray tracing. Emulating through software can be hard. I don’t think many games even from 20 years ago can be fully run on modern CPUs.