mirror of
https://github.com/jbranchaud/til
synced 2026-09-02 09:41:47 +00:00
Compare commits
2
Commits
a126b13d7c
...
12180acb02
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12180acb02 | ||
|
|
8f722061b4 |
@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
|
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
|
||||||
|
|
||||||
_1806 TILs and counting..._
|
_1808 TILs and counting..._
|
||||||
|
|
||||||
See some of the other learning resources I work on:
|
See some of the other learning resources I work on:
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
|||||||
* [Linux](#linux)
|
* [Linux](#linux)
|
||||||
* [LLM](#llm)
|
* [LLM](#llm)
|
||||||
* [Mac](#mac)
|
* [Mac](#mac)
|
||||||
|
* [Math](#math)
|
||||||
* [Mise](#mise)
|
* [Mise](#mise)
|
||||||
* [MongoDB](#mongodb)
|
* [MongoDB](#mongodb)
|
||||||
* [MySQL](#mysql)
|
* [MySQL](#mysql)
|
||||||
@@ -771,6 +772,10 @@ If you've learned something here, support my efforts writing daily TILs by
|
|||||||
- [View All Windows Of The Current App](mac/view-all-windows-of-the-current-app.md)
|
- [View All Windows Of The Current App](mac/view-all-windows-of-the-current-app.md)
|
||||||
- [Write System Clipboard To A File](mac/write-system-clipboard-to-a-file.md)
|
- [Write System Clipboard To A File](mac/write-system-clipboard-to-a-file.md)
|
||||||
|
|
||||||
|
### Math
|
||||||
|
|
||||||
|
- [Generate Permutations Of All Valid 9-ball Racks](math/generate-permutations-of-all-valid-9-ball-racks.md)
|
||||||
|
|
||||||
### Mise
|
### Mise
|
||||||
|
|
||||||
- [Create Umbrella Task For All Test Tasks](mise/create-umbrella-task-for-all-test-tasks.md)
|
- [Create Umbrella Task For All Test Tasks](mise/create-umbrella-task-for-all-test-tasks.md)
|
||||||
@@ -1072,6 +1077,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
|||||||
- [Define Typed Class Interface With Protocol](python/define-typed-class-interface-with-protocol.md)
|
- [Define Typed Class Interface With Protocol](python/define-typed-class-interface-with-protocol.md)
|
||||||
- [Dunder Methods](python/dunder-methods.md)
|
- [Dunder Methods](python/dunder-methods.md)
|
||||||
- [Easy Key-Value Aggregates With defaultdict](python/easy-key-value-aggregates-with-defaultdict.md)
|
- [Easy Key-Value Aggregates With defaultdict](python/easy-key-value-aggregates-with-defaultdict.md)
|
||||||
|
- [Enable Pyright Type Checking In Cursor](python/enable-pyright-type-checking-in-cursor.md)
|
||||||
- [Get Absolute Seconds From `timedelta` Object](python/get-absolute-seconds-from-timedelta-object.md)
|
- [Get Absolute Seconds From `timedelta` Object](python/get-absolute-seconds-from-timedelta-object.md)
|
||||||
- [Get Quotient And Remainder In One Operation](python/get-quotient-and-remainder-in-one-operation.md)
|
- [Get Quotient And Remainder In One Operation](python/get-quotient-and-remainder-in-one-operation.md)
|
||||||
- [Install With PIP For Specific Interpreter](python/install-with-pip-for-specific-interpreter.md)
|
- [Install With PIP For Specific Interpreter](python/install-with-pip-for-specific-interpreter.md)
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# Generate Permutations Of All Valid 9-ball Racks
|
||||||
|
|
||||||
|
I wanted to produce a full listing of all valid rack arrangements for the game
|
||||||
|
of [9-ball](https://en.wikipedia.org/wiki/Nine-ball). The constraints on how a
|
||||||
|
9-ball rack can be arranged are, first, that the 1 ball must be placed at the
|
||||||
|
head of the diamond and, second, that the 9 ball must be placed at the center of
|
||||||
|
the diamond. After that, all other balls (2 through 8) can be placed in any
|
||||||
|
arrangement.
|
||||||
|
|
||||||
|
Because each of those seven remaining balls can be arranged in distinct
|
||||||
|
orderings where each ball is placed once, this is a
|
||||||
|
[_permutation_](https://en.wikipedia.org/wiki/Permutation) problem.
|
||||||
|
|
||||||
|
> In elementary combinatorics, the k-permutations, or partial permutations, are
|
||||||
|
> the ordered arrangements of k distinct elements selected from a set. When k is
|
||||||
|
> equal to the size of the set, these are the permutations in the previous
|
||||||
|
> sense.
|
||||||
|
|
||||||
|
For this problem, the seven distinct elements can be arranged into `7!` (seven
|
||||||
|
factorial) unique permutations. That is, 5040 permutations.
|
||||||
|
|
||||||
|
I can use [Ruby's `Array#permutations`
|
||||||
|
method](https://docs.ruby-lang.org/en/4.0/Array.html#method-i-permutation) to
|
||||||
|
enumerate these 5040 permutations like so:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
[2,3,4,5,6,7,8].permutation.map do |perm|
|
||||||
|
[1, *perm[0..2], 9, *perm[3..7]]
|
||||||
|
end.to_a
|
||||||
|
=> [[1, 2, 3, 4, 9, 5, 6, 7, 8],
|
||||||
|
[1, 2, 3, 4, 9, 5, 6, 8, 7],
|
||||||
|
[1, 2, 3, 4, 9, 5, 7, 6, 8],
|
||||||
|
[1, 2, 3, 4, 9, 5, 7, 8, 6],
|
||||||
|
[1, 2, 3, 4, 9, 5, 8, 6, 7],
|
||||||
|
[1, 2, 3, 4, 9, 5, 8, 7, 6],
|
||||||
|
[1, 2, 3, 4, 9, 6, 5, 7, 8],
|
||||||
|
...
|
||||||
|
[1, 8, 7, 6, 9, 5, 3, 2, 4],
|
||||||
|
[1, 8, 7, 6, 9, 5, 3, 4, 2],
|
||||||
|
[1, 8, 7, 6, 9, 5, 4, 2, 3],
|
||||||
|
[1, 8, 7, 6, 9, 5, 4, 3, 2]]
|
||||||
|
```
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Enable Pyright Type Checking In Cursor
|
||||||
|
|
||||||
|
In most ways [Cursor](https://cursor.com/), a clone of VS Code, behaves like VS
|
||||||
|
Code and uses the same extensions as VS Code. It even offers to clone all your
|
||||||
|
existing extensions and setup from VS Code when you first install it.
|
||||||
|
|
||||||
|
However, the Pyright type checking setup that I had in VS Code stopped working
|
||||||
|
when I opened up the same Python project in Cursor. It seems that to get Pyright
|
||||||
|
to reliably work with forks of VS Code, you need to use a compatible fork like
|
||||||
|
[Based Pyright](https://docs.basedpyright.com/latest/).
|
||||||
|
|
||||||
|
Once I installed _Based Pyright_ from the extension marketplace, I was able to
|
||||||
|
enable it in `.vscode/settings.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
...,
|
||||||
|
"basedpyright.analysis.typeCheckingMode": "basic"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
I may have needed to restart Cursor at this point, I cannot remember exactly.
|
||||||
|
However, once this setup was in place the helpful type checking errors started
|
||||||
|
appearing as red squiggles.
|
||||||
Reference in New Issue
Block a user