From cf0ebf0bdefe44515f422d1510543efed05e7e89 Mon Sep 17 00:00:00 2001 From: Edera Date: Thu, 7 Oct 2021 23:43:31 +0200 Subject: [PATCH 1/4] added: solution in python to find missing number challenge --- .../solutions/valentinadagata/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 challenges/easy/find-missing-number/solutions/valentinadagata/main.py diff --git a/challenges/easy/find-missing-number/solutions/valentinadagata/main.py b/challenges/easy/find-missing-number/solutions/valentinadagata/main.py new file mode 100644 index 0000000..5d7e73b --- /dev/null +++ b/challenges/easy/find-missing-number/solutions/valentinadagata/main.py @@ -0,0 +1,10 @@ +def find_missing_number(l): + # total list = sum all the numbers between the min and the max of the list + # difference between the total list and the list will be the missing number + n = sum(range(min(l), max(l) + 1)) - sum(l) + return n + + +if __name__ == '__main__': + mylist = [230, 222, 220, 224, 229, 221, 225, 223, 228, 226] + print(find_missing_number(mylist)) \ No newline at end of file From 39d2a9a10dfae4f3adc3eb86f8bce9b632dc2f2d Mon Sep 17 00:00:00 2001 From: Edera Date: Sat, 9 Oct 2021 15:26:28 +0200 Subject: [PATCH 2/4] fix: sort the list and take the first and the last item to iterate only 1 time (instead of using max and min) --- .../find-missing-number/solutions/valentinadagata/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/challenges/easy/find-missing-number/solutions/valentinadagata/main.py b/challenges/easy/find-missing-number/solutions/valentinadagata/main.py index 5d7e73b..8db1d76 100644 --- a/challenges/easy/find-missing-number/solutions/valentinadagata/main.py +++ b/challenges/easy/find-missing-number/solutions/valentinadagata/main.py @@ -1,7 +1,9 @@ def find_missing_number(l): + # sort the list to get the min and the max taking the first and the last item + l.sort() # total list = sum all the numbers between the min and the max of the list # difference between the total list and the list will be the missing number - n = sum(range(min(l), max(l) + 1)) - sum(l) + n = sum(range(l[0], l[len(l)-1] + 1)) - sum(l) return n From cacc49acc65cd01ca86a2c9b56c884e2ea37e9ea Mon Sep 17 00:00:00 2001 From: Edera Date: Sun, 10 Oct 2021 13:57:34 +0200 Subject: [PATCH 3/4] added: my solution in erlang --- .../solutions/valentinadagata/main.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 challenges/easy/find-missing-number/solutions/valentinadagata/main.erl diff --git a/challenges/easy/find-missing-number/solutions/valentinadagata/main.erl b/challenges/easy/find-missing-number/solutions/valentinadagata/main.erl new file mode 100644 index 0000000..44eb902 --- /dev/null +++ b/challenges/easy/find-missing-number/solutions/valentinadagata/main.erl @@ -0,0 +1,10 @@ +-module(main). +-import(lists,[sum/1]). +-export([start/0]). + +start() -> + MyList=[230, 222, 220, 224, 229, 221, 225, 223, 228, 226], + Total = sum(lists:seq(lists:min(MyList), lists:max(MyList))), + MissingNum = Total - sum(MyList), + io:fwrite("~w~n", [MissingNum]), + MissingNum. From 642b89cfd916c98b8885e560d0ae2bcabecd81a7 Mon Sep 17 00:00:00 2001 From: Edera Date: Sun, 24 Oct 2021 18:45:22 +0200 Subject: [PATCH 4/4] findMissingNumber function was created to return the result --- .../solutions/valentinadagata/main.erl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/challenges/easy/find-missing-number/solutions/valentinadagata/main.erl b/challenges/easy/find-missing-number/solutions/valentinadagata/main.erl index 44eb902..9c08fab 100644 --- a/challenges/easy/find-missing-number/solutions/valentinadagata/main.erl +++ b/challenges/easy/find-missing-number/solutions/valentinadagata/main.erl @@ -2,9 +2,11 @@ -import(lists,[sum/1]). -export([start/0]). -start() -> - MyList=[230, 222, 220, 224, 229, 221, 225, 223, 228, 226], +findMissingNumber(MyList) -> Total = sum(lists:seq(lists:min(MyList), lists:max(MyList))), MissingNum = Total - sum(MyList), - io:fwrite("~w~n", [MissingNum]), MissingNum. + +start() -> + MyList=[230, 222, 220, 224, 229, 221, 225, 223, 228, 226], + io:fwrite("~w~n", [findMissingNumber(MyList)]).