about summary refs log tree commit diff
AgeCommit message (Collapse)AuthorFilesLines
2020-12-18 Create offline, org file from TeamBlind LC questionsWilliam Carroll1-0/+88
TeamBlind.com hosts a curated list of DS&As questions from LeetCode.com that the author claims appropriately samples the topics worth exploring. I'm creating an offline list so that I can track my progress and work while I'm traveling.
2020-12-13 Show Morning and Evening habits by defaultWilliam Carroll1-2/+2
Now that I've deployed this, and I have an iPad running in kiosk mode, I realized that I'd like to show my morning routine and my evening routine.
2020-12-13 Update Sunday and Morning chainsWilliam Carroll1-3/+1
Adapting to changes.
2020-12-13 Add -r to cp to copy the directoryWilliam Carroll1-1/+1
This should be the last hold-out before deploying habit-screens! :)
2020-12-13 Commit compiled file, output.css to habit-screensWilliam Carroll2-1/+103571
As you can see, I was previously `.gitignore`-ing this file, but because my `default.nix` attempts to `cp output.css`, I need that file available.
2020-12-13 Productionize habit-screensWilliam Carroll2-12/+20
At some point I should document or write a script for how I package Elm projects with Nix to be deployed on my website. For now, I'm modeling everything after my previous success LearnPianoChords.
2020-12-12 Add project-local .gitignoreWilliam Carroll1-0/+1
Since the `default.nix` file is specific to my tooling, I'm ignoring it.
2020-12-12 Add usage instructions to top-level READMEWilliam Carroll2-21/+14
Also delete redundant `README` from `server` directory.
2020-12-12 Expose functions at API layerWilliam Carroll4-2/+104
Creating a simple HTTP RESTful API for exposing our `Server.semiprime` function. It supports some help messages, primitive parsing and error handling, and singular vs. batch processing of arguments. For more sophisticated parsing and error-checking, I prefer to use Haskell's Servant library.
2020-12-12 Include cache hit/miss info in return typeWilliam Carroll2-3/+4
This can be useful downstream for diagnostics.
2020-12-12 Expand 10^5 in READMEWilliam Carroll1-1/+1
I think it's more readable this way.
2020-12-12 Simple Math testsWilliam Carroll1-3/+1
Calling `assert` within the `Enum.map` makes the errors more usable.
2020-12-12 Define Server.semiprimeWilliam Carroll2-9/+49
- Clear the boilerplate that `mix` generated - Consume `Math.factor` to test which inputs are semiprimes - Cache all inputs that are semiprimes as soon as we discover that they are - semiprimes I considered a couple things related to the Cache: - Could save space by storing all semiprime factors in a tree. This would make the lookups more expensive. Also because the tree's depth would never exceed two (because all semiprimes only have two factors), the tree would be quite broad, and we may not be saving enough space for the trade to be worthwhile. I might be wrong about that though. - We could consider pre-computing all semiprimes when we start the app, but without running some tests firsts, I'm not sure whether or not it's worth the trouble.
2020-12-12 Define Cache.{list,clear} to help debuggingWilliam Carroll1-0/+14
Since I'm often using `iex` for interactive development, these functions are useful.
2020-12-12 Define Cache and convert app to OTPWilliam Carroll4-1/+58
Define a simple in-memory key-value store for our cache. TL;DR: - Define `Cache` as a simple state-keeping `Agent` - Define `Sup`, which starts our Cache process - Define `App`, which starts our Supervisor process - Whitelist `App` in `mix.exs`, so that it starts after calling `iex -S mix`
2020-12-11 Add moduledoc to ExtrasWilliam Carroll1-0/+4
9 out of 10 doctors agree that every module needs a doc. Ask your doctor if moduledocs are right for you!
2020-12-11 Move the habit-screens project into //websiteWilliam Carroll17-18/+149
I'd like to eventually deploy this to wpcarro.dev. Coming soon!
2020-12-11 Delete //website/habitsWilliam Carroll2-17/+0
Accommodating space for my habit-screens project.
2020-12-11 Delete //website/habitgardenWilliam Carroll15-5904/+0
This is change #2 in a series of other larger changes...
2020-12-11 Delete //website/days-of-week-habitsWilliam Carroll15-6048/+0
This is one small change in a series of other, larger changes.
2020-12-11 Define stubbed default.nixWilliam Carroll1-0/+1
In case I want to package this project with Nix. For now, it's useful to store this at the project root because it help my Emacs's `project-find-file` function.
2020-12-11 Define Math moduleWilliam Carroll2-0/+58
Support `Math.factor` and cover it with tests.
2020-12-11 Define Extras moduleWilliam Carroll2-0/+36
I'll use as the host for utility functions needed to extend the stdlib.
2020-12-11 Init Elixir projectWilliam Carroll8-0/+107
Starting fresh with... ```shell mix new server ```
2020-12-11 Initialize the Semiprimes ServiceWilliam Carroll1-0/+30
This is an exciting take-home assignment because I get to write a service in Elixir!
2020-12-07 Update groceries/list.orgWilliam Carroll1-39/+76
Oh the times they are a-changin'
2020-12-07 Define another function to illustrate Reservoir SamplingWilliam Carroll1-0/+11
Documenting a few ideas about Reservoir Sampling while it's fresh on my mind.
2020-12-07 Fix typoWilliam Carroll1-1/+1
It's Splitwise... not Transferwise!
2020-11-23 Update BFS implsWilliam Carroll2-3/+3
I've subtly been implementing breadth-first traversals in graphs incorrectly. The change is subtle, but updating `seen` needs to happen immediately after queuing an item. The results will remain the same, but the runtimes will differ dramatically. I didn't notice this until I attempted to complete LeetCode's "count islands" challenge, and LeetCode rejected my solution because it could not finish before timing out. After looking at other candidates' solutions and comparing them to mine, I couldn't see any difference... except for this subtle difference. This SO answer provides a helpful explanation: https://stackoverflow.com/questions/45623722/marking-node-as-visited-on-bfs-when-dequeuing The take-away lesson here is to always call `seen.add(..)` immediately after enqueuing.
2020-11-21 Solve "cafe order checker" (again)William Carroll1-0/+34
Perhaps my fifth iteration of solving this problem.
2020-11-21 Solve "permutation palindrome" (again)William Carroll1-0/+8
Python's `collections` library really shines for this problem.
2020-11-21 Implement a queue using two stacksWilliam Carroll1-0/+17
The space cost is O(n). The runtime cost of enqueue is O(1); the runtime cost of dequeue is O(n). Using the "accounting method", the cost of an item in the system is O(1). Here's why: +------------+----------------------------+------+ | enqueue | push onto lhs | O(1) | +------------+----------------------------+------+ | lhs -> rhs | pop off lhs; push onto rhs | O(1) | +------------+----------------------------+------+ | dequeue | pop off rhs | O(1) | +------------+----------------------------+------+
2020-11-21 Implement a bottom-up fibonacciWilliam Carroll1-0/+6
The bottom-up solution run in O(n) time instead of O(2^n) time, which the recursive solution runs as: ``` def fib(n): return fib(n - 2) + fib(n - 1) ``` Remember that exponential algorithms are usually recursive algorithms with multiple sibling calls to itself.
2020-11-21 Solve "linked-list-cycles"William Carroll1-0/+70
Write a predicate for checking if a linked-list contains a cycle. For additional practice, I also implemented a function that accepts a linked-list containing a cycle and returns the first element of that cycle.
2020-11-21 Reimplement bst-checkerWilliam Carroll1-0/+14
Practice makes perfect. See the previous commit for a more details about this solution.
2020-11-21 Refactor existing bst-checker implementationWilliam Carroll1-40/+10
I believe the previous solution is invalid. This solution works and it should be more time and space efficient. Space-wise our stack grows proportionate to the depth of our tree, which for a "balanced" BST should be log(n). Doing a BFT on a BST results in memory usage of n because when we encounter the leaf nodes at the final level in the tree, they will be 1/2 * n for a balanced BST.
2020-11-21 Solve merge-sorted-arrays (again)William Carroll1-0/+30
InterviewCake.com has a section on Facebook's interview, so I'm attempting to solve all of the problems on there even if that means I'm resolving problems. The more practice, the better. Right? URL: interviewcake.com/facebook-interview-questions
2020-11-21 Solve "find duplicate" using a graphWilliam Carroll1-0/+57
This problem is unusually difficult, but the solution is elegant.
2020-11-20 Implement the Levenstein "edit distance" algorithmWilliam Carroll1-0/+47
This is the mother of dynamic programming algorithms in my opinion. It computes the minimal "edit distance" between two input strings where an edit is considered one of: - inserting a character into `a` - deleting a character from `a` - substituting a character in `a` with a character from `b` It took me awhile to grok the algorithm, but I implemented this from my understanding of something that I read ~3 nights prior, so I must've understood what I read. Good news!
2020-11-20 Solve "count islands" problemWilliam Carroll1-0/+53
This morning, I attended the "Interview Club" and was asked this question by the interviewer in front of ~20 FTEs. While I struggled to fully solve it during the abridged (i.e. 20 minute) timeslot, I completed the problem afterwards. Here is my solution.
2020-11-19 Re-implement suffix_tree functionWilliam Carroll1-0/+29
Create a suffix tree from an input string. This implementation uses a stack to control the flow of the program. I expected this attempt to be easier than my first attempt, but surprisingly, it was similarly difficult. It took me ~30-45 minutes to successfully implement this function, and I'm still not pleased with the final result.
2020-11-19 Implement a suffix treeWilliam Carroll1-0/+64
While it took me awhile to implement, this exercise was definitely worth doing. I think there should be a more elegant way to construct the tree using maybe a stack, but I couldn't find it. All of this was part of a larger effort to search a string for a variety of patterns. The solution is to compile the string into a suffix tree and then search the suffix tree for each of the patterns. I'm glad I didn't gloss over this exercise.
2020-11-17 Refactor random-choiceWilliam Carroll1-2/+2
Prefer initializing `result` to an empty array of size `m`, which makes the algorithm a bit more elegant.
2020-11-17 Solve algorithms dealing with randomnessWilliam Carroll2-0/+46
Tonight I learned that random sample where each element in the sampling corpus has an equal likelihood of being chosen is a brand of algorithms known as "reservoir sampling". - Implement random.shuffle(..) - Implement random.choice(..) Surprisingly, candidates are expected to encounter problems like this during interviews.
2020-11-16 Solve "nearby words" functionWilliam Carroll1-0/+33
Given an input like "gello" suggest an correction like "hello". This is a proof-of-concept problem for writing a simplistic auto-correction algorithm for a mobile device.
2020-11-16 Implement the Rabin Karp string matching algorithmWilliam Carroll1-0/+27
This algorithm is pretty interesting because it runs in linear time with respect to the length of the `corpus` string. It does this by using a sliding window hash. This hash -- because it's a sliding window -- runs in constant time for each iteration; we're only adding and subtracting one character each time and not re-hashing the whole "window". When our hashes match, only then do we compare the "window" to the `pattern`. String comparisons are linear because they compare each character to each character one at a time. But because we only compare strings when are hashes match (a check which runs in constant time), this spares us the performance hit.
2020-11-16 Prefer mutative variant of delete for HashTableWilliam Carroll1-3/+16
Instead of calling `filter(..)`.
2020-11-16 Add another solution to the "move zeroes to end" problemWilliam Carroll1-15/+51
Support the optimally performance solution of which I'm aware.
2020-11-16 Solve "find pairs for sum"William Carroll1-0/+19
I have encountered this problem 3x in the wild thus far: 1. www.InterviewCake.com 2. Cracking the Coding Interview 3. www.Pramp.com
2020-11-16 Start working on the "Hard" problemsWilliam Carroll1-0/+22
Firstly, implement a function that adds two arguments together... without using the `+` operator. I need to drill this problem. Thankfully I took a Coursera course that taught me how to make a half-adder and a full-adder, but the recommended solution for this is a bit more difficult.