Compare commits

...

2 Commits

Author SHA1 Message Date
tomatocream ab80017903 feat: add iterator flashcards, sync script, and project scaffolding
- iterator.org: C++ iterator flashcard deck
- questions.org: LeetCode question index (217, 242)
- inbox.org: learning inbox with two-sum implementation and notes
- sync-anki.sh: batch sync org files to Anki via emacsclient
- AGENTS.md: conventions for AI agents working in this repo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 00:48:31 +08:00
tomatocream a8715e9850 docs: add org-mode syntax reference flashcards 2026-04-20 21:52:51 +08:00
6 changed files with 541 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
# Agents
## Repo Purpose
C++ flashcard notes using org-mode (exportable to Anki).
## Flashcard Location
- `org/cpp/` — all flashcard `.org` files live here
- Create new `.org` files here as needed (e.g., `org/cpp/containers.org`)
## Task Inbox
- `inbox.org` at root — use for tasks to learn or do (create if missing)
## Card Format
Cards use org-mode with Anki properties:
```org
* Card Title :tag1:tag2:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: TIMESTAMP
:END:
** Front
Question text
** Back
#+begin_src c++
code
#+end_src
```
## Assets
- `images/` — store any images referenced by cards
## Self-Improvement
Periodically review this file and suggest improvements to the user if you notice gaps, inconsistencies, or missing conventions.
+59
View File
@@ -0,0 +1,59 @@
#+title: Inbox
* 1. two sum
#+begin_src c++
class Solution {
public:
vector<int> twoSum(vector<int> &nums, int target) {
vector<pair<int, int>> rev;
// Fix 1 & 2: Loop over nums.size() and push nums[i]
for (int i = 0; i < nums.size(); i++) {
rev.push_back({nums[i], i});
}
std::sort(rev.begin(), rev.end());
for (int i = 0; i < rev.size(); i++) {
int want = target - rev[i].first;
// Fix 3: Pass the SORTED vector 'rev' to the search
int j = bs(rev, want, i + 1);
if (j >= 0) {
int a = rev[i].second;
int b = rev[j].second;
return vector<int>{min(a, b), max(a, b)};
}
}
return {};
}
// Updated to handle vector of pairs
using PairIter = vector<pair<int, int>>::iterator;
PairIter lower_bound(PairIter l, PairIter r, int target) {
while (l < r) {
PairIter mid = l + (r - l) / 2;
if (mid->first >= target) { // Access value via .first or ->first
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
int bs(vector<pair<int, int>> &indexedNums, int target, int offset) {
auto it =
lower_bound(indexedNums.begin() + offset, indexedNums.end(), target);
if (it == indexedNums.end() || it->first != target) {
return -1;
}
return it - indexedNums.begin();
}
};
#+end_src
~using PairIter = vector<pair<int, int>>::iterator;~
what is using?
we need to write binary search, lower bound search
learn about binary search functions the natural one by god
+116
View File
@@ -0,0 +1,116 @@
* What is a C++ iterator :cpp:iterator:concept:recognition:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491263
:END:
** Front
What is an iterator in C++?
** Back
An object that points to elements in a container and allows traversal through them, providing a common interface for accessing elements sequentially without exposing the underlying structure.
* Task: Traverse a vector with iterators :cpp:iterator:production:code:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491259
:END:
** Front
Write C++ code to iterate through a std::vector<int> using iterators
** Back
#+begin_src c++
std::vector<int> vec = {1, 2, 3};
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
#+end_src
* Iterator operations :cpp:iterator:concept:enumeration:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491255
:END:
** Front
What are the four required operations for a C++ iterator?
** Back
- `operator*` — dereference to get current element
- `operator++` — advance to next element (pre and post)
- `operator==` — equality comparison
- `operator!=` — inequality comparison
* cpp iterator categories :cpp:iterator:concept:enumeration:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491250
:END:
** Front
List the five iterator categories in C++ (from simplest to most advanced)
** Back
1. Input Iterator — read values, advance once
2. Output Iterator — write values, advance once
3. Forward Iterator — read/write, multiple passes
4. Bidirectional Iterator — + operator--
5. Random Access Iterator — + arithmetic, subscript
* Task: Use const iterator :cpp:iterator:production:code:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491246
:END:
** Front
Write C++ code to safely traverse a const std::vector without modifying elements
** Back
#+begin_src c++
std::vector<int> vec = {1, 2, 3};
for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
std::cout << *it << " ";
}
#+end_src
* Task: Use reverse iterator :cpp:iterator:production:code:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491241
:END:
** Front
Write C++ code to iterate backwards through a std::vector
** Back
#+begin_src c++
std::vector<int> vec = {1, 2, 3};
for (auto it = vec.rbegin(); it != vec.rend(); ++it) {
std::cout << *it << " ";
}
#+end_src
* Minimal custom iterator implementation :cpp:iterator:implementation:production:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491237
:END:
** Front
Write the minimal C++ code to implement a forward iterator for a custom class
** Back
#+begin_src c++
class MyIterator {
Node* ptr;
public:
reference operator*() const { return ptr->data; }
pointer operator->() const { return &ptr->data; }
MyIterator& operator++() { ptr = ptr->next; return *this; }
MyIterator operator++(int) { auto tmp = *this; ++*this; return tmp; }
bool operator==(const MyIterator& other) const { return ptr == other.ptr; }
bool operator!=(const MyIterator& other) const { return !(*this == other); }
};
#+end_src
* When to use iterators vs indices :cpp:iterator:concept:comparison:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1776621491226
:END:
** Front
When would you choose iterators over index-based loops in C++?
** Back
- Container type is unknown or could change (iterators abstract the container)
- Using standard library algorithms (std::find, std::sort, etc.)
- Need to traverse multiple containers simultaneously
- Working with containers without random access (list, map)
- Decouple algorithm from container structure
+3
View File
@@ -0,0 +1,3 @@
#+title: Questions
* 217
* 242 valid anagrams
+309
View File
@@ -0,0 +1,309 @@
# Org-Mode Syntax Reference
This document covers org-mode syntax for creating flashcards.
* Headlines
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you create headlines in org-mode?
** Back
=* Heading 1= (one asterisk)
=** Heading 2= (two asterisks)
=*** Heading 3= (etc.)
#+begin_src org
* Top Level
** Second Level
*** Third Level
#+end_src
* Emphasis
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you bold, italic, and code in org-mode?
** Back
=*bold*= :: *bold*
=/italic /= :: /italic/
=~code~= :: ~code~ (inline code, like backticks)
==verbatim== :: =verbatim= (literal text)
=_underline_= :: _underline_
* Code Blocks
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you write a source code block in org-mode?
** Back
#+begin_src org
#+begin_src cpp
std::vector<int> v;
#+end_src
#+end_src
Supported languages: =cpp=, =c=, =python=, =bash=, =javascript=, =sql=, =json=, =html=, =css=, =rust=, =go=, etc.
* Links
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you write links in org-mode?
** Back
#+begin_src org
[[https://example.com][Description]]
[[https://example.com]] (auto-named)
[[file:path/to/file.org][Local file]]
#+end_src
* External Links
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you link to external URLs in org-mode?
** Back
Plain URL or with description:
#+begin_src org
https://example.com
[[https://example.com][Example Site]]
#+end_src
* Lists
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you write bullet and numbered lists in org-mode?
** Back
#+begin_src org
- Bullet item
- Another item
- Sub-item (indent with spaces)
1. Numbered item
2. Second item
- [ ] Unchecked task
- [X] Checked task
#+end_src
* Properties Drawer
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you add properties to a flashcard heading?
** Back
#+begin_src org
* Card Title :tag1:tag2:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:ANKI_NOTE_ID: 1234567890
:END:
** Front
Question
** Back
Answer
#+end_src
Properties drawer goes directly after the heading, before Front.
* Tags
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you add tags to a headline?
** Back
Tags go after the heading, separated by colons:
#+begin_src org
* My Card :cpp:containers:stl:
#+end_src
Tags can be inherited by subheadings.
* Flashcard Structure
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
What is the complete structure of an org-mode flashcard?
** Back
#+begin_src org
* Question/Title :tag:
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
The question or prompt
** Back
The answer (often includes source blocks)
#+begin_src cpp
code here
#+end_src
#+end_src
* Export Blocks
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you create a block that exports to a specific format?
** Back
#+begin_src org
#+begin_export html
HTML content here
#+end_export
#+begin_export latex
LaTeX content here
#+end_export
#+end_src
* Comments
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you add comments in org-mode?
** Back
#+begin_src org
#+COMMENT: This entire line is a comment
# Also a comment (headline-level)
#+end_src
* Block Quotes
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you create a block quote in org-mode?
** Back
#+begin_src org
#+begin_quote
Your quote text here.
It can span multiple lines.
#+end_quote
#+end_src
* Example Blocks
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you create an example block (literal text)?
** Back
#+begin_src org
#+begin_example
This text is literal - no emphasis processing.
*not bold*
#+end_example
#+end_src
* Horizontal Rules
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you create a horizontal rule in org-mode?
** Back
Five or more dashes:
#+begin_src org
-----
#+end_src
* Tables
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you create a table in org-mode?
** Back
#+begin_src org
| Header 1 | Header 2 |
|----------+----------|
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
#+end_src
Tables need at least one dash in the separator row.
* footnotes
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you add footnotes in org-mode?
** Back
#+begin_src org
Some text with a footnote[fn:1]
[fn:1] This is the footnote content.
#+end_src
* Special Symbols
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you insert special symbols in org-mode?
** Back
Using org-entities:
#+begin_src org
\alpha → \alpha
\beta → \beta
\sum → \sum
\pm → \pm
\rightarrow → \rightarrow
#+end_src
Also works: =\egal= (𝑎𝑏𝑐), =~abc~= (code)
* Todo States
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you mark a headline as a todo item?
** Back
#+begin_src org
TODO Some task
DONE Completed task
#+end_src
Common states: =TODO=, =DONE=, =NEXT=, =WAITING=, =CANCELLED=
* Radio Targets
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
What is a radio target in org-mode?
** Back
Links that jump to specific locations in the same file:
#+begin_src org
<<target name>>
[[target name]] or [[*target name]]
#+end_src
* Statistics Cookies
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
** Front
How do you show task progress in org-mode?
** Back
#+begin_src org
[50%] - percentage
[3/5] - completed/total
#+end_src
Often used in lists like: =[- 2/5]=
Executable
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Sync org files to Anki using emacsclient
set -euo pipefail
FILES=(
"org/cpp/iterator.org"
"org/cpp/containers.org"
# add more files here
)
for file in "${FILES[@]}"; do
if [[ -f "$file" ]]; then
echo "Syncing $file..."
emacsclient --eval "(progn (find-file \"$file\") (org-anki-sync-all))"
else
echo "File not found: $file" >&2
fi
done
echo "Done."