diff --git a/challenges/find-closest-number/README.md b/challenges/find-closest-number/README.md new file mode 100644 index 0000000..d6e5b8a --- /dev/null +++ b/challenges/find-closest-number/README.md @@ -0,0 +1,73 @@ +# find-closest-number + +Created by [@Divlo](https://github.com/Divlo) on 1 May 2022. + +## Instructions + +Given an array of `n` integers, find the closest value to the given number (`given_number`). + +## Input + +- **Line 1:** An integer `given_number` for the number to find the closest value to +- **Line 2:** An integer `n` for the length of the list of integers +- **`n` next lines:** the integers + +## Output + +The closest value in the array to the given number. + +## Examples + +See the `test` folder for examples of input/output. + +### Example 1 + +#### Input + +```txt +3 +6 +1 +2 +3 +4 +5 +6 +``` + +#### Output + +```txt +3 +``` + +**Explanation:** The given number is `3` and `3` is in the array, so the closest value is `3`. + +### Example 2 + +#### Input + +```txt +0 +14 +7 +-10 +13 +8 +4 +-7 +-12 +-3 +3 +-9 +6 +-1 +-6 +7 +``` + +#### Output + +```txt +-1 +``` diff --git a/challenges/find-closest-number/solutions/.gitkeep b/challenges/find-closest-number/solutions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/challenges/find-closest-number/test/1/input.txt b/challenges/find-closest-number/test/1/input.txt new file mode 100644 index 0000000..c07b3b5 --- /dev/null +++ b/challenges/find-closest-number/test/1/input.txt @@ -0,0 +1,8 @@ +3 +6 +1 +2 +3 +4 +5 +6 \ No newline at end of file diff --git a/challenges/find-closest-number/test/1/output.txt b/challenges/find-closest-number/test/1/output.txt new file mode 100644 index 0000000..e440e5c --- /dev/null +++ b/challenges/find-closest-number/test/1/output.txt @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git a/challenges/find-closest-number/test/2/input.txt b/challenges/find-closest-number/test/2/input.txt new file mode 100644 index 0000000..b39b59a --- /dev/null +++ b/challenges/find-closest-number/test/2/input.txt @@ -0,0 +1,16 @@ +0 +14 +7 +-10 +13 +8 +4 +-7 +-12 +-3 +3 +-9 +6 +-1 +-6 +7 \ No newline at end of file diff --git a/challenges/find-closest-number/test/2/output.txt b/challenges/find-closest-number/test/2/output.txt new file mode 100644 index 0000000..d7d17fc --- /dev/null +++ b/challenges/find-closest-number/test/2/output.txt @@ -0,0 +1 @@ +-1 \ No newline at end of file diff --git a/challenges/find-closest-number/test/3/input.txt b/challenges/find-closest-number/test/3/input.txt new file mode 100644 index 0000000..69d8d72 --- /dev/null +++ b/challenges/find-closest-number/test/3/input.txt @@ -0,0 +1,12 @@ +80 +10 +2 +42 +82 +122 +162 +202 +242 +282 +322 +362 \ No newline at end of file diff --git a/challenges/find-closest-number/test/3/output.txt b/challenges/find-closest-number/test/3/output.txt new file mode 100644 index 0000000..9d1ce53 --- /dev/null +++ b/challenges/find-closest-number/test/3/output.txt @@ -0,0 +1 @@ +82 \ No newline at end of file diff --git a/challenges/find-closest-number/test/4/input.txt b/challenges/find-closest-number/test/4/input.txt new file mode 100644 index 0000000..a31a5de --- /dev/null +++ b/challenges/find-closest-number/test/4/input.txt @@ -0,0 +1,10 @@ +11 +8 +1 +2 +4 +5 +6 +6 +8 +9 \ No newline at end of file diff --git a/challenges/find-closest-number/test/4/output.txt b/challenges/find-closest-number/test/4/output.txt new file mode 100644 index 0000000..f11c82a --- /dev/null +++ b/challenges/find-closest-number/test/4/output.txt @@ -0,0 +1 @@ +9 \ No newline at end of file diff --git a/challenges/find-closest-number/test/5/input.txt b/challenges/find-closest-number/test/5/input.txt new file mode 100644 index 0000000..3969dc5 --- /dev/null +++ b/challenges/find-closest-number/test/5/input.txt @@ -0,0 +1,8 @@ +4 +6 +2 +5 +6 +7 +8 +9 \ No newline at end of file diff --git a/challenges/find-closest-number/test/5/output.txt b/challenges/find-closest-number/test/5/output.txt new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/challenges/find-closest-number/test/5/output.txt @@ -0,0 +1 @@ +5 \ No newline at end of file