-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 72cd9db
Showing
22 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-module(tut). | ||
-export([double/1]). | ||
double(X)-> | ||
2*X. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |