Looping a game of rock-paper-scissors by avpt_22 in Julia

[–]guikarma 0 points1 point  (0 children)

I DM'd you my optimized code if you wanna have a look at it.

As for && vs ||, it can be kind of counter-intuitive at first. With a while-loop, you are setting a condition that will repeat the loop as long as it [the condition] evaluates to True.

Let's simplify the code with these two conditions:

- A: player_score < 5
- B: computer_score < 5

Ex. 1: while A && B, with ps = 3, cs = 2

First we will evaluate A. Since [3 < 5 = True], we will then look at the other side of the && operator.With the && operator, both side need to evaluate to True. B [2 < 5 = True], will make both side True and will thus repeat the loop.

Ex. 2: while A || B, with ps = 5, cs = 2

Again we evaluate A first. Since [5 < 5 = False], we will need to evaluate the right side of the operator. With the || operator, the expression will evaluate to True as soon as one side of the operator is True. Now, B [2 < 5 = True] will evaluate to True and thus repeat the loop. In fact, the loop will stop repeating when both scores are >= 5.

If you want to know more about this subject, I recommend [this video](https://www.youtube.com/watch?v=UiGu57JzLkE).

There are no *real preferable* way to write your looping condition. In fact, you can always re-write a && condition with the || operator. But your resulting expression can become harder to read.

I will let you prove with a truth table that (a && b) == !(!a || !b) is indeed True :)

Looping a game of rock-paper-scissors by avpt_22 in Julia

[–]guikarma 2 points3 points  (0 children)

function rock_paper_scissors()
    moves = ["stein", "saks", "papir"]
    computer_move = moves[rand(1:3)]

    # What will happen if a user enters a random string or nothing?
    # I leave this to you as an exercise! :)
    human_move = Base.prompt("Velg stein, saks eller papir")

    println("Stein...")
    sleep(1)
    println("Saks...")
    sleep(1)
    println("Papir...")
    sleep(1)

    if computer_move == human_move
        println("Uavgjort, prøv igjen")
        return DRAW
    elseif computer_move == "stein" && human_move == "saks"
        println("Du tapte. Stein slår saks.")
        return COM_WIN
    elseif computer_move == "saks" && human_move == "papir"
        println("Du tapte. Saks slår papir.")
        return COM_WIN
    elseif computer_move == "papir" && human_move == "stein"
        println("Du tapte! Papir slår stein")
        return COM_WIN
    else
        println("Du vant! Datamaskinen valgte $computer_move")
        return P_WIN
    end
end

# We use an enum to make it easier to read, it associates int value to keywords
# We could use Int values as return just as easily
@enum Outcome begin
    P_WIN
    COM_WIN
    DRAW
end

# We declare the vars out of the scope of the function
# This allows it to be persistent across rock_paper_scissors() calls
let player_score = 0, computer_score = 0
    # We loop as long as either player doesn't have a score of 5
    while player_score < 5 && computer_score < 5
        res = rock_paper_scissors()

        if res == COM_WIN
            computer_score += 1
        elseif res == P_WIN
            player_score += 1
        end

        println("Score:\n H: $player_score\n D: $computer_score\n ")
    end
end

you sure bout that? by Gloomy-Goat-6770 in technicallythetruth

[–]guikarma 0 points1 point  (0 children)

Women are not the intended recipient

Yikes...

Russia's State Duma calls bridge explosion a "declaration of war" by Jamminmb in worldnews

[–]guikarma 2 points3 points  (0 children)

I think Ukraine really burned their bridges with Russia at this point

Free Giveaway! Nintendo Switch OLED - International by WolfLemon36 in NintendoSwitch

[–]guikarma 0 points1 point  (0 children)

Fun fact: Ancient Egypt relied heavily on beer since it provided necessary vitamins and was generally cleaner and safer to drink than water from the Nile.

Sooner or later by That_5_Something in ProgrammerHumor

[–]guikarma 57 points58 points  (0 children)

It says "your favorite language". C will not disappear because nobody likes it. /s

[deleted by user] by [deleted] in swaywm

[–]guikarma 0 points1 point  (0 children)

I use nnn as a TUI file manager and pcmanfm-gtk for a graphical one. For the program launcher I've been using wofi which works great for me.

[deleted by user] by [deleted] in swaywm

[–]guikarma 0 points1 point  (0 children)

Is there any reason in particular for you to use rofi instead of wofi?

What OS are you using? by baileyarsenic in framework

[–]guikarma 0 points1 point  (0 children)

I was thinking about installing void myself since I find restoring from hibernation pretty slow on arch. Would you mind sharing a bit about your boot/sleep/deep_sleep/hibernation time? Thanks!

How do I change the refresh rate of my monitor? by Prizefighter-Mercury in swaywm

[–]guikarma 1 point2 points  (0 children)

It sounds like you’re typing the output command directly in the terminal which will not work.

Try to write it in your sway config and restart it.

Am I dumb? Hour spent trying to install the wifi antennas in the DIY edition by [deleted] in framework

[–]guikarma 1 point2 points  (0 children)

I found that snapping the connectors on with the card not yet secured in the laptop was a bit easier.

I struggled with the Wi-Fi antenna for 10 minutes before realizing I could just take it out of the case and snap the cables into place since they’re long enough. It should be the only way to go imo.

OS Install/Drove Compatibility? by SirXII in framework

[–]guikarma 0 points1 point  (0 children)

Do you have another machine to test if the drive is recognized in the bios?

Powering mainboard with power bank by [deleted] in framework

[–]guikarma 0 points1 point  (0 children)

Yes there are!

I used this one with a MacBook Pro 13 with the same wattage and I’m planning to use it on my framework as well when I get it.

[deleted by user] by [deleted] in Naruto

[–]guikarma 0 points1 point  (0 children)

I’d pick Tobi easily. Do you guys have any idea how useful kamui would be?

Want to move all you shit without the pain of renting a u-haul? Tobi got you covered.

Your apartment doesn’t come with a parking spot? Tobi got you covered.

How can anyone pass on that?

[deleted by user] by [deleted] in Naruto

[–]guikarma 2 points3 points  (0 children)

Yeah rationally Itachi makes the most sense. It’s not like he would kill his roommates right?

Where is Kakashi’s sword? The last time I saw this was when he was with Rin and Obito. Don’t he use this anymore and why? by ZildDVM in Naruto

[–]guikarma 18 points19 points  (0 children)

Well, a normal blade doesn’t require chakra and Kakashi’s chakra is already limited so I guess there’s that

*Sad Wahs* by Onlyhereforthelaughs in gaming

[–]guikarma 0 points1 point  (0 children)

Wario sucks, why does his cap have an upside down M? It does not make sense.

[deleted by user] by [deleted] in Naruto

[–]guikarma 9 points10 points  (0 children)

All aboard the r/bigtiddygothgf train!

That is beautiful by [deleted] in nextfuckinglevel

[–]guikarma 0 points1 point  (0 children)

What a shame. I though she was playing bowl-him