HGPA

A Little Computer Programming

(This is WIP)

This is a little workbook on computer programming. It falls somewhere between beginner and intermediate. I am not an expert.

This workbook is meant to be followed sequentially. I recommend Python or Javascript. If you use a Lisp you will identify things you can skip.

Computer programming is a skill. Deliberate practice is necessary to improve this skill. Only with skill and effort can we achieve.

Computer programming is fun. Enjoy these challenges for what they are. Forget about everything else.

Checklist

Dimension 1:

Dimension 1.5:

Dimension 2:

Dimension 1

Essential Functions

Write these basic functions but don't forget them!

isarray(obj)

isempty(array)

first(array)

rest(array)

push(val, array)

Useful Functions

repeat(val, count)

last(array)

initial(array)

range(start, stop, step=1)

remove(array, val)

slice(array, start, stop, step=1)

Now implement all of these recursively without using loops. Use the Essential Functions. You do not need to know the length of the array!

Reversing

reverse(array)

Please do this three ways:

From here on out please implement each function twice: iteratively and recursively!

Map/Reduce

Use reduce to calculate some common reductions:

Noticing a recurring theme here? 😂

Partitioning

This is a challenging group. No joke intended.

flatten(array)

partition(fn, array)

partition_at_pivot(fn, array)

groups_of(array, n)

groups_prioritized(array, n)

groups(array, n)

interleave(*arrays)

deinterleave(array, n)

zip(*arrays)

unzip(array[])

(I'm just throwing these last two down here for now)

concat(*array)

Set Theory

A set is an unordered collection of unique items. In other words, there are no duplicates. Hint: Dictionaries can help you remember things!



Sorted Lists

Sorting

All these should mutate the array, i.e. do the work in-place.

reverse_mutate(array)

Use the following arrays to test:

  actual = [2,1,9,8,4,5,7,0,3,6]
  expected = [0,1,2,3,4,5,6,7,8,9]

bubble_sort(array)

selection_sort(array)

insertion_sort(array)

TODO:

Strings

trim(string, characters=" \t\n\r")

parse_int

Bits

Trees

TODO

Ideas

Note regarding Space Matrices

for any [M][N] array (Rows x Columns)

# assuming array[m][n]
for m in xrange(array): # rows
  for n in xrange(array[m]): # columns
    print array[m][n]

1 x N = [1,2,3]
M x 1 = [
  [1],
  [2],
  [3],
]


The problem with this is that it 

How we usually think of arrays in code:
[
  [1,2,3],
  [4,5,6]
  [7,8,9]
]

Translates to these [M][N] pairs:
[
  [(0,0),(0,1),(0,2)],
  [(1,0),(1,1),(1,2)],
  [(2,0),(2,1),(2,2)],
]

If the center is the origin then move like this.
[
  [(-1,-1),(-1,0),(-1,+1)],
  [( 0,-1),( 0,0),( 0,+1)],
  [(+1,-1),(+1,0),(+1,+1)],
]

Just picture the matrix! FORGET the Cartesian plane! this i Column x Row with origin at bottom-left FORGET the image plane! this is column Column x Row with origin at top-left FORGET latitude and longitude. I can't even remember which is which or how it works!

https://en.wikipedia.org/wiki/Row-_and_column-major_order

Tips

History

After various failed online, phone, and on-site technical interviews I made this workbook. It is the culmination of lessons learned the hard way.

This is a work in progress. HGPA

Filename: a-little-computer-programming.md (Edit)
Modified: 2017-03-04 (3aef9a8355360f085c00b9e3cfea97978116f548)
Created: 2017-03-02 (18b38430a69fd1e016089c80a93899306397683a)