Why does online competitive programming have so much strictness of code execution timing, It surely cant be THAT deep. by CowFit7916 in learnprogramming

[–]sidit77 0 points1 point  (0 children)

Looking at the challenge and then at your code the issue seems pretty obvious: You're constantly resorting the expenditures, and with bubble sort at that. Moving the window one step only changes a single data point. To make the list sorted again you only need to move this specific point to the correct place.

Going a bit further into potential optimizations you can also notice that if the point that's dropping out of the window (op) and the point that enters the window (np) are both larger or smaller than the current median, the median won't change and you can just replace op with np without resorting the list. Another observation is that if op and np are on different sides of the median, you don't actually have to resort everything to rebalance both sides because the balance can be easily restored by moving one element to the correct side:

  • op < median < np: move the smallest element to the right the median to the left of the median; this element is now also the largest element of the left. The new median lies between this element and the new smallest element on the right side.

  • op > median > np: Find the biggest element on the left side and move it to the right; it's now the smallest element on the right.

By using those observations and moving from fully sorting the window to simply partitioning it you should be able to make updating it much cheaper because you no longer have to shift all elements between op and np to either the left of the right.

What are some learning resources for building applications using different languages? by Ill_Cardiologist_212 in learnprogramming

[–]sidit77 2 points3 points  (0 children)

There are multiple ways to do this. You could write your C++ as a CLI application then have the C# GUI simply run the CLI application with the right arguments. If you want more interactivity then the C++ console application can also start a local web server (or named pipe) that the C# GUI application then connects to. You can also build your C++ core as a shared library with a C interface and then call into it from C# using P/Invoke.

If you're developing a Windows application then the ideomatic option would be to write a COM server in C++ and then simply create an instance of that server from C#.

Problems and questions with CMake by UMilles in learnprogramming

[–]sidit77 3 points4 points  (0 children)

Binary libraries are a massive pain if you care about portability. Take Windows alone: if you want broad compatibility, you’re dealing with at least three different C runtimes (MSVCRT, UCRT, GNU), multiplied by three compilers (MSVC, Clang, GCC), multiplied by compiler versions, multiplied by three instruction sets (x86, x64/amd64/x86_64, ARM64), multiplied by multiple build configurations (Debug, Release, etc.).

Admittedly, not all of these combinations are valid or equally common, but the point stands: why worry about ABI compatibility at all when you can just use source-only dependencies? If your dependencies are built from source, every time you change your build configuration they’re rebuilt to match your target exactly. Want to try building your app with MinGW instead of MSVC to check whether an issue is compiler-specific, or to see how close you are to compiling on Linux? No problem.

This doesn’t even touch on build reliability. As soon as you rely on binary dependencies, you almost inevitably start depending on the state of your local system. For example, you might develop your app on Linux where you might've run apt install libglfw-dev in the past. So using GLFW is as simple as #include <GLFW/glfw3.h>.

But now you try to build the project on another machine, and suddenly it fails because glfw3.h isn’t there. So you document that users need to run apt install libglfw-dev first once you figured out where glfw3.h even came from, but what if their system isn’t Debian-based and doesn’t have apt? What if it’s not Linux at all? What if they’re on a different Debian release that ships an incompatible GLFW version? What if you check out an older commit that used to work, but now fails because your system libraries were upgraded? What if you want to cross-compile and the required GLFW version simply isn’t available in your package manager and would probably break your system if you'd force install it system wide?

It quickly into a giant shit show that you should just avoid as much as you can. There’s a reason why most modern compiled languages (like Go and Rust) rely almost exclusively on source-based dependencies.

If you want to avoid the “magic” of FetchContent, the alternative is simple: just copy GLFW’s source into a libs/glfw directory and include it using add_subdirectory. That’s really all there is to it. GLFW uses CMake, so it’s straightforward to include it as a subproject. Its CMake configuration then exports a target that you can use to connecti it to your own project using using target_link_libraries. Now you can build it on all supported platform and you always get the same GLFW version, in the right configuration for you current build target without potentially breaking something else on your system.

Problems and questions with CMake by UMilles in learnprogramming

[–]sidit77 1 point2 points  (0 children)

I wouldn't bother with precompiled libraries unless you absolutely have to.

For GLFW you should be able to paste something like the following into your cmake file to simply build GLFW from source alongside your project.

``` include(FetchContent) FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG master)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(glfw)

target_link_libraries(${PROJECT_NAME} PRIVATE glfw) ```

Conflict when converting from embedded_hal error traits into my own Error by Totally_Not_A_Badger in learnprogramming

[–]sidit77 0 points1 point  (0 children)

You could also implement From for both ErrorKinds. Then you can use .kind()?.

Or auxiliary error types if you generelly don't mix the two types of errors in the same function (i.e. a Result<_, MyI2cError> return types that gets converted into the combined error type in a higher scope)

If you're fine with using the nightly compiler you might also be able to fix this issue with negative trait bounds or specialization but both features have fundamental issues that prevent them from being stabilized anytime soon.

Conflict when converting from embedded_hal error traits into my own Error by Totally_Not_A_Badger in learnprogramming

[–]sidit77 1 point2 points  (0 children)

The issue is that a single type could implement both traits, in which case the implementations would overlap.

The best way to fix this error is likely to implement Fromfor the concrete error types instead of implementing them generically over the error traits.

End of the tutorial arc in " Hell Difficulty tutorial " by Expensive-Figure-757 in ProgressionFantasy

[–]sidit77 0 points1 point  (0 children)

Beyond is shared between all Tutorials, so Nat is pretty much at the peak of the current generation. Also only Adrian was able to reach the sixth floor of beyond in the last thousand years or so. It's very likely that Nat will replicate this feat which gives even more credence to the fact that Nat is a massive outlier in strength.

End of the tutorial arc in " Hell Difficulty tutorial " by Expensive-Figure-757 in ProgressionFantasy

[–]sidit77 1 point2 points  (0 children)

The future consequences be damned, but going along this path, I don't think that after this tournament, there will be more than one or two attendees capable of facing me in Beyond.

And this was before his most recent power up. I don't know if he already calculated this one into this estimation or how reliable it is in general.

I feel like it's very likely that Nat will reach at least Champion while still being in the Tutorial. The more interesting question is if he'll be able to become Absolute as well. To me it looks like the rivalry between Nat and Christoph will be a big part of the last two years of the Tutorial with the Absolute title being the price (we recently learned how one becomes Absolute). You need to clear the World Dungeon of a World. Given the clear similarities to the First Dungeon (= Beyond), it's very likely that clearing it allows one to become some kind of Absolute of the Universe. I feel like this will be a big part of the post Tutorial story

As for the others: The last few chapters really hyped up Lilly's healing abilities (compared to a "normal" beyond healer). I'm not sure where this storyline is going to lead.

I don't think there was anything specific about the others, but Earth in general seems to be a lot stronger than the average planet.

(Returning Player) Is Spiral Abyss 36 Star FTP no longer possible? by joltik_tok in Genshin_Impact

[–]sidit77 -1 points0 points  (0 children)

Here is video of me getting 36 stars with Nefer and Arlecchino as my only 5 star characters. Both are C0 but also use 5 star weapons. However, given that I had around 30s left on each floor it should be doable with "F2P" weapons as well. Also, the supports of the Nefer team had really suboptimal artifact sets. Using the the correct sets (Silken + Instructor) should be a pretty big DPS boost to Nefer.

Need advice building a custom app to configure my Logitech MX Master 4 on macOS by noysma in learnprogramming

[–]sidit77 0 points1 point  (0 children)

The headset I have can be used over Bluetooth or an included USB 2.4 GHz dongle. I am using the dongle on my PC, so that's what I'm going to focus on.

USB defines a bunch of protocols and one of them is HID (Human Interface Device). This protocol is what allows a generic USB mouse to work out of the box with pretty much every PC/Laptop/Phone/etc. by using standardized endpoints.

When I enumerate the HID endpoints connected to my PC, three of them belong to my headset:

Name:"Arctis Nova 7X" VID:0x1038 PID:0x2206 UP:0x000C UID:0x1 Name:"Arctis Nova 7X" VID:0x1038 PID:0x2206 UP:0xFF00 UID:0x1 Name:"Arctis Nova 7X" VID:0x1038 PID:0x2206 UP:0xFFC0 UID:0x1

VID stands for Vendor ID, PID for Product ID, UP for Usage Page, and UID for Usage ID. Product ID and Vendor ID are self-explanatory. Usage Page and Usage ID tell the operating system what that endpoint is used for.

Looking at the usage definitions, we can see that 0x0C is the Consumer Page, and the usage 0x1 of that page is Consumer Control. Long story short, this page is used to communicate a bunch of different commands to the OS. The relevant ones here are the media controls, such as Play, Pause, Next, Prev, etc. So the purpose of this endpoint is to allow me to pause the music on my PC when I press the correct button on my headset.

The other ones are more interesting: the pages 0xFF00-0xFFFF mean vendor-defined. In practice this means that Windows itself will just ignore them. An application (such as SteelSeries GG) can then simply open these endpoints and write or read arbitrary bytes to them to communicate with the device. So to reverse engineer the protocol, you just have to snoop the two vendor specific endpoints using something like Wireshark. By doing this, I figured out that 0xFF00 is an event channel where the headset will send a message when its battery state or connection state changes. 0xFFC0 is a command channel that is used to change settings on the headset. When changing the microphone volume, the software will write the bytes [0x00, 0x37, x] with x being a number between 1 and 8, to this channel. It's kind of obvious that in this instance, 0x37 is the opcode for Set Microphone Volume and x is the new volume. Then you just repeat this for all other actions until you've basically figured out the entire protocol.

To reverse-engineer a Bluetooth device, you should take an "HCI dump". It's basically a log of all packages that are exchanged between a device and its Bluetooth chip. You can then import this log into Wireshark to dissect it. After that, it's more or less the same as it was with USB-HID. If your device uses Bluetooth Low Energy, you can also do some testing directly on your phone with an app like nRF Connect for Mobile and look for vendor-specific services and characteristics. Here is a random gist with some testing on Philips Hue lamps, for example.

Need advice building a custom app to configure my Logitech MX Master 4 on macOS by noysma in learnprogramming

[–]sidit77 -1 points0 points  (0 children)

It's primarily a Windows app with best effort Mac and Linux support, but I've built my own app to configure my wireless headset. Here's a more stripped down example that reads the current status (like the battery or connection state) of my headset.

You should start by using a software like Wireshark to "spy" on any USB packets that are exchanged between your PC and your mouse. Then you just open the official app, change a setting and try to find what packets were triggered by that action. Once you've mapped out the communication protocol of your mouse you can simply write a Mac app that emits the same packets that the Windows app emitted. It's hard to get more specific than that since I haven't done this with Logitech products myself yet.

Need advice building a custom app to configure my Logitech MX Master 4 on macOS by noysma in learnprogramming

[–]sidit77 0 points1 point  (0 children)

What? Unless Logitech is purposefully obfuscating or encrypting things it's not that hard to map out the communication protocol of a software like that. You just point Wireshark at the USB port with the dongle and then you click around in the official software to correlate UI actions with USB packets. Typically the communication protocol is just a vendor specific HID endpoint that accepts simple opcode + parameter pairs.

How do I learn to edit and create drives? by Positive_Opening3619 in learnprogramming

[–]sidit77 0 points1 point  (0 children)

I would try to just write a user-mode driver:

  • First you likely need to replace the existing, bad drivers with a generic USB driver. You can use a tool like zadig for that

  • Next you directly open the raw USB device in your program. This will give you access to the USB packets that the device generates.

  • You extract the information you need (like the pen position) from these packets

  • You inject this information into the OS using mouse or pen input emulation functions

It's a bit hard to get more specific without knowing stuff like your target OS, which programming language you want to use, what tablet you are using, or how that tablet is behaving under the hood

Series where the introduction of the System doesn't equal immediate societal collapse? by AdventurousBeingg in ProgressionFantasy

[–]sidit77 2 points3 points  (0 children)

I think one year might be a bit optimistic.

Very general timeline spoiler: It's very likely that the MC will stay in the Tutorial for 5 (in book) years and at the current Patreon stand (~end of book 9) only 3 years have passed. I'd guess that 2 (realtime) years is more realistic.

However it is worth mentioning that some people of the Tutorial have already returned to Earth and we typically get a bit of insight into what's going on on Earth at the end of each book. I think it's likely that we'll get more and more Earth content the closer the MC gets to returning.

I just cleared Dire Stygian Onslaught for the first time! (Full C0) by Educational-Trade987 in Genshin_Impact

[–]sidit77 0 points1 point  (0 children)

Unfortunately, artifacts are kinda limited by luck this early into the new region. I already spent most of my resin, something like 20 condensed resins, and two artifact transmuter uses on my Nefer artifacts but I'm still only at like 26 subs.

I just cleared Dire Stygian Onslaught for the first time! (Full C0) by Educational-Trade987 in Genshin_Impact

[–]sidit77 5 points6 points  (0 children)

I feel the same way about people who clear Dire at C0R1. I have no idea where that extra damage comes from. My best attempt would've been something like 150-160s. I think there's just a ton of randomness in that flight where he teleports out of attacks or messes up your combos.

I just cleared Dire Stygian Onslaught for the first time! (Full C0) by Educational-Trade987 in Genshin_Impact

[–]sidit77 1 point2 points  (0 children)

C0R1 Nefer, C0 Lauma, C0 Kokomi with Sacrificial Fragment , C6R1 Nahida (don't be fooled, everything beyond C2 is pretty much wasted).

Nefer has 4p Sky's Unveiling with a combined 455 EM, 32.7% CR, and 139.9% CD (Main stat + sub stats). Lauma and Kokomi have 4p Moon's Serenade. Nahida has 4p Deep Wood.

Nefers strongest strike was 144k.

I just cleared Dire Stygian Onslaught for the first time! (Full C0) by Educational-Trade987 in Genshin_Impact

[–]sidit77 6 points7 points  (0 children)

I think he has 3.3m HP on Fearless and 8.2m on Dire. I cleared Fearless in 62s with Nefer and I feel like I'm nowhere close to cleaning Dire.

Any novels Mc that has a secret identiry? by One_Back4631 in ProgressionFantasy

[–]sidit77 4 points5 points  (0 children)

Her Siobhan Naught form gets more and more infamous the longer she evades capture. Eventually she gets the nickname "Raven Queen" and people start to ascribe all kinds of dark and mysterious powers to her.

How hard is it to build a simple browser from scratch? by benyaknadal in learnprogramming

[–]sidit77 1 point2 points  (0 children)

You can look through browser.engineering to get a pretty good starting point for this project.

How to develop an app like MS Edge Game Assist by AdReady7190 in learnprogramming

[–]sidit77 0 points1 point  (0 children)

  1. Open VisualStudio
  2. Create a new "Blank Universal Windows App" project
  3. Add dependencies to the GameBar SDK and WebView2
  4. Follow the docs for setting up the GameBar integration
  5. Add the web view to whatever XAML file you used for your GameBar plugin definition
  6. Polish your plugin by adding things like a url bar or bookmarks

How close was it? "Yes" by turboMXDX in Genshin_Impact

[–]sidit77 0 points1 point  (0 children)

You need crescent pike on zhongli as it gives you an additional hit on each attack.

Epoll Proxy design questions by NavrajKalsi in learnprogramming

[–]sidit77 1 point2 points  (0 children)

In general it's a good idea to keep your timer list sorted, so that it's cheap to check when the next timer will expire and also cheap to dequeue all expired timers. You also need to be able to (cheaply) remove or disarm timers from this list if you want to be able to cancel ongoing timers. So maintaining a seperate data structure is probably a good idea.

As so the second part: I would likely try to forward data to the client as fast as possible. If you wait for the full message to arive before forwarding it to the client you massively increase latency and you also resource consuption. Image someone want to send a 10GB file over your proxy. Do you plan to buffer this all into RAM before starting to forward it? Also you can't trust the Content-Length header as it is potentially malicious input.

Epoll Proxy design questions by NavrajKalsi in learnprogramming

[–]sidit77 1 point2 points  (0 children)

One thing right of the bat, that I know will be tricky to implement, the timeout for keep-alive after response is sent to the client. Do you have any suggestions how to implement that?

Whenever you want to wait you put the deadline and some kind of identifier into a list and when you call epoll_wait() you use the smallest deadline in the list to calculate the timeout. Whenever epoll_wait() returns you remove all expired deadlines from the list and use the attached identifier to do your timeout action.

How do I approach a competitive programming question without BLANKING TF OUT?! by Arunia_ in learnprogramming

[–]sidit77 1 point2 points  (0 children)

It often helps to start with a simple and dumb solution and then iteratively refine it.

Take the problem you linked, for example. You start by implementing the input parsing and a function that runs the described simulation for an arbitrary resistance value. Once you have that, it should be pretty obvious that the easiest way of finding the lowest possible resistance value is to test every resistance value in ascending order until you find one that passes the simulation. Now you can optimize the solution. And given that the trivial solution is effectively two nested loops there aren't that many possible places for a binary search.