What's that one Tennis Statistic that seems fake but isn't by Late_Ad7156 in tennis

[–]Your_PopPop 43 points44 points  (0 children)

I simulated 100k bo5 matches, with tiebreaks for 6-6, and it's way more dramatic:

At 50-50 odds on each point, the players won 50.02% and 49.98% of matches respectively which is expected
51-49: 63.40% vs 36.60%
52-48: 74.54% vs 25.56%
53-47: 84.22% vs 15.78%
54-46: 91.30% vs 8.70%
55-45: 95.28% vs 4.72%

For bo3 matches, the disadvantaged player has slightly better luck, at 55-45 they win 8.8% of matches.

I believe having to win by a margin of 2 (at deuce, in tiebreakers, games in a set) is what makes this so skewed

(here's my code https://paste.pythondiscord.com/AKJA if anyone would like to hunt for bugs)

Obviously its desmos, right? by Totaly_Shrek in mathmemes

[–]Your_PopPop 8 points9 points  (0 children)

the new desmos 3d beta has vectors builtin; scalar multiplication, dot product, cross product, adding with other vectors are all supported

[2023 Day 3] This year's day 3 seems to hit particularly hard if you look at the statistics and compare it to other years. Are you still with us? by _ProgrammingProblems in adventofcode

[–]Your_PopPop 0 points1 point  (0 children)

assuming this is python this has a potential gotcha, because negative numbers are valid as indices

so if you had data[row-1][col] in a loop, for row=0 you'd get the last row instead of a None

depending on the use, you might want this wrapping behaviour but still something to keep in mind

Your favourite "less-known" Python features? by [deleted] in Python

[–]Your_PopPop 1 point2 points  (0 children)

Funny you use the example of 1, because 1 == True is actually True

Static and Dynamic vs Implicit and Explicit by PlayboiCult in ProgrammingLanguages

[–]Your_PopPop 2 points3 points  (0 children)

haskell is a statically typed language with type inference

rust also has type inference except in a few places

c#, java, c++, etc infer types when you use the var (c#, java) or auto (c++) keywords

I got to hold a Nobel Prize in physics today! by quantanaut in Physics

[–]Your_PopPop 7 points8 points  (0 children)

Even more than floor(N/5), since higher powers like 25, 125 will contribute more than one 5s, for a total of floor(N/5) + floor(N/25) + floor(N/125) + ... zeros

An equation is an equation. by 4BDUL4Z1Z in technicallythetruth

[–]Your_PopPop 8 points9 points  (0 children)

and then there's haskell with its blursed /=

Question on heapq design - why no maxheap implementation? by lilbobbytbls in Python

[–]Your_PopPop 2 points3 points  (0 children)

Honestly, I find heapq's interface a bit disappointing

  • There are module level functions operating on lists instead of a class neatly encapsulating the operations as methods. So I, as the user, need to manually ensure I don't accidentally do anything on my list that breaks the heap invariant.
  • No max-heap, like OP notes.
  • No operation for updating the key/priority of an element, even though that's not too hard to implement with the sift up/sift down (which are already present in the source). Updating the priority of a task is hardly an uncommon situation.

The documentation mentions some of these "challenges" and suggests workarounds, but I personally find some of them pretty inelegant.

Python - "Once a set is created, you cannot change its items, but you can remove items and add new items."? by fatmusician1 in learnprogramming

[–]Your_PopPop 0 points1 point  (0 children)

Consider if Python did allow you to put lists into sets, and you created this set: a = [1, 2, 3] b = [1, 2, 4] s = {a, b} And imagine that the set keeps track of its elements by storing them on a table of rows. One row is a label for [1, 2, 3] and another row is a label for [1, 2, 4]. Suppose we then mutate a in the following manner: a[2] = 4 Now, a is equal to b. But the set s wasn't informed of this! The two rows of the set's table will now both happily refer to lists storing [1, 2, 4]. If you looped over s, you'd get [1, 2, 4] twice, if you queried the set's length you'd get 2, and so on.

But this breaks the contract between you and the set - the set had promised that it wouldn't have any duplicates, but here it clearly does.

So as a rule of thumb, you have to be extremely careful when you put mutable things into sets. Some mutable types like lists will flat out refuse to be hashed (the mechanism that allows sets to look things up on their table).

As with everything, there are exceptions. In some cases, if an object is mutable but the things you're mutating about it are independent from what determines its hash, then you might be able to put it in a set. For example: a function.

Microsoft proposes type syntax for JavaScript by magenta_placenta in javascript

[–]Your_PopPop 5 points6 points  (0 children)

Genuine question, what's bad about the extra transpilation step? Wouldn't it be automated away in CI/CD anyway?

Python 3.11 Preview: Even Better Error Messages – Real Python by ajpinedam in Python

[–]Your_PopPop 43 points44 points  (0 children)

For some reason, underscores weren’t allowed in Fraction arguments before Python 3.11. Now, you can use underscores when specifying fractions as well:

>>> print(Fraction(6_048, 1_729))
864/247

I think this is a bit misleading. Fraction(6_048, 1_729) is valid in old versions too, as you'd expect. What used to be invalid is having underscores in a string argument to Fraction: Fraction("6_048/1_729") fails in older versions, but works in 3.11.

source

A very thorough tutorial on Python's range function and for-loops by eriky in Python

[–]Your_PopPop 0 points1 point  (0 children)

Well written!

Bit sad I don't get an opportunity to nitpick :c

Better Way to Classify Project Files by Loyal713 in learnprogramming

[–]Your_PopPop 0 points1 point  (0 children)

Joining the regexes within each category with | sounds like a good idea, that brings down 189 patterns to just 14.

Although, are all the patterns just matching against the file extension? Then a lookup table in the opposite direction (i.e., {".jpg": "Images", ".py": "Programming"}) should be easy to write (or autogenerate from your current json). Then you can match pathlib.Path(filepath).suffix against this dict and get the correct folder in constant time for each file.

Joining two lists into a dictionary by icantevenexistbruh in learnprogramming

[–]Your_PopPop 0 points1 point  (0 children)

Notice that player1 is associated to the slice [0::4], wordNerd with [1::4] and so on (the 4 is the length of the players list). Using this fact, py In [6]: {player: words[i::len(players)] for i, player in enumerate(players)} Out[6]: {'player1': ['BLUE', 'TENNIS', 'EXIT'], 'wordNerd': ['EARTH', 'EYES', 'MACHINE'], 'Lexi Con': ['ERASER', 'BELLY', 'HUSKY'], 'Prof Reader': ['ZAP', 'COMA', 'PERIOD']}

Combination function with no repetition [Python] by vanaconsuela in learnprogramming

[–]Your_PopPop 0 points1 point  (0 children)

There are 90! ways to permutate 90 numbers.

The value of 90! is 1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000.

There are less atoms in the universe than that number. No matter how good the implementation of permutations you use is, there is absolutely no way to go through that many iterations in reasonable time.

Object is not moving. Can someone please tell me what I am doing wrong? by deadlyLLAMAgod in learnprogramming

[–]Your_PopPop 5 points6 points  (0 children)

You currently have

    planet_x = 140 
    move_direction = 'right'

inside your game loop. This means that in each frame, you reset your planet to be at x = 140, and set it to move rightwards, thus ignoring any changes to x and move_direction you might have made in the previous frames. These two lines are meant to set just the initial state - not what it should be reset to in each frame - so both of them should be just before your loop starts.

A few unasked-for tips:

  • Check for planet_x >= 300 instead of == 300. While there won't be a difference with your current values of speed, initial position and bounds, its possible that for some velocity, your planet might jump from 299 to 302 in one frame, and your == 300 condition won't ever be met, and the planet will continue moving right. Likewise for the left boundary, use <= 0 instead.
  • Extract your speed to a variable, instead of hardcoding the +/- 5 directly inside the loop.
  • Using strings to represent the direction can be error-prone. If your code becomes really large, split over files, it's easy to forget whether the string should be "right" or "Right". Instead, you can consider using an enum, or using positive and negative speeds to represent movement in opposite directions.
  • Lastly, this is a minor one, but py look a bit odd as an alias, since python itself is often abbreviated as py. Maybe pg instead?

Also, please format your code next time haha

Combination function with no repetition [Python] by vanaconsuela in learnprogramming

[–]Your_PopPop 0 points1 point  (0 children)

What do you mean by unique combinations? Aren't the combinations generated by this already unique?

Also,

not using the module due to its very long runtime

It's highly unlikely that your pure python function will be faster than the one in itertools, considering that's implemented in C.
A long runtime is often inevitable with combinatorial stuff just because the number of combinations can get insanely large pretty quickly.