Benjamin Halsted // [bgh] todo, add something clever here.

12Mar/100

Erlang Programming Exercise: 3-2

Exercise 3-2 is also 2 questions:

Write a function that returns a list of the format [1,2,..,N-1,N].

Write a function that returns a list of the format [N, N-1,..,2,1]

I've created 4 functions, create/1, create/2, reverse_create/1, and reverse_create/2. The /1 functions set up the arguments for the /2 worker functions to loop on.

-module(threetwo).
-export([create/1, reverse_create/1]).

create(1, [1|_T]=List) ->
	List;
create(Num, List) ->
	Next = Num-1,
	create(Next, [Next|List]).

create(Num) when Num > 0 ->
	create(Num, [Num]).

reverse_create_list(Num, [Num|_T]=List) ->
	List;
reverse_create_list(Num, [H|_T]=List) ->
	reverse_create_list(Num, [H+1|List]).

reverse_create(Num) when Num > 0 ->
	reverse_create_list(Num, [1]).

An example run:

4> threetwo:create(10).
[1,2,3,4,5,6,7,8,9,10]
5> threetwo:reverse_create(10).
[10,9,8,7,6,5,4,3,2,1]

The key in is to pass your target number along and to build the list from right to left. In each iteration we peak at the head of the list, modify that value and then prepend the result to the head of the full list.

[H|_T]=List

H is the first item in the list.
List is the full List.

Cheers,
Ben

5Mar/100

Subversion loves Araxis Merge (or, How I finally configured subversion to use Araxis Merge in a not so stupid way.)

Araxis suggests modifying subversions diff-cmd and diff3-cmd settings to get it to use Araxis Merge instead of the defaults. Here is a snippet from their docs. (You can skip it, it's just here to make my post look bigger.):

Open your ‘SVN configuration area’ configuration file in a text editor. The default location for this file is ~/.subversion.

Uncomment the line that specifies the diff-cmd and set its value to the path of the Merge araxissvndiff executable that you have installed on your machine:

diff-cmd = /Users/<userid>/bin/araxissvndiff

Note: in the above path, replace /Users/<userid>/bin/araxissvndiff with the full path to the Merge Merge araxissvndiff command-line utility that you have installed on your machine.

Also uncomment the line that specifies the diff-cmd3 and set its value to the path of the Merge araxissvndiff3 executable that you have installed on your machine:

diff3-cmd = /Users/<userid>/bin/araxissvndiff3

Note: in the above path, replace /Users/<userid>/bin/araxissvndiff3 with the full path to the Merge Merge araxissvndiff3 command-line utility that you have installed on your machine.

By doing what they say, you tell svn to use Araxis Merge every time it needs to merge a file. The problem with this is that svn will open Araxis Merge to make every merge. When you have a couple hundred files, you want svn to merge everything it can without opening Araxis Merge, and to only open it when there is a conflict. There is a way to do this, but it is not obvious.

7Oct/09Off

Shock & Awe @ Google

2009.10.7 Google Homepage

2009.10.7 Google Homepage

Today Googles homepage has a nice look to it, so much different that I was shocked when I arrived. The navigation and footer links faded in when you move your mouse. Very nice Google, I applaud you.

Tagged as: No Comments
14Sep/09Off

Meh… new web host.

>:D<

Filed under: Uncategorized No Comments