Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv857 committed Nov 16, 2014
0 parents commit 72cd9db
Show file tree
Hide file tree
Showing 22 changed files with 148 additions and 0 deletions.
Binary file added Screen Shot 2014-09-30 at 12.31.59 AM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added binary search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions binary_search.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-module (binary_search).
-export ([search/2]).

search(Set, Value) ->
search(lists:sort(Set), Value, 1, length(Set)).

search(Set, Value, Low, High) ->
if
(High < Low) ->
{notfound, Value};
(true) ->
Mid = (Low + High) div 2,
MidVal = lists:nth(Mid, Set),
if
(MidVal > Value) ->
search(Set, Value, Low, Mid - 1);
(MidVal < Value) ->
search(Set, Value, Mid + 1, High);
(true) ->
{{value, Value}, {position, Mid}}
end
end.
Binary file added bins.beam
Binary file not shown.
29 changes: 29 additions & 0 deletions bins.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-module(bins).
-export([binary/2]).

binary(List, Value) ->
binarys(List, Value, 1, length(List)).


binarys(List, Value, Low, High) ->

if
length(List) < 10 ->
io:format("length of the list is less than 10. ");
true ->
if Low > High ->
io:format("Number ~p not found in the list~n", [Value]);

true ->
Mid = (Low + High) div 2,
MidNo = lists:nth(Mid, List),
if MidNo > Value ->
binarys(List, Value, Low, Mid-1);
MidNo < Value ->
binarys(List, Value, Mid+1, High);
true ->
io:format("Number ~p found at index ~p in the list~n", [Value, Mid])

end
end
end.
10 changes: 10 additions & 0 deletions cal.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-module(cal).
-export([area/1]).
area({square, Side}) ->
Side * Side;
area({circle, Radius}) ->
3.14159 * Radius * Radius;
area({rectangle, X, Y}) ->
X * Y;
area({rtriangle, B, H}) ->
0.5 * B * H.
Binary file added dolphins.beam
Binary file not shown.
13 changes: 13 additions & 0 deletions dolphins.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

-module(dolphins).
-compile(export_all).

dolphin1() ->
receive
do_a_flip ->
io:format("How about no?~n");
fish ->
io:format("So long and thanks for all the fish!~n");
_ ->
io:format("Heh, we're smarter than you humans.~n")
end.
Binary file added insert.beam
Binary file not shown.
1 change: 1 addition & 0 deletions insert.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-module(insert).-export([sort/1]). sort([]) -> []; sort(L) -> [H|T] = L, sort(H, T, []). sort(Val, [H|T], []) -> sort(H, T, [Val]); sort(Val, [], Sorted) -> insert(Val, Sorted); sort(Val, [H|T], Sorted) -> sort(H, T, insert(Val, Sorted)). insert(Val, []) -> [Val]; insert(Val, [H|T]) -> if Val =< H -> [Val,H|T]; true -> [H | insert(Val, T)]end.
Expand Down
Binary file added inserti.beam
Binary file not shown.
1 change: 1 addition & 0 deletions inserti.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-module(inserti).-export([sort/1]). sort([]) -> []; sort(L) -> [H|T] = L, sort(H, T, []). sort(Val, [H|T], []) -> sort(H, T, [Val]); sort(Val, [], Sorted) -> insert(Val, Sorted); sort(Val, [H|T], Sorted) -> sort(H, T, insert(Val, Sorted)). insert(Val, []) -> [Val]; insert(Val, [H|T]) -> if Val =< H -> [Val,H|T]; true -> [H | insert(Val, T)] end.
Expand Down
Binary file added insertion sort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added insertion_sort.beam
Binary file not shown.
12 changes: 12 additions & 0 deletions insertion_sort.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-module(insertion_sort).
-export([insertion_sort/1]).

insertion_sort([]) -> [];
insertion_sort([X | []]) -> [X];

insertion_sort(ToSort) -> insertion_sort(ToSort, []).

insertion_sort([], Sorted) -> Sorted;

insertion_sort(Unsorted, Sorted) -> Max = lists:max(Unsorted),
insertion_sort(lists:delete(Max, Unsorted), [Max] ++ Sorted).
4 changes: 4 additions & 0 deletions tut.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-module(tut).
-export([double/1]).
double(X)->
2*X.
8 changes: 8 additions & 0 deletions tut1.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-module(tut1).
-export([fac/1, mult/2]).
fac(1) ->
1;
fac(N) ->
N * fac(N - 1).
mult(X, Y) ->
X * Y.
Binary file added tut14.beam
Binary file not shown.
13 changes: 13 additions & 0 deletions tut14.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-module(tut14).

-export([start/0, say_something/2]).

say_something(What, 0) ->
done;
say_something(What, Times) ->
io:format("~p~n", [What]),
say_something(What, Times - 1).

start() ->
spawn(tut14, say_something, [hello, 3]),
spawn(tut14, say_something, [goodbye, 3]).
Binary file added tut15.beam
Binary file not shown.
29 changes: 29 additions & 0 deletions tut15.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-module(tut15).

-export([start/0, ping/2, pong/0]).

ping(0, Pong_PID) ->
Pong_PID ! finished,
io:format("ping finished~n", []);

ping(N, Pong_PID) ->
Pong_PID ! {ping, self()},
receive
pong ->
io:format("Ping received pong~n", [])
end,
ping(N - 1, Pong_PID).

pong() ->
receive
finished ->
io:format("Pong finished~n", []);
{ping, Ping_PID} ->
io:format("Pong received ping~n", []),
Ping_PID ! pong,
pong()
end.

start() ->
Pong_PID = spawn(tut15, pong, []),
spawn(tut15, ping, [3, Pong_PID]).
6 changes: 6 additions & 0 deletions tut2.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-module(tut2).
-export([convert/2]).
convert(M, inch) ->
M / 2.54;
convert(N, centimeter) ->
N * 2.54.

0 comments on commit 72cd9db

Please sign in to comment.