This commit is contained in:
louiscklaw
2025-01-31 19:51:47 +08:00
parent 118e4a5f39
commit 866bfd3b42
189 changed files with 43536 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
-module(cw).
-import(string,[len/1, substr/3]).
-import(maps,[foreach/2]).
-export([start/0, test_find/2, ttt/5, checkMatch/3, find_patterns/2]).
checkMatch(Test, Wanted, CheckPos) when Test == Wanted ->
CheckPos -1;
checkMatch(Test, Wanted, CheckPos) when Test /= Wanted ->
"".
ttt(Data, Pattern, DataLength, PatternLength, StartPos) when StartPos >= (DataLength - (PatternLength -1)) ->
checkMatch(substr(Data,StartPos,PatternLength), Pattern, StartPos);
ttt(Data, Pattern, DataLength, PatternLength, StartPos) when StartPos < (DataLength - (PatternLength -1)) ->
[checkMatch(substr(Data,StartPos,PatternLength), Pattern, StartPos)| ttt(Data, Pattern, DataLength, PatternLength, StartPos+1)].
test_find(Data, Pattern) ->
DataLength = len(Data),
PatternLength = len(Pattern),
ttt(Data,Pattern, DataLength, PatternLength, 1).
test_helloworld(Data, []) ->
"";
test_helloworld(Data, [H|T]) ->
[test_find(Data, H) | test_helloworld(Data, T)].
find_patterns(Data, Pattern) ->
io:format(Pattern).
start() ->
io:format("~p~n",[test_helloworld("AAA",["AA"])]),
io:format("~p~n",[test_helloworld("AAA",["AA", "AC"])]),
io:format("~p~n",[test_helloworld("AAC",["AA", "AC"])]),
io:format("~p~n~n",[test_helloworld("AAAAAAAAAAAAAAACCCAAAAAAAAAAAAACCCA",["CC", "CCC"])]),
io:format("done~n").

View File

@@ -0,0 +1,9 @@
services:
ubuntu_1804:
# image: ubuntu:latest
build:
context: .
command: sleep infinity
working_dir: /app
volumes:
- .:/app

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -ex
docker compose up -d --build
docker compose exec -it ubuntu_1804 bash

View File

@@ -0,0 +1,5 @@
FROM ubuntu:latest
RUN apt update -qyy && \
apt install -qyy erlang

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,16 @@
-module(for_loop).
-import(string,[len/1, substr/3]).
-export([for/4,start/0, helloworld/0]).
for(0,_, D, P) ->
[substr(D, 1, 2)];
for(N,Term, D, P) when N > 0 ->
io:fwrite("~p~n",[substr(D, 4-(N-1), 2)]),
[ok|for(N-1,"A", D, P)].
helloworld() ->
io:fwrite("~p~n",[for(4,1,"AAAA","AA")]).
start() ->
helloworld().

View File

@@ -0,0 +1,9 @@
-module(func_tryout).
-export([add/2,start/0]).
add(X,Y) ->
Z = X+Y,
io:fwrite("~w~n",[Z]).
start() ->
add(5,6).

View File

@@ -0,0 +1,5 @@
-module(hello).
-export([hello_world/0]).
hello_world() ->
io:fwrite("hello, world\n").

View File

@@ -0,0 +1,7 @@
-module(map_tryout).
-export([hello_world/0]).
hello_world() ->
M1 = #{name=>adam,age=>24,date=>{july,29}},
io:format("M1:~p~n", [M1]),
M1.

View File

@@ -0,0 +1,18 @@
{
"name": "hk1234566",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "tests",
"gitUpdate": "git add . && git commit -m 'update Lab7 - Coursework Erlang part,' && git push",
"docker_rebuild": "docker compose up -d",
"into_backend": "docker compose exec -it ubuntu_1804 bash"
},
"scripts": {
"test": "node ./tests/test.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

@@ -0,0 +1,7 @@
-module(record_tryout).
-export([new/2]).
-record(person, {name, age}).
new(Name, Age) ->
#person{name=Name, age=Age}.

View File

@@ -0,0 +1,9 @@
-module(recursion).
-export([fac/1,start/0]).
fac(N) when N == 0 -> 1;
fac(N) when N > 0 -> N*fac(N-1).
start() ->
X = fac(4),
io:fwrite("~w",[X]).

View File

@@ -0,0 +1,40 @@
% "AAA"
% ["AA"]
% cw:find_patterns("AAA",["AA"])
% [[0,1]]
-module(string_index_of).
-import(string,[len/1, substr/3]).
-import(maps,[foreach/2]).
-export([start/0, test_find/2, ttt/5, checkMatch/3, find_patterns/2]).
checkMatch(Test, Wanted, CheckPos) when Test == Wanted ->
CheckPos -1;
checkMatch(Test, Wanted, CheckPos) when Test /= Wanted ->
"".
ttt(Data, Pattern, DataLength, PatternLength, StartPos) when StartPos >= (DataLength - (PatternLength -1)) ->
checkMatch(substr(Data,StartPos,PatternLength), Pattern, StartPos);
ttt(Data, Pattern, DataLength, PatternLength, StartPos) when StartPos < (DataLength - (PatternLength -1)) ->
[checkMatch(substr(Data,StartPos,PatternLength), Pattern, StartPos) , ttt(Data, Pattern, DataLength, PatternLength, StartPos+1)].
test_find(Data, Pattern) ->
DataLength = len(Data),
PatternLength = len(Pattern),
ttt(Data,Pattern, DataLength, PatternLength, 1).
test_helloworld(Data, []) ->
"";
test_helloworld(Data, [H|T]) ->
[test_find(Data, H) | test_helloworld(Data, T)].
find_patterns(Data, Pattern) ->
io:format(Pattern).
start() ->
io:format("~p~n",[test_helloworld("AAA",["AA"])]),
io:format("~p~n",[test_helloworld("AAA",["AA", "AC"])]),
io:format("~p~n",[test_helloworld("AAC",["AA", "AC"])]),
io:format("~p~n~n",[test_helloworld("AAAAAAAAAAAAAAACCCAAAAAAAAAAAAACCCA",["CC", "CCC"])]),
io:format("done~n").

View File

@@ -0,0 +1,7 @@
-module(string_tryout).
-export([hello_world/0]).
hello_world() ->
M1 = #{name=>adam,age=>24,date=>{july,29}},
io:format("M1:~p~n", [M1]),
M1.

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# rm -rf hello.beam
# erlc ./hello.erl
# erl -noshell -s hello hello_world -s init stop
# rm -rf func_tryout.beam
# erlc ./func_tryout.erl
# erl -noshell -s func_tryout function_test -s init stop
# rm -rf string_index_of.beam
# erlc ./string_index_of.erl
# erl -noshell -s string_index_of start -s init stop
# rm -rf map_tryout.beam
# erlc ./map_tryout.erl
# erl -noshell -s map_tryout hello_world -s init stop
# rm -rf recursion.beam
# erlc ./recursion.erl
# erl -noshell -s recursion start -s init stop
# rm -rf func_tryout.beam
# erlc ./func_tryout.erl
# erl -noshell -s func_tryout start -s init stop
rm -rf cw.beam
erlc ./cw.erl
erl -noshell -s cw start -s init stop
# rm -rf for_loop.beam
# erlc ./for_loop.erl
# erl -noshell -s for_loop start -s init stop
# rm -rf test_list.beam
# erlc ./test_list.erl
# erl -noshell -s test_list start -s init stop
echo 'done'

View File

@@ -0,0 +1,10 @@
-module(test_list).
-import(string,[len/1, substr/3]).
-export([start/0, helloworld/0]).
helloworld() ->
Temp = [1,2,3| [] ],
io:fwrite("~p~n",[Temp]).
start() ->
helloworld().

View File

@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1