Hammerheart

joined 2 years ago
[–] Hammerheart 1 points 1 day ago

This is amazing, thank you! You've given me a lot to think about, not just with respect to this program, but what sort of things to consider when analyzing the behavior of any program. Describing the classes of input like you did was enlightening.

[–] Hammerheart 1 points 1 day ago

I added a description to OP.

Gambler (PROGRAM 1.3.8) is a simulation that can help answer these questions. It does a sequence of trials, using Math.random() to simulate the sequence of bets, continuing until the gambler is broke or the goal is reached, and keeping track of the number of wins and the number of bets.

5
submitted 1 day ago* (last edited 1 day ago) by Hammerheart to c/learn_programming
 

I'm going through the Programming With a Purpose course on Coursera, and trying to come up with my own implementation of some of the example programs before looking at the example. I just finished the example of a gambling situation. I was hoping to get some more eyes on my code and be told whether my version is going to behave differently from the example. Due to the nature of simulations, I can't just compare the output of the two, since it will vary.

This is the explanation of what the code is meant to represent:

Gambler (PROGRAM 1.3.8) is a simulation that can help answer these ques tions. It does a sequence of trials, using Math.random() to simulate the sequence of bets, continuing until the gambler is broke or the goal is reached, and keeping track of the number of wins and the number of bets.

Mine:

public class Gambler
{
    public static void main(String[] args)
    {
        int stake = Integer.parseInt(args[0]);
        int initialStake = stake;
        int goal = Integer.parseInt(args[1]);
        int desiredGain = goal - stake;
        int trials = Integer.parseInt(args[2]);
        int games = 0;
        int wins = 0;
        int bets = 0;

        while (games < trials)
        {
            bets++;
            if (Math.random() >= 0.5)
            {
                stake++;
                desiredGain = goal - stake;
                if (desiredGain <= 0)
                {
                    wins++;
                    games++;
                    stake = initialStake;
                }
            }
            else
            {
                stake--;
                if (stake < 1)
                {
                    games++;
                    stake = initialStake;
                }
            }
        }
        int averageBets = bets / trials;
        int percentWins = (100*wins / trials);
        System.out.println("Theoretical chance of winning: " + 100*initialStake/goal);
        System.out.println("Expected Bets: " + initialStake*(goal - initialStake));
        System.out.println(percentWins + "% wins");
        System.out.println("Average # bets: " + averageBets);
    }
}

Example:

public class Gambler2
{
    public static void main(String[] args)
    {
        int stake = Integer.parseInt(args[0]);
        int goal = Integer.parseInt(args[1]);
        int T = Integer.parseInt(args[2]);
        int bets = 0;
        int wins = 0;

        for (int t=0; t<T; t++)
        {
            int cash = stake;
            while (cash > 0 && cash < goal)
            {
                bets++;
                if (Math.random() < 0.5) cash++;
                else                     cash--;
            }
            if (cash == goal) wins++;
        }
    int averageBets = bets / T;
    int percentWins = (100*wins / T);
    System.out.println("Theoretical chance of winning: " + 100*stake/goal);
    System.out.println("Expected Bets: " + stake*(goal - stake));
    System.out.println(percentWins + "% wins");
    System.out.println("Average # bets: " + averageBets);
    }
}

The example is obviously much cleaner, but here is why I think mine should work the same:

  1. Each time the player's current stake exceeds the goal or reaches 0, the number of games played is incremented. When games == trials, the loop ends.
  2. When a game ends, stake is reset to its initial value for the next trial
  3. Bets is incremented each time the loop runs
  4. If the current stake meets or exceeds the goal, wins is incremented

I set up my conditions for interpreting the output of Math.random() opposite of the example. If that even makes a difference at all, it seems like it would take a lot more than 1000 trials before it became apparent.

I just want to make sure I'm not missing something.

[–] Hammerheart 2 points 5 days ago (1 children)

Were you able to transfer those concepts you learned from clojure to other languages?

[–] Hammerheart 1 points 1 month ago* (last edited 1 month ago) (1 children)

thank you! your command worked like a charm once i prepended it with exec. i even added a final command taking me back to workspace 1. tested it with exec_always and it seems to be good, crossing fingers it will actually work on boot.

maybe you can answer another question for me: is the config file executed asynchronously? What i mean is, does it run through each line, or is there a chance that, say, line 25 might execute before line 13?

 

I've been struggling with getting a wezterm window running cmus on a specific workspace upon start up for a while now. I can't use assign because the only eligible criteria differentiating it from a generic wezterm window is the pid, and my attempts to get the pid from get_tree and use that have been unsuccessful. I thought I had figured it out, when I put these lines in a another file:

#! /bin/bash
sway workspace 10 && sway 'exec wezterm -e cmus'

then in my config file I have this: exec ./start_cmus.sh

But it doesn't work. If I run start_cmus from the shell, the expected behavior ensues (a wezterm window running cmus is opened on workspace 10).

Any tips?

 

I have to read more Zelazny after this. I was struck by two things in particular: The surprising playful quality of the prose. He has little vignettes dispersed among the main narrative, and it gave me the sense that Zelazny was having a lot of fun while writing this book. It was kind of refreshing after reading so many other self-seriously, rigidly constructed novels. It gave me a feeling similar to the ones I experience when I listen to some experimental music, where the process is not treated as a mere necessary evil on the way to the finish product.

The second thing was struck a chord was the ending. I liked how it was all show and no tell, which I wasn't expecting. It was kind of creepy, and very intense. I wasn't expecting such a visceral end to a book which, until then, had been rather laid back.

Now that I've finished it, I feel like it was very dense, thematically. I suspect I will revisit it and gleam many meanings which I missed this time.

I would like to open the thread to recommendations. I've heard he wrote a fantasy series that is pretty good, and I think I would like to check that out.

[–] Hammerheart 2 points 2 months ago

The jank is kind of severe, but I like what they're trying to do. Still, I keep meaning to make a bug report, because I cant right click on the tab bare without the browser crashing more than half the time.

[–] Hammerheart 19 points 2 months ago (3 children)

short variable names, and the only vowel is 'i'

[–] Hammerheart 1 points 2 months ago

Metaservices.

[–] Hammerheart -4 points 2 months ago (1 children)

Rust is a psyop

[–] Hammerheart 2 points 2 months ago (2 children)

I think the default mod key is the 'super' key (formerly known as the windows key). It might be alt actually, I don't remember. Super + 1-9 switches between workspaces, which hold your windows. Shift + super + 1-9 moves a window to another workspace. you can find more key bindings by viewing $XDG_CONFIG_HOME/sway/config (or wherever config files go on your system).

[–] Hammerheart 6 points 2 months ago

I think those are more interesting. I like seeing the process.

[–] Hammerheart 9 points 2 months ago

That's kindeof poetic tbh

[–] Hammerheart 1 points 4 months ago* (last edited 4 months ago)

Python

(Part 1) omg I can't believe this actually worked first try!

with open('input') as data:
    parts = data.read().rstrip().split("\n\n")
    ordering_rules = parts[0].split("\n")
    updates = parts[1].split("\n")

correct_updates = []
middle_updates = []

def find_relevant_rules(pg_num: str, rules: list[str]) -> list[str] | None:
    for rule in rules:
        return list(filter(lambda x: x.split("|")[0] == pg_num, rules))

def interpret_rule(rule: str) -> list[str]:
    return rule.split("|")

def interpret_update(update: str) -> list[str]:
    return update.split(",")

def find_middle_update_index(update: list[str]) -> int:
    num_of_elements = len(update)
    return num_of_elements // 2

for update in updates:
    is_correct = True
    for i, page in enumerate(interpret_update(update)):
       rules_to_check = find_relevant_rules(page, ordering_rules) 
       for rule in rules_to_check:
           if rule.split("|")[1] in interpret_update(update)[:i]:
               is_correct = False
    if is_correct:
        correct_updates.append(update)

for update in correct_updates:
    split_update = update.split(",")
    middle_updates.append(int(split_update[find_middle_update_index(split_update)]))
print(sum(middle_updates))
5
submitted 4 months ago* (last edited 4 months ago) by Hammerheart to c/advent_of_code
 

So this is really kind of tangential, I am just messing around with the data and trying to at least nail down some basics so I can do sanity checks in my actual code. I am running into an odd discrepancy when trying to determine the number of times "XMAS" occurs in the input. I am only concerned with the straight forward matches, the instances of the substring "XMAS" appearing in the raw data.

When i do "grep -c XMAS input" or "rg -c XMAS input" they both show 107. But when I use regex101.com and search for the pattern XMAS, it shows 191 matches. Please help, I am truly at a loss here. While writing this, it occurred to me to just try using string.count("XMAS") in python on the data as a raw string, and it also returns 191. So really this question is more about grep and rp than anything. why are they only returning 107?

 

I am working on a rudimentary Breakout clone, and I was doing the wall collision. I have a function that I initially treated as a Boolean, but I changed it to return a different value depending on which wall the ball hit. I used the walrus operator to capture this value while still treating the function like a bool. I probably could have just defined a variable as the function's return value, then used it in an if statement. But it felt good to use this new thing I'd only heard about, and didn't really understand what it did. I was honestly kind of surprised when it actually worked like I was expecting it to! Pretty cool.

 

All I want to do is put a still image over a MP3 so I can upload a song to Youtube. (Sidenote: It feels really good to find a song I want to show someone that isn't already on Youtube. It used to be a somewhat regular thing i'd do, I have about a dozen Youtube videos that are just songs I uploaded because I wanted to show them to someone, but I guess Youtube got more stuff and my taste got more pedestrian, so I haven't felt the need to do it until now. Feels good!)

I used VEED, a web editor, and it produced a >300mb file. That seems a bit excessive. For the curious, this is the song: https://youtu.be/iLz7VXhCrnk

7
submitted 10 months ago* (last edited 10 months ago) by Hammerheart to c/[email protected]
 

Every so often, I accidentally activate .... what ever this is... I can't seem to find any info on what it's called, or exactly what hotkey makes it happen. It kinda bugs me because tonight I wanted to turn it on, because I wanted to access something from my history that it would have been tedious to up arrow to. I thought windowsKey + , did it, but when I tried it in a new tab, it didn't work. Someone must know what this is and how to toggle it.

 

I started working through the 100 Days of Code course of Udemy last February, and I'm in the home stretch. I'm on the final lessons, which are really just prompts for projects. No hand holding, just a brief description of the goal. I recently finished a tkinter GUI program, the goal of which was to enable adding text watermarks.

I took a few liberties--mainly, I made it possible to layer a png on top of the background. It was a really fun project and quickly grew more complicated than I expected it to. I got some hands on experience with the Single Responsibility Principle, as I started off doing everything in my Layout class.

Eventually, I moved all the stuff that actually involved manipulating the Image objects to an ImageManager class. I feel like I could have gotten even more granular. That's one thing I would love to get some feedback on. How would a more experienced programmer have architected this program?

Anyway, I guess this preamble is long enough. I'm going to leave a link to the repository here. I would have so much appreciation for anyone who took the time to look at the code, or even clone the repo and see if my instructions for getting it to run on your machine work.

Watermark GUI Repo

 

cross-posted from: https://programming.dev/post/14680192

I have a VPS, but no root access so I can't use apt, or even read a lot of the system files. I would like to get jellyfin (or any media server, really) running on it. Jellyfin has a portable installation option, so I followed the instructions in the docs to install it from the .tar.gz.

But it says I have to install ffmpeg-jellyfin, and I can't find a portable installation of that. My VPS already has ffmpeg installed on it. Will jellyfin work if I just point it to that instead? Or, how can I go about installing ffmpeg-jellyfin without root access?

 

I have a VPS, but no root access so I can't use apt, or even read a lot of the system files. I would like to get jellyfin (or any media server, really) running on it. Jellyfin has a portable installation option, so I followed the instructions in the docs to install it from the .tar.gz.

But it says I have to install ffmpeg-jellyfin, and I can't find a portable installation of that. My VPS already has ffmpeg installed on it. Will jellyfin work if I just point it to that instead? Or, how can I go about installing ffmpeg-jellyfin without root access?

 

I recently got ssh set up so I can do stuff in powershell on my desktop from my laptop. I want to be able to start a movie on my desktop from my laptop, instead of having to reach for my wireless keyboard. I was researching how to do this with SSH, and it looks like OpenSSH no longer allows you to run the server as a user, it can only be ran as a service which doesn't have access to the desktop.

What's the best way to achieve this functionality?

 

I have been using sway (basically i3 for Wayland) instead of a traditional desktop environment because it really makes a difference in my laptops performance.

But apparently sway ignores .desktop files which was how i was autostarting things on KDE.

Is the best way to handle this by going through the sway config? If not, how would you do it.

Bonus points if you can tell me how to get the autostart programs to also open in specific workspaces.

view more: next ›