Skip to content

Commit bf5a5d0

Browse files
authored
Merge pull request #5 from sir-gon/feature/solve_me_first
[Hacker Rank]: Warmup: Solve Me Firs. Solved ✅
2 parents 9c72788 + 35edc78 commit bf5a5d0

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# [Solve Me First](https://www.hackerrank.com/challenges/solve-me-first)
2+
3+
Difficulty: #easy
4+
Category: #warmup
5+
6+
Complete the function solveMeFirst to compute the sum of two integers.
7+
8+
## Example
9+
10+
$ a = 7 $ \
11+
$ b = 3 $
12+
13+
Return 10.
14+
15+
## Function Description
16+
17+
Complete the solveMeFirst function in the editor below.
18+
solveMeFirst has the following parameters:
19+
20+
- int a: the first value
21+
- int b: the second value
22+
23+
## Constraints
24+
25+
$ 1 \leq a, b \leq 1000 $
26+
27+
## Sample Input
28+
29+
```text
30+
a = 2
31+
b = 3
32+
```
33+
34+
## Sample Output
35+
36+
```text
37+
5
38+
```
39+
40+
## Explanation
41+
42+
```text
43+
2 + 3 = 5
44+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
int HACKERRANK_WARMUP_solveMeFirst(int a, int b);
8+
9+
#ifdef __cplusplus
10+
} // extern "C"
11+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <exercises/hackerrank/warmup/solve_me_first.h>
2+
3+
/**
4+
* @link Problem definition [[docs/hackerrank/warmup/solveMeFirst.md]]
5+
*/
6+
7+
int HACKERRANK_WARMUP_solveMeFirst(int a, int b) { return a + b; }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <catch2/catch_test_macros.hpp>
2+
3+
#include <exercises/hackerrank/warmup/solve_me_first.h>
4+
#include <filesystem>
5+
#include <fstream>
6+
#include <nlohmann/json.hpp>
7+
#include <vector>
8+
9+
using json = nlohmann::json;
10+
11+
TEST_CASE("solveMeFirst JSON Test Cases",
12+
"[hackerrank] [jsontestcase] [warmup]") {
13+
std::filesystem::path cwd = std::filesystem::current_path();
14+
std::string path =
15+
cwd.string() +
16+
"/unit/lib/hackerrank/warmup/solve_me_first.testcases.json";
17+
18+
INFO("solveMeFirst JSON test cases FILE: " << path);
19+
20+
std::ifstream f(path);
21+
json data = json::parse(f);
22+
23+
for (auto testcase : data) {
24+
int result = HACKERRANK_WARMUP_solveMeFirst(testcase["a"], testcase["b"]);
25+
CHECK(result == testcase["expected"]);
26+
}
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{ "a": 0, "b": 0, "expected": 0 },
3+
{ "a": 2, "b": 3, "expected": 5 },
4+
{ "a": 0, "b": 7, "expected": 7 },
5+
{ "a": 7, "b": 0, "expected": 7 },
6+
{ "a": 7, "b": 7, "expected": 14 }
7+
]

0 commit comments

Comments
 (0)