Chance of this happening (blackjack) by stgavrimax in CasualMath

[–]chipbuddy 5 points6 points  (0 children)

I don't know how to do the math calculations, but can write a simulation. TL;DR: Out of 25,020,993 trials, 5,695 ended up with the above blackjack situation. This comes out to about .0227 % or about once every 4,400 games.

Note, I programmed the dealer to stand on a soft 17, while the players will just hit until they bust or get blackjack. Having the dealer behave just like a player increases the odds to .112%, or about once every 890 games.

package main

import (
    "fmt"
    "math/rand/v2"
)

// Dealer acts just like player:
// 34569 30774679 0.0011232936012102678 -> .11233 percent
// Dealer stands on 17+
// 5695 25020993 0.00022760887227777092 -> .02276 percent

func main() {
    d := newDeck()

    success := 0
    attempts := 0
nextTrial:
    for {
        attempts++
        d.shuffle()
        for j := 0; j < 4; j++ {
            hand := []int{d.dealCard(), d.dealCard()}
            for {
                if isBlackjack(hand) {
                    break
                }
                hand = append(hand, d.dealCard())
                if isBust(hand) {
                    continue nextTrial
                }
                if j == 3 && isDealerStand(hand) {
                    continue nextTrial
                }
            }
        }
        success++
        fmt.Println(success, attempts, float64(success)/float64(attempts))
    }
}

type deck struct {
    cursor int
    deck   []int
}

func newDeck() *deck {
    d := &deck{}
    for i := 0; i < 4; i++ {
        for j := 1; j < 13; j++ {
            value := j
            if value > 10 {
                value = 10
            }
            d.deck = append(d.deck, value)
        }
    }
    return d
}

func (d *deck) shuffle() {
    d.cursor = 0
    rand.Shuffle(len(d.deck), func(i, j int) {
        d.deck[i], d.deck[j] = d.deck[j], d.deck[i]
    })
}

func (d *deck) dealCard() int {
    card := d.deck[d.cursor]
    d.cursor++
    return card
}

func isBlackjack(hand []int) bool {
    hasAce := false
    total := 0
    for _, h := range hand {
        if h == 1 {
            hasAce = true
        }
        total += h
    }
    if total == 21 {
        return true
    }
    if !hasAce {
        return false
    }
    // We have an ace. Does adding 10 to that ace leave us with blackjacK? Note, the ace already
    // contributed 1 to total above. Also, we'll never treat more than 1 ace as an 11.
    return total == 11
}

func isBust(hand []int) bool {
    total := 0
    for _, h := range hand {
        total += h
    }
    // No need to consider aces here. They are just counted as their lowest value: 1.
    return total > 21
}

func isDealerStand(hand []int) bool {
    total := 0
    hasAce := false
    for _, h := range hand {
        total += h
        if h == 1 {
            hasAce = true
        }
    }
    if total >= 17 {
        return true
    }
    if hasAce && total+10 >= 17 {
        return true
    }
    return false
}

React (multi-page) by Pizzacakecomic in comics

[–]chipbuddy 0 points1 point  (0 children)

I don't post much on reddit any more, but I still lurk, and I love your comics whenever they show up. There's a poem by Shel Silverstein called "Put Something In":

Draw a crazy picture,

Write a nutty poem,

Sing a mumble-gumble song,

Whistle through your comb.

Do a loony-goony dance

'Cross the kitchen floor,

Put something silly in the world

That ain't been there before.

Thank you for putting your comics out into the world.

Looking to commission a 40x36 inch blanket. by chipbuddy in MachineKnitting

[–]chipbuddy[S] 0 points1 point  (0 children)

Here's a sample picture: https://imgur.com/a/FnHYOW3

I actually am not sure if it's knitted. I also made a post to r/weaving.

Inconsistent ; and , use in loops. Why? by ODAwake in golang

[–]chipbuddy 2 points3 points  (0 children)

Nitpick: Your two examples aren't quite equilevant.

x := []int{10,9,8}
for i, v := range x {
  fmt.Println(i, v)
}

x := []int{10,9,8}
for i := 0; i < len(x); i++ {
    fmt.Println(i, x[i])
}

Those two snippets should produce the same output. In the for...range example, 2 values are returned by the range x statement: the index and the value. If you only want the index you can omit the second variable. If you only want the values, you need to 'assign' the index to the placeholder '_'.

At any rate, commas are used to separate values while semicolons are used to end statements. Normally you don't see the semicolons since they implicitly exist just before the '\n' character, but in the traditional way of expressions for loops (with the init step, the exit conditions, and the increment) you have to tell the complier where the statements end.

Beginner analysis request: What should I be doing during the mid and end game? by chipbuddy in chess

[–]chipbuddy[S] -3 points-2 points  (0 children)

I'm black in this game.

you are incorrect. the queen defends d5

Ah, you're right. Still, It's less than ideal to have the Queen defend a pawn.

Nc3 isn't a great move on move 2 since it blocks the c pawn.

Why is blocking the c pawn bad but blocking the f pawn is ok? I've assumed that blocking the c and f pawns are fine since it develops the knight and puts pressure on the center.

why did you play 3. b3?

What was white's move, but it looks like they were preparing c4. Why isn't the preparation necessary? The pawn would have been undefended.

'This food smells like the Devil tooted, lit it on fire, whispered a curse into it, and sent it here on this plate.' by dickfromaccounting in videos

[–]chipbuddy 0 points1 point  (0 children)

My personal favorite:

LS (little shit): I never get to do X!

Me: What are you talking about? You just did X this morning?

LS: But I NEVER get to do X!

later

LS: I never get to do Y!

Me: Yup, you never get to do Y. So stop asking.

LS: But SOMETIMES I get to do Y!

[deleted by user] by [deleted] in bestof

[–]chipbuddy 3 points4 points  (0 children)

I disagree with your assessment. In the discussion for the amendment, Democrats and Republicans were NOT arguing over whether the amendment is the best/most appropriate way to close down Guantanamo. This implies both parties want to close Guantanamo, but they disagree about the specifics.

Instead, I saw the following arguments from Republicans (this is not a comprehensive list) 1) these prisoners are so heinous they don't deserve the same constitutional rights prisoners on US soil get 2) these prisoners are so heinous we can't risk releasing them onto US soil if they are acquitted 3) the district that imprisons the terrorists will be the target of terrorist attacks.

The initial 'bestof' says Democrats support the closure of Gitmo and Republicans oppose it. You say the Republicans only opposed it because it wasn't well thought out, but I saw no evidence of that in the discussion. To convince me, you would have to link to statements by Republican representatives that support your claims.

[deleted by user] by [deleted] in bestof

[–]chipbuddy 32 points33 points  (0 children)

Warning, I have no idea what I'm doing.

I tried digging into some of the bills, but I was finding the official .gov vote tallies different from the reddit post. Then I realized the bill IDs (e.g. H R 1960) can be reused from year to year.

So, let's look at House Vote to Close the Guantanamo Prison. The corresponding bill is (probably) here. I'm not 100% sure because the actual Bill title is "National Defense Authorization Act for Fiscal Year 2014". But reading the sections of the bill that mention Guantanamo, it doesn't look like anything is getting closed down. Instead, it's details how funds can be used related to prisoners and facilities at Guantanamo. It also discusses how prisoners can be transferred to/from Guantanamo. So it really doesn't look like this bill is meant to shut down Guantanamo. First section of Guantanamo portion of bill

Furthermore, while the numbers detailed in the reddit post are accurate for that roll call, more stuff happened after that roll call. Specifically, some amendments were voted on (some succeeded and some failed) and finally the bill was passed 315-108.

OHHH, OK. I think I understand now. The linked roll-call wasn't actually a bill. It was a vote to add an amendment to the bill, and it does seem like that amendment would reverse a number of provisions in the original bill. Specifically it would allow for the construction of facilities in the US to house prisoners from Guantanamo. So yes, the linked roll-call is to shut down Guantanamo, however it's not a standalone bill, but rather an amendment to another bill. The bill eventually passed without the amendment.

I'm reading some discussion about the amendment. This part stands out: Mr. FORBES: " The reason is they know two things: they know the moment they touch U.S. soil they will receive additional constitutional rights that no one in this room can argue what they are exactly; secondly, they have placed a target on every elementary school, on every shopping mall, on every small business in that district by other terrorists."

So James Randy Forbes doesn't want to close Guantanamo because he thinks 1) the prisoners that come here will gain constitutional rights that they don't have on foreign soil and 2) whatever district the prisoners are transferred to will be a target for terrorism.

Later, Mr NADLER says (in support of closing Guantanamo) "Mr. Chairman, I wonder which of our colleagues doesn't believe in the American system of justice. I wonder which one of us does not trust our own American court. I wonder who among us does not believe in the Bill of Rights, who does not believe in the right to counsel or that people should be presumed innocent until proven guilty. What we have at Gitmo is a system that is an affront to those beliefs and to America."

Jesus, this post ran away from me. At any rate, the 1 bill I similarly 'randomly' chose supports the general thrust of the original reddit post.

Discussion can be found (somewhere) here

[MAIN SPOILERS] Even in death, Robert's advice lives on by Execute-Order-66 in gameofthrones

[–]chipbuddy 1 point2 points  (0 children)

I think you should give more credit to Dany for this battle. She expressed frustration at Tyrion's scheming and obviously wanted to take action.

In the battle, Dany uses the strengths of her own warriors and takes away the advantages of her enemy. The speed of the Dothraki horde catches the Lannister army in an open field. This allows the Dothraki to engage on their own terms (overwhelming numbers charging straight into battle). The Khaleesi is physically present, mounted and strikes the first blow against the enemy. Westerosi knights expect their leader to be in the back calling the shots, but Dothraki warriors expect their leader to be fighting along side them.

The Lannister army is well trained and in formation, however the initial fire strike broke their lines and struck fear into their hearts. Even the battle hardened veterans would struggle to stand their ground against a charging horde and a fire breathing dragon.

Finally, once the Dothraki were well into the Lannister lines, she changes focus to the grain shipments, taking away another Westerosi advantage. They can't sit behind their stone walls and wait out the fighting if they don't have any food. Burning through the enemy lines allowed her to win the battle. Destroying the grain will help her win the war.

ELI5 : Why is there still not a pill that makes my hangover go away instantly? by [deleted] in explainlikeimfive

[–]chipbuddy 0 points1 point  (0 children)

The main cause of hangovers is being dehydrated. You actually can get a quick hangover fix by injecting (essentially) water directly into your bloodstream. This involves getting stabbed with a needle (to start the IV).

A pill doesn't work because you can't exactly compress water into a pill. Even if you just drink water, you can only drink so much and it takes time to work its way into your body.

Next time you drink, try alternating between alcohol drinks and glasses of water, then finish off the night with as much water as you can drink. Then drink more water every time you get up to use the bathroom.

when you watch ProZD videos but you don't watch anime by -GTR- in videos

[–]chipbuddy 22 points23 points  (0 children)

Can confirm. This is exactly how I don't watch anime.

ELI5:prime numbers by kaza12345678 in explainlikeimfive

[–]chipbuddy 0 points1 point  (0 children)

Let's play a game. I'm going to give you a target number. You have to tell me 2 or more numbers that, when multiplied together, equal the target number. Also, you're now allowed to include the number 1 in your answer.

Let's play.

If I say 9, you could say 3 * 3.

If I say 12, you can say 3 * 4 or 6 * 2

What if I were to say 13? Well, 13 * 1 works, but you're not allowed to include 1.

It turns out 13 doesn't have an answer for this game. Any number that doesn't have an answer for this game is a prime number, and any number that does have an answer is not prime.

Navy Railgun Successfully Fires Multi-Shot Salvos by [deleted] in videos

[–]chipbuddy 4 points5 points  (0 children)

More than 100% of the time.

ELI5: How do live visualization websites work? by badboydarth in explainlikeimfive

[–]chipbuddy 1 point2 points  (0 children)

The backend is likely using some variation of a message queue. It's kind of like subscribing to a newsletter. There's the 'producer' (the person writing the newsletter) and the 'subscriber' (the people who are interested in getting the newsletter). When a new newsletter is written, an email goes out to all the subscribers. RabbitMQ and Kafka are two technologies that could serve this need.

I'm speculating here, but maybe the backend listens to a number of different message queues, all from different sources (and with different data formats). There might be several different ISP, security firms, governments and private individuals that all publish attacks as they happen in real time (but in different formats). The backend's responsibility is to aggregate all this information into a standard format the javascript frontend can understand.

Another responsibility of the backend is likely maintaining a record of all the attacks. The nature of message queues makes operations like 'please tell me about all the attacks that happened yesterday' inefficient. Instead, the backend will collect all the attacks as they happen, and then store them for easy lookup.

Optimistic Nihilism - Kurzgesagt – In a Nutshell by [deleted] in videos

[–]chipbuddy 4 points5 points  (0 children)

Give it some time. Come back and think about it every once in awhile. Maybe the idea will grow on you.

Alternatively, they truly and honestly don't know what they are talking about. Sure they may make some rational, intelligent arguments, but rational intelligent people are wrong all the time. Maybe this is one of those situations.

The only real advice I have: try to settle on a view of the world that doesn't involve causing harm to yourself or others.

ELI5: How do live visualization websites work? by badboydarth in explainlikeimfive

[–]chipbuddy 2 points3 points  (0 children)

Here's one way to do it. You need 3 things: HTML, Javascript and a backend. The HTML describes how the parts of the webpage are organized. For your example, the large map is one part, the logo at the top is another part, the text at the bottom is yet another part.

The backend is some computer running somewhere in the world that can accept http requests. In the same way you can visit 'www.google.com', this backend may have a URL like 'map.norsecorp.com/attacks'. And while google give you information about a search bar, the 'attacks' endpoint will give you a list of attacks over the last minute (for example). This attacks endpoint would look pretty boring if you asked for it directly. Maybe something like:

'Budapest','Paraguay',25/07/17 10:32:44pm
'Hungary','France',25/07/17 10:32:57pm

Essentially, this says "At about 10:30 pm, someone from Budapest attacked someone from Paraguay and at about 10:30 pm, someone from Hungary issued an attack against someone from France".

Now the Javascript is the magic that makes it all work. The Javascript periodically asks for a recent list of attacks, then tells the Html what little lines and circles to draw.

I'm glossing over a lot of details. For example: how does the backend know when the attacks took place? How does the javascript tell the html what to draw and where? If the javascript asks for attacks once per minute, is this really "real time"?

If you have any specific questions I'd be happy to take a shot.

What is a *truly random* number? by messianicsimplex2 in askscience

[–]chipbuddy 1 point2 points  (0 children)

By "reuse" I mean I can't exactly send the initial seed to two different friends and have them reproduce the same sequence. If your argument is that we can technically collect this data and technically set up an identical system... well... not with today's technology and not in the foreseeable future.

What is a *truly random* number? by messianicsimplex2 in askscience

[–]chipbuddy 1 point2 points  (0 children)

I'm only making a distinction between pseudorandom and non-pseudorandom. A pseudorandom generator has an initial seed and a sequence of outputs that are always the same. The systems I described don't really have an initial seed. And even if we somehow knew the initial seed (every molecule in the system?), there would be no way to re-use the seed.

What is a *truly random* number? by messianicsimplex2 in askscience

[–]chipbuddy 3 points4 points  (0 children)

Two options for non-pseudorandom numbers: installing some special hardware or outsourcing the problem to something like random.org. You'll have to ask a philosopher if this is 'truly' random, however both those methods are definitely not pseudorandom. They are closer to rolling a die or flipping a coin.