Consider the following straightforward mutable queue implementation using two stacks:
type 'a adt_queue = {
mutable head : 'a head;
mutable tail : 'a tail;
}
Grid problems are almost always just graph problems and typically straightforward ones. I initially found them a bit weird because in algorithm classes they present graphs as adjacency nodes or adjacency matrices. In a grid, each cell is a node, and it's neighbors are the four-directional neighboring cells or sometimes 8-directional, if the problem at hand allows travel in all the diagonals in addition to up, down, left, right. The vertices are not explicit but usually we don't need to worry about them in these problems. | |
There is nothing special about a grid vs another type of graph representation. Just need to tweak the grpah algorithms at our disposal. | |
Basic graph techniques: | |
BFS- traverses the entire graph, going layer by layer expanding from the starting point. It allows us to do a couple of things, count connected components in a graph, find the shortest distance from one cell to another cell. While traversing, | |
we need to track visited cells. You can do that by changing the cell value (coloring) or r |
" Statusline (requires Powerline font) | |
set statusline= | |
set statusline+=%(%{&buflisted?bufnr('%'):''}\ \ %) | |
set statusline+=%< " Truncate line here | |
set statusline+=%f\ " File path, as typed or relative to current directory | |
set statusline+=%{&modified?'+\ ':''} | |
set statusline+=%{&readonly?'\ ':''} | |
set statusline+=%= " Separation point between left and right aligned items | |
set statusline+=\ %{&filetype!=#''?&filetype:'none'} | |
set statusline+=%(\ %{(&bomb\|\|&fileencoding!~#'^$\\\|utf-8'?'\ '.&fileencoding.(&bomb?'-bom':''):'') |
#!/bin/sh | |
# | |
# Setup a work space called `work` with two windows | |
# first window has 3 panes. | |
# The first pane set at 65%, split horizontally, set to api root and running vim | |
# pane 2 is split at 25% and running redis-server | |
# pane 3 is set to api root and bash prompt. | |
# note: `api` aliased to `cd ~/path/to/work` | |
# | |
session="work" |