Add rough preview
This commit is contained in:
parent
7d5d4f1080
commit
315e369f88
1 changed files with 69 additions and 17 deletions
86
README.md
86
README.md
|
@ -1,23 +1,75 @@
|
||||||
# Lytlang
|
# Lytlang
|
||||||
|
|
||||||
**TODO: Add description**
|
Lytlang's goal is to allow for more terse Elixir code and is itself written in
|
||||||
|
Elixir. Its syntax is a terrible merging of Elm, CoffeeScript, Elixir, and some
|
||||||
|
made-up crap. Here's a rough preview:
|
||||||
|
|
||||||
|
```
|
||||||
|
!mod Leetcode
|
||||||
|
|
||||||
|
# Look, a comment!
|
||||||
|
|
||||||
|
### part of the comment
|
||||||
|
Look, a multiline comment!
|
||||||
|
part of the comment ###
|
||||||
|
|
||||||
|
@doc
|
||||||
|
LeetCode #1: two_sum
|
||||||
|
|
||||||
|
TODO: store a map of complements (differences) as iterating for O(n)
|
||||||
|
|
||||||
|
fn two_sum _:list _:int i=0 ::
|
||||||
|
[] _ _ -> nil
|
||||||
|
[cur | rest] target current_index
|
||||||
|
Enum.find_index rest, fn x -> cur + x == target ::
|
||||||
|
nil -> two_sum rest target current_index
|
||||||
|
i -> [current_index, 1 + current_index + i]
|
||||||
|
|
||||||
|
@doc LeetCode #2: add_two_numbers
|
||||||
|
|
||||||
|
fn add_two_numbers _:list _:list _=[] i=0 ::
|
||||||
|
[] _ l m, _ [] l m -> finish_add_two_numbers l m
|
||||||
|
[n1 | r1] [n2 | r2] l carry
|
||||||
|
add_two_numbers r1 r2 [rem (carry + n1 + n2) 10) | l] (div n1 + n2 10)
|
||||||
|
|
||||||
|
fn finish_add_two_numbers l:list m:int -> m == 0 ? l : [m | l]
|
||||||
|
|
||||||
|
@doc
|
||||||
|
LeetCode #3: longest non-repeating susbtring
|
||||||
|
|
||||||
|
TODO: better utility function names?
|
||||||
|
|
||||||
|
fn longest_non_repeating_substring s
|
||||||
|
s |> String.codepoints |> Enum.reduce {0 0 0 %{}} &ln3_reducer/2 |> elem 0
|
||||||
|
|
||||||
|
fn ln3_new_least least map char
|
||||||
|
Map.has_key? map char ::
|
||||||
|
true -> max least ((Map.get map char) + 1)
|
||||||
|
_ -> least
|
||||||
|
|
||||||
|
fn ln3_reducer char {mx i least map}
|
||||||
|
least = ln3_new_least least map char
|
||||||
|
{(max mx (i - least + 1) (i + 1) least (Map.put map char i)}
|
||||||
|
|
||||||
|
@doc
|
||||||
|
LeetCode #4: median of sorted arrays
|
||||||
|
|
||||||
|
TODO: solution should me O(log(m+n))
|
||||||
|
TODO: finish an actual solution?
|
||||||
|
|
||||||
|
fn median_of_sorted_arrays _ _ -> 3
|
||||||
|
|
||||||
|
@doc LeetCode #65: Valid Number
|
||||||
|
|
||||||
|
@valid_decimal_number_regex ~r/^\s*(?:\+|-)?\d+(?:\.(?=\d))?\d*(?:e(?=[\d\+-]))?(?:\+|-)?\d*(?:\.(?=\d))?\s*$/
|
||||||
|
|
||||||
|
fn valid_decimal_number s -> Regex.match? @valid_decimal_number_regex s
|
||||||
|
```
|
||||||
|
|
||||||
|
**TODO: Add more description**
|
||||||
|
|
||||||
|
## Development Resources
|
||||||
|
|
||||||
+ https://pl-rants.net/posts/leex-yecc-in-elixir/
|
+ https://pl-rants.net/posts/leex-yecc-in-elixir/
|
||||||
+ https://notes.eellson.com/2017/01/22/html-parsing-in-elixir-with-leex-and-yecc/
|
+ https://notes.eellson.com/2017/01/22/html-parsing-in-elixir-with-leex-and-yecc/
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
|
||||||
by adding `lytlang` to your list of dependencies in `mix.exs`:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
def deps do
|
|
||||||
[
|
|
||||||
{:lytlang, "~> 0.1.0"}
|
|
||||||
]
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
|
||||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
|
||||||
be found at [https://hexdocs.pm/lytlang](https://hexdocs.pm/lytlang).
|
|
||||||
|
|
Loading…
Reference in a new issue