More combination-related notes and PIE.
parent
27adc88529
commit
8d6978c429
|
@ -128,11 +128,11 @@
|
|||
"algorithms/sorting/selection-sort.md": "fcd0dc2ebaabd0a4db1baf7e7ef9f7a9",
|
||||
"algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97",
|
||||
"binary/hexadecimal.md": "c3d485f1fd869fe600334ecbef7d5d70",
|
||||
"binary/index.md": "b4db8fe8ae874a682a5acf81271e303b",
|
||||
"binary/index.md": "ab345e75dc01f890faa31bc26676d526",
|
||||
"_journal/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109",
|
||||
"c/types.md": "cf3e66e5aee58a94db3fdf0783908555",
|
||||
"logic/quantification.md": "5d7579a511e9ff683edeec62bcc291b8",
|
||||
"c/declarations.md": "d2e7dcb5bbf6644651f4f25503b165e1",
|
||||
"c/declarations.md": "7b0277d89b83fb330970deeb37e664c4",
|
||||
"algorithms/sorting/bubble-sort.md": "16dad1016dc6555163e42ba20f1d152d",
|
||||
"_journal/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
|
||||
"_journal/2024-01/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970",
|
||||
|
@ -153,13 +153,13 @@
|
|||
"_journal/2024-02/2024-02-11.md": "afee9f502b61e17de231cf2f824fbb32",
|
||||
"encoding/ascii.md": "c01e50f96d0493d94dc4d520c0b6bb71",
|
||||
"encoding/index.md": "071cfa6a5152efeda127b684f420d438",
|
||||
"c/strings.md": "813aa7b27c4d9e75b9076681726e11ee",
|
||||
"c/strings.md": "d3a5405f5d5237ee169a8894ff4e21ab",
|
||||
"logic/truth-tables.md": "7892ceaa416c9a65acc79ca1e6ff778f",
|
||||
"logic/short-circuit.md": "26d300f407f14883022d0ef8dc4f7300",
|
||||
"logic/boolean-algebra.md": "f9101b2dfdedb73dc13c34c1a70a0010",
|
||||
"_journal/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0",
|
||||
"_journal/2024-02/2024-02-12.md": "618c0035a69b48227119379236a02f44",
|
||||
"binary/shifts.md": "146ee4898faa13b26f00a31024020c2e",
|
||||
"binary/shifts.md": "c7fb2a5722a69bb23047b603edcd0b91",
|
||||
"_journal/2024-02-14.md": "76d1b607470305fb3f00a47b8e9ece27",
|
||||
"_journal/2024-02/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0",
|
||||
"_journal/2024-02-15.md": "575ba46d692795d9606de9e635d1f4ac",
|
||||
|
@ -180,7 +180,10 @@
|
|||
"_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
|
||||
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
|
||||
"combinatorics/permutations.md": "3c76f548e22f7271280b9ed82ae584ec",
|
||||
"combinatorics/combinations.md": "8957575cef86f05918a47fcb5bc5f8c1"
|
||||
"combinatorics/combinations.md": "c00ae174e8a172be1c3f89c231a2dd03",
|
||||
"_journal/2024-02-20.md": "4e6ff95c5c3163fb909f37c078759b13",
|
||||
"_journal/2024-02/2024-02-19.md": "df1a9ab7ab89244021b3003c84640c78",
|
||||
"combinatorics/inclusion-exclusion.md": "0c63d52507b87cf276615715977218cb"
|
||||
},
|
||||
"fields_dict": {
|
||||
"Basic": [
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
title: "2024-02-20"
|
||||
---
|
||||
|
||||
- [x] Anki Flashcards
|
||||
- [x] KoL
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [x] OGS (1 Life & Death Problem)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
- [ ] Interview Prep (1 Practice Problem)
|
||||
- [ ] Log Work Hours (Max 3 hours)
|
||||
|
||||
* Added `printf` `length` field notes.
|
||||
* 101weiqi (serial numbers)
|
||||
* Q-138432
|
||||
* Q-266721
|
||||
* Q-110886
|
||||
* Q-267289
|
||||
* Q-275961
|
||||
* Q-324650
|
||||
* Q-83832
|
|
@ -4,7 +4,7 @@ title: "2024-02-19"
|
|||
|
||||
- [x] Anki Flashcards
|
||||
- [x] KoL
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [x] Sheet Music (10 min.)
|
||||
- [ ] OGS (1 Life & Death Problem)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
- [ ] Interview Prep (1 Practice Problem)
|
|
@ -8,7 +8,7 @@ tags:
|
|||
|
||||
## Overview
|
||||
|
||||
A binary digit or **bit** is a `0` or `1` character. A bit string is then a contiguous sequence of bits. It's **weight** is a reference to the number of `1`s in the bit string. Compare the below operation to the method for converting from one numerical base to another (e.g. [[hexadecimal]]).
|
||||
A binary digit or **bit** is a `0` or `1` character. A **bit string** is then a contiguous sequence of bits. It's **weight** is a reference to the number of `1`s in the bit string. Compare the below operation to the method for converting from one numerical base to another (e.g. [[hexadecimal]]).
|
||||
|
||||
```c
|
||||
unsigned int bit_weight(int64_t n) {
|
||||
|
|
|
@ -105,7 +105,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
How is $x \bmod 2^k$ equivalently written as a bit mask?
|
||||
Back: `x & (k - 1)`
|
||||
Back: `x & ((1 << k) - 1)`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c
|
||||
<!--ID: 1707873410780-->
|
||||
|
|
|
@ -8,15 +8,17 @@ tags:
|
|||
|
||||
## Overview
|
||||
|
||||
Signed | Unsigned | 32-bit | 64-bit
|
||||
----------- | -------------- | ------ | ------
|
||||
signed char | unsigned char | 1 | 1
|
||||
short | unsigned short | 2 | 2
|
||||
int | unsigned | 4 | 4
|
||||
long | unsigned long | 4 | 8
|
||||
char * | - | 4 | 8
|
||||
float | - | 4 | 4
|
||||
double | - | 8 | 8
|
||||
Signed | Unsigned | 32-bit | 64-bit
|
||||
----------- | ------------------- | ------ | ------
|
||||
signed char | unsigned char | 1 | 1
|
||||
short | unsigned short | 2 | 2
|
||||
int | unsigned | 4 | 4
|
||||
long | unsigned long | 4 | 8
|
||||
long long | unsigned long long | 8 | 8
|
||||
char * | - | 4 | 8
|
||||
float | - | 4 | 4
|
||||
double | - | 8 | 8
|
||||
|
||||
Fixed width data integral types (e.g. `int32_t`) can be found by including `<stdint.h>`.
|
||||
|
||||
%%ANKI
|
||||
|
@ -103,6 +105,29 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1707493017222-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
`long long` *typically* represents {8} bytes(s) on a 64-bit platform.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708425521263-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What distinguishes `long` from `long long`?
|
||||
Back: `long long`s are guaranteed to be at least 64-bit wide.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708425521292-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*Why* is there both a `long` and `long long`?
|
||||
Back: `long long`s are at least 64-bit wide, even on 32-bit platforms.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708425521296-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
`char *` *typically* represents {8} bytes(s) on a 64-bit platform.
|
||||
|
@ -182,4 +207,4 @@ END%%
|
|||
|
||||
## References
|
||||
|
||||
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
|
|
|
@ -61,6 +61,13 @@ Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia
|
|||
<!--ID: 1708384441472-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`width` and `precision`} fields are output related whereas the {`length`} field is input related.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
<!--ID: 1708425941269-->
|
||||
END%%
|
||||
|
||||
Flag | Description
|
||||
--------- | -----------
|
||||
`-` | Left-aligns the output
|
||||
|
@ -232,6 +239,57 @@ Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia
|
|||
<!--ID: 1707918756888-->
|
||||
END%%
|
||||
|
||||
Length | Description
|
||||
--------- | -----------
|
||||
`hh` | `int` sized integer argument promoted from a `char`
|
||||
`h` | `int` sized integer argument promoted from a `short`
|
||||
`l` | `long` sized integer argument
|
||||
`ll` | `long long` sized integer argument
|
||||
`z` | `size_t` sized integer argument
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
*Why* do length modifiers for e.g. `char` exist?
|
||||
Back: For maximum portability in the face of default argument promotions.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
<!--ID: 1708426673637-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`hh`} length corresponds to the {`char`} type declaration.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
<!--ID: 1708426673664-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`h`} length corresponds to the {`short`} type declaration.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
<!--ID: 1708426673668-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`l`} length corresponds to the {`long`} type declaration.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
<!--ID: 1708426673711-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`ll`} length corresponds to the {`long long`} type declaration.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
<!--ID: 1708426673719-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`z`} length corresponds to the {`size_t`} type declaration.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
<!--ID: 1708426673725-->
|
||||
END%%
|
||||
|
||||
Specifier | Description
|
||||
--------- | -----------
|
||||
`d`, `i` | a decimal `signed int`
|
||||
|
@ -263,7 +321,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`d` and `i`} format specifers work on a {decimal `signed int`}.
|
||||
The {`%d` and `%i`} format specifers work on a {decimal `signed int`}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083040-->
|
||||
|
@ -271,7 +329,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
{`d` and `i`} are to `signed` as {`u`} is to `unsigned`.
|
||||
{`%d` and `%i`} are to `signed` as {`%u`} is to `unsigned`.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083044-->
|
||||
|
@ -279,7 +337,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`u`} format specifier outputs a {decimal `unsigned int`}.
|
||||
The {`%u`} format specifier outputs a {decimal `unsigned int`}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083047-->
|
||||
|
@ -287,7 +345,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What distinguishes format specifiers `d` and `i`?
|
||||
What distinguishes format specifiers `%d` and `%i`?
|
||||
Back: Nothing.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
|
@ -297,7 +355,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which format specifiers were probably used to yield `printf` output `-12`?
|
||||
Back: `d` or `i`
|
||||
Back: `%d` or `%i`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083054-->
|
||||
|
@ -305,7 +363,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What distinguishes format specifiers `d` and `u`?
|
||||
What distinguishes format specifiers `%d` and `%u`?
|
||||
Back: The former is for signed integers, the latter unsigned.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
|
@ -314,7 +372,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`x`} format specifier outputs a {lowercase hexadecimal `unsigned int`}.
|
||||
The {`%x`} format specifier outputs a {lowercase hexadecimal `unsigned int`}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083063-->
|
||||
|
@ -323,7 +381,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which format specifier were probably used to yield `printf` output `7af`?
|
||||
Back: `x`
|
||||
Back: `%x`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083068-->
|
||||
|
@ -331,7 +389,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`X`} format specifier outputs an {uppercase hexadecimal `unsigned int`}.
|
||||
The {`%X`} format specifier outputs an {uppercase hexadecimal `unsigned int`}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083074-->
|
||||
|
@ -340,7 +398,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which format specifier were probably used to yield `printf` output `7AF`?
|
||||
Back: `X`
|
||||
Back: `%X`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083080-->
|
||||
|
@ -348,7 +406,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What distinguishes format specifiers `x` and `X`?
|
||||
What distinguishes format specifiers `%x` and `%X`?
|
||||
Back: The former outputs lowercase hex digits, the latter uppercase.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
|
@ -357,7 +415,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`o`} format specifier outputs an {octal `unsigned int`}.
|
||||
The {`%o`} format specifier outputs an {octal `unsigned int`}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083091-->
|
||||
|
@ -365,7 +423,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
Why doesn't the `o` format specifier have a corresponding `O` specifier?
|
||||
Why doesn't the `%o` format specifier have a corresponding `%O` specifier?
|
||||
Back: There is no distinction between lower and uppercase octal digits.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
|
@ -374,7 +432,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`s`} format specifiers outputs a {`NUL`-terminated string}.
|
||||
The {`%s`} format specifiers outputs a {`NUL`-terminated string}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083100-->
|
||||
|
@ -383,7 +441,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which format specifier was probably used to yield `printf` output `abc`?
|
||||
Back: `s`
|
||||
Back: `%s`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083105-->
|
||||
|
@ -391,7 +449,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`c`} format specifier outputs a {`char` character}.
|
||||
The {`%c`} format specifier outputs a {`char` character}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083109-->
|
||||
|
@ -400,7 +458,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which format specifier was probably used to yield `printf` output `a`?
|
||||
Back: `c`
|
||||
Back: `%c`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083113-->
|
||||
|
@ -408,7 +466,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Cloze
|
||||
The {`p`} format specifier outputs a {`void*` address}.
|
||||
The {`%p`} format specifier outputs a {`void*` address}.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083117-->
|
||||
|
@ -417,7 +475,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which format specifier was probably used to yield `printf` output `0b80000000`?
|
||||
Back: `p`
|
||||
Back: `%p`
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
<!--ID: 1707852083121-->
|
||||
|
@ -425,7 +483,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is the address outputted by the `p` format specifier written?
|
||||
How is the address outputted by the `%p` format specifier written?
|
||||
Back: In an implementation-specific way.
|
||||
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
|
||||
Tags: printf
|
||||
|
|
|
@ -238,9 +238,77 @@ Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n
|
|||
<!--ID: 1708384441423-->
|
||||
END%%
|
||||
|
||||
## Bit Strings
|
||||
|
||||
A [[binary/index|bit string]] can be used to represent subsets of some finite set. A `1` value usually corresponds to inclusion in a subset, whereas a `0` value corresponds to exclusion. Thus, given set e.g. $A = \{1, 2, 3, 4\}$, $0110_2$ would correspond to subset $\{2, 3\}$.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given $A = \{1, 2, 3, 4\}$, what subset does $1010_2$ correspond to?
|
||||
Back: $\{1, 3\}$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662140-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
Representing subsets with bit strings, {$0000_2$} maps to {$\varnothing$} $\subseteq \{1, 2, 3, 4\}$.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662148-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
Representing subsets with bit strings, {$1111_2$} maps to {$\{1, 2, 3, 4\}$} $\subseteq \{1, 2, 3, 4\}$.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662151-->
|
||||
END%%
|
||||
|
||||
Bit strings also make it clear that the number of subsets with even cardinality must be equal to the number of subsets with odd cardinality. Hence, $$\binom{n}{0} - \binom{n}{1} + \cdots + (-1)^n \binom{n}{n} = 0$$
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does $\sum_{k=0}^n (-1)^k \binom{n}{k}$ evaluate to?
|
||||
Back: $0$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662154-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What does expression $\sum_{k=0}^n (-1)^k \binom{n}{k} = 0$ indicate about sets?
|
||||
Back: There is an equal number of even-sized subsets as odd-sized subsets.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662157-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What isomorphism shows finite sets have an equal number of even-sized subsets as odd-sized subsets?
|
||||
Back: The one-to-one relationship between subsets and bit strings.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662160-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given finite set $A$, how many subsets of even cardinality does $A$ have?
|
||||
Back: Let $n = |A|$. Then $2^{n-1}$.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662163-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given finite set $A$, how many subsets of odd cardinality does $A$ have?
|
||||
Back: Let $n = |A|$. Then $2^{n-1}$.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708434662166-->
|
||||
END%%
|
||||
|
||||
## Lattice Paths
|
||||
|
||||
A **lattice path** is one of the shorted possible paths connecting two points on a lattice, moving only horizontally and vertically. By representing each horizontal move by "1" and each vertical move by "0", we see every lattice path has a corresponding bit string.
|
||||
A **lattice path** is one of the shorted possible paths connecting two points on a lattice, moving only horizontally and vertically. By representing each horizontal move by `1` and each vertical move by `1`, we see every lattice path has a corresponding [[#Bit Strings|bit string]].
|
||||
|
||||
![[lattice-path-example.png]]
|
||||
|
||||
|
@ -330,9 +398,9 @@ Back:
|
|||
<!--ID: 1708384441446-->
|
||||
END%%
|
||||
|
||||
## Binomials
|
||||
## Binomial Coefficients
|
||||
|
||||
A **binomial** is a polynomial containing two terms. Consider $(x + y)^n$.
|
||||
A **binomial** is a polynomial containing two terms. Consider $(x + y)^n$. We see that term $x^ky^{n-k}$ maps to *some* bit string containing $k$ `1`s and $n - k$ `0`s. This might feel more obvious when expanding to $x \cdot x \cdots x \cdot y \cdots y$. Since multiplication is commutative, the number of matching "bit strings" is the same as $\binom{n}{k}$.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
---
|
||||
title: Principle of Inclusion/Exclusion
|
||||
TARGET DECK: Obsidian::STEM
|
||||
FILE TAGS: combinatorics set
|
||||
tags:
|
||||
- combinatorics
|
||||
- set
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The **principle of inclusion/exclusion** refers to the oscillating adding and subtracting used to find the cardinality of potentially overlapping sets. Consider sets $A$, $B$, and $C$. Then
|
||||
|
||||
$$|A \cup B| = |A| + |B| - |AB|$$
|
||||
|
||||
and
|
||||
|
||||
$$|A \cup B \cup C| = |A| + |B| + |C| - |AB| - |AC| - |BC| + |ABC|$$
|
||||
|
||||
Notice the number of terms containing one set, two sets, three sets, etc. match the [[combinations#Binomial Coefficients|binomial coefficients]].
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given finite sets $A$ and $B$ and using PIE, what is $|A \cup B|$?
|
||||
Back: $|AB| = |A| + |B| - |AB|$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356466-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given finite sets $A$ and $B$, what combinatorial concept is used to find $|A \cup B|$?
|
||||
Back: The principle of inclusion/exclusion.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356471-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Why is the principle of inclusion/exclusion named the way it is?
|
||||
Back: Because it involves an alternating adding and subtracting of terms.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356474-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What concept does PIE typically refer to?
|
||||
Back: The **p**rinciple of **i**nclusion/**e**xclusion.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356477-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given finite sets $A$ and $B$, what is $|A \cup B \cup C|$?
|
||||
Back: $|A| + |B| + |C| - |AB| - |AC| - |BC| + |ABC|$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356480-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Using sigma notation, what identity is used to prove PIE correctly counts members?
|
||||
Back: $\sum_{k=0}^n (-1)^k \binom{n}{k} = 0$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356483-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Why might PIE be considered a top-down approach to counting?
|
||||
Back: It starts by counting every member of each union operand.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356486-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the bottom-up approach contrasting PIE?
|
||||
Back: Apply the additive property to all disjoint sets the union operands can make.
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356490-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Given finite sets $A$ and $B$ and using a bottom-up approach (i.e. *not* PIE), what is $|A \cup B|$?
|
||||
Back: $|A \cup B| = |AB| + |A - AB| + |B - AB|$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708438356493-->
|
||||
END%%
|
||||
|
||||
## References
|
||||
|
||||
* Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
Loading…
Reference in New Issue