Micah Weston commited on
Commit
b1826a1
·
1 Parent(s): 295908e

Fix error.

Browse files
Files changed (1) hide show
  1. data/genericify_cpp.jsonl +2 -2
data/genericify_cpp.jsonl CHANGED
@@ -16,5 +16,5 @@
16
  {"base_canonical_solution": "template <typename T>\nint count_distinct_characters(T str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "base_prompt": "Make the following function generic for the parameter `str`.", "concepts_canonical_solution": "template <typename T>\n requires std::same_as<typename T::value_type, char>\nint count_distinct_characters(T str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a sequenced container of value type character.", "invalids": "int main() { count_distinct_characters(std::vector<int>{}); }", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<std::is_same_v<typename T::value_type, char>, int> = 0>\nint count_distinct_characters(T str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a sequenced container of value type character.", "starter_code": "int count_distinct_characters(std::string str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "task_id": "HEP/16", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\nint main() {\n ASSERT(count_distinct_characters(std::string{\"\"}) == 0);\n ASSERT(count_distinct_characters(std::string{\"abcde\"}) == 5);\n ASSERT(count_distinct_characters(std::string{\"abcdecadeCADE\"}) == 5);\n ASSERT(count_distinct_characters(std::string{\"aaaaAAAAaaaa\"}) == 1);\n ASSERT(count_distinct_characters(std::string{\"Jerry jERRY JeRRRY\"}) == 5);\n\n ASSERT(count_distinct_characters(std::vector<char>{}) == 0);\n ASSERT(count_distinct_characters(\n std::vector<char>{'a', 'b', 'c', 'd', 'e'}) == 5);\n ASSERT(count_distinct_characters(std::vector<char>{'a', 'b', 'c', 'd', 'e',\n 'c', 'a', 'd', 'e', 'C',\n 'A', 'D', 'E'}) == 5);\n ASSERT(count_distinct_characters(std::vector<char>{\n 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a'}) == 1);\n ASSERT(count_distinct_characters(\n std::vector<char>{'J', 'e', 'r', 'r', 'y', ' ', 'j', 'E', 'R', 'R',\n 'Y', ' ', 'J', 'e', 'R', 'R', 'R', 'Y'}) == 5);\n}\n"}
17
  {"base_canonical_solution": "template <typename T>\nT parse_music(std::string music_string) {\n std::string current = \"\";\n T out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "base_prompt": "Make the following function generic for the return type.", "concepts_canonical_solution": "template <typename T>\n requires requires(T& t, int v) {\n { t.push_back(v) };\n }\nT parse_music(std::string music_string) {\n std::string current = \"\";\n T out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a container of int that can be pushed back into.", "invalids": "int main() { parse_music(float{3.0}) }", "sfinae_canonical_solution": "template <typename T,\n typename = std::void_t<\n decltype(std::declval<T&>().push_back(std::declval<int>()))>>\nT parse_music(std::string music_string) {\n std::string current = \"\";\n T out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a container of int that can be pushed back into.", "starter_code": "std::vector<int> parse_music(std::string music_string) {\n std::string current = \"\";\n std::vector<int> out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "task_id": "HEP/17", "tests": "\ntemplate <typename T>\nbool issame(T a, T b) {\n if (a.size() != b.size()) return false;\n return std::equal(a.begin(), a.end(), b.begin());\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(parse_music<_type_>(\"\"), _type_{})); \\\n ASSERT(issame(parse_music<_type_>(\"o o o o\"), _type_{4, 4, 4, 4})); \\\n ASSERT(issame(parse_music<_type_>(\".| .| .| .|\"), _type_{1, 1, 1, 1})); \\\n ASSERT(issame(parse_music<_type_>(\"o| o| .| .| o o o o\"), \\\n _type_{2, 2, 1, 1, 4, 4, 4, 4})); \\\n ASSERT(issame(parse_music<_type_>(\"o| .| o| .| o o| o o|\"), \\\n _type_{2, 1, 2, 1, 4, 2, 4, 2})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<int>);\n TEST_ON_TYPE(std::deque<int>);\n TEST_ON_TYPE(std::list<int>);\n}\n"}
18
  {"base_canonical_solution": "template <typename T>\nT how_many_times(std::string str, std::string substring) {\n T out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "base_prompt": "Make the following function generic for the return value.", "concepts_canonical_solution": "template <std::integral T>\nT how_many_times(std::string str, std::string substring) {\n T out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is an integer type.", "invalids": "int main() { how_many_times<float>(\"\", \"x\"); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nT how_many_times(std::string str, std::string substring) {\n T out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is an integer type.", "starter_code": "int how_many_times(std::string str, std::string substring) {\n int out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "task_id": "HEP/18", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(how_many_times<_type_>(\"\", \"x\") == (_type_)0); \\\n ASSERT(how_many_times<_type_>(\"xyxyxyx\", \"x\") == (_type_)4); \\\n ASSERT(how_many_times<_type_>(\"cacacacac\", \"cac\") == (_type_)4); \\\n ASSERT(how_many_times<_type_>(\"john doe\", \"john\") == (_type_)1); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(unsigned);\n TEST_ON_TYPE(unsigned long long);\n TEST_ON_TYPE(short);\n}\n"}
19
- {"base_canonical_solution": "template <typename T>\nstd::vector<T> find_closest_elements(std::vector<T> numbers) {\n std::vector<T> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "base_prompt": "Make the following function generic for the value type of the vector parameter and vector return value.", "concepts_canonical_solution": "template <std::floating_point T>\nstd::vector<T> find_closest_elements(std::vector<T> numbers) {\n std::vector<T> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a floating point type.", "invalids": "int main() { find_closest_elements(std::vector<int>{1, 2, 3, 4, 5}); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>\nstd::vector<T> find_closest_elements(std::vector<T> numbers) {\n std::vector<T> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a floating point type.", "starter_code": "std::vector<float> find_closest_elements(std::vector<float> numbers) {\n std::vector<float> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "task_id": "HEP/20", "tests": "template <typename T>\nbool issame(std::vector<T> a, vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (std::abs(a[i] - b[i]) > 1e-4) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 3.9, 4.0, 5.0, 2.2}), \\\n _type_{3.9, 4.0})); \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 5.9, 4.0, 5.0}), \\\n _type_{5.0, 5.9})); \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 3.0, 4.0, 5.0, 2.2}), \\\n _type_{2.0, 2.2})); \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}), \\\n _type_{2.0, 2.0})); \\\n ASSERT(issame(find_closest_elements(_type_{1.1, 2.2, 3.1, 4.1, 5.1}), \\\n _type_{2.2, 3.1})); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(float);\n TEST_ON_TYPE(double);\n}\n"}
20
- {"base_canonical_solution": "template <typename T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "base_prompt": "Make the following function generic for the value type of the vector parameter and vector return value.", "concepts_canonical_solution": "template <std::floating_point T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a floating point type.", "invalids": "int main() { rescale_to_unit(std::vector<int>{1, 2, 3}); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a floating point type.", "starter_code": "std::vector<float> rescale_to_unit(std::vector<float> numbers) {\n float min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "task_id": "HEP/21", "tests": "template <typename T>\nbool issame(std::vector<T> a, vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (std::abs(a[i] - b[i]) > 1e-4) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 49.9}), _type_{0.0, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{100.0, 49.9}), _type_{1.0, 0.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{1.0, 2.0, 3.0, 4.0, 5.0}), \\\n _type_{0.0, 0.25, 0.5, 0.75, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 1.0, 5.0, 3.0, 4.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n ASSERT(issame(rescale_to_unit(_type_{12.0, 11.0, 15.0, 13.0, 14.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<float>);\n TEST_ON_TYPE(std::vector<double>);\n}\n"}
 
16
  {"base_canonical_solution": "template <typename T>\nint count_distinct_characters(T str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "base_prompt": "Make the following function generic for the parameter `str`.", "concepts_canonical_solution": "template <typename T>\n requires std::same_as<typename T::value_type, char>\nint count_distinct_characters(T str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a sequenced container of value type character.", "invalids": "int main() { count_distinct_characters(std::vector<int>{}); }", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<std::is_same_v<typename T::value_type, char>, int> = 0>\nint count_distinct_characters(T str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a sequenced container of value type character.", "starter_code": "int count_distinct_characters(std::string str) {\n std::vector<char> distinct = {};\n std::transform(str.begin(), str.end(), str.begin(), ::tolower);\n for (int i = 0; i < str.size(); i++) {\n bool isin = false;\n for (int j = 0; j < distinct.size(); j++)\n if (distinct[j] == str[i]) isin = true;\n if (isin == false) distinct.push_back(str[i]);\n }\n return distinct.size();\n}", "task_id": "HEP/16", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\nint main() {\n ASSERT(count_distinct_characters(std::string{\"\"}) == 0);\n ASSERT(count_distinct_characters(std::string{\"abcde\"}) == 5);\n ASSERT(count_distinct_characters(std::string{\"abcdecadeCADE\"}) == 5);\n ASSERT(count_distinct_characters(std::string{\"aaaaAAAAaaaa\"}) == 1);\n ASSERT(count_distinct_characters(std::string{\"Jerry jERRY JeRRRY\"}) == 5);\n\n ASSERT(count_distinct_characters(std::vector<char>{}) == 0);\n ASSERT(count_distinct_characters(\n std::vector<char>{'a', 'b', 'c', 'd', 'e'}) == 5);\n ASSERT(count_distinct_characters(std::vector<char>{'a', 'b', 'c', 'd', 'e',\n 'c', 'a', 'd', 'e', 'C',\n 'A', 'D', 'E'}) == 5);\n ASSERT(count_distinct_characters(std::vector<char>{\n 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a'}) == 1);\n ASSERT(count_distinct_characters(\n std::vector<char>{'J', 'e', 'r', 'r', 'y', ' ', 'j', 'E', 'R', 'R',\n 'Y', ' ', 'J', 'e', 'R', 'R', 'R', 'Y'}) == 5);\n}\n"}
17
  {"base_canonical_solution": "template <typename T>\nT parse_music(std::string music_string) {\n std::string current = \"\";\n T out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "base_prompt": "Make the following function generic for the return type.", "concepts_canonical_solution": "template <typename T>\n requires requires(T& t, int v) {\n { t.push_back(v) };\n }\nT parse_music(std::string music_string) {\n std::string current = \"\";\n T out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a container of int that can be pushed back into.", "invalids": "int main() { parse_music(float{3.0}) }", "sfinae_canonical_solution": "template <typename T,\n typename = std::void_t<\n decltype(std::declval<T&>().push_back(std::declval<int>()))>>\nT parse_music(std::string music_string) {\n std::string current = \"\";\n T out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a container of int that can be pushed back into.", "starter_code": "std::vector<int> parse_music(std::string music_string) {\n std::string current = \"\";\n std::vector<int> out = {};\n if (music_string.size() > 0) music_string = music_string + ' ';\n for (int i = 0; i < music_string.length(); i++) {\n if (music_string[i] == ' ') {\n if (current == \"o\") out.push_back(4);\n if (current == \"o|\") out.push_back(2);\n if (current == \".|\") out.push_back(1);\n current = \"\";\n } else\n current += music_string[i];\n }\n return out;\n}", "task_id": "HEP/17", "tests": "\ntemplate <typename T>\nbool issame(T a, T b) {\n if (a.size() != b.size()) return false;\n return std::equal(a.begin(), a.end(), b.begin());\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(parse_music<_type_>(\"\"), _type_{})); \\\n ASSERT(issame(parse_music<_type_>(\"o o o o\"), _type_{4, 4, 4, 4})); \\\n ASSERT(issame(parse_music<_type_>(\".| .| .| .|\"), _type_{1, 1, 1, 1})); \\\n ASSERT(issame(parse_music<_type_>(\"o| o| .| .| o o o o\"), \\\n _type_{2, 2, 1, 1, 4, 4, 4, 4})); \\\n ASSERT(issame(parse_music<_type_>(\"o| .| o| .| o o| o o|\"), \\\n _type_{2, 1, 2, 1, 4, 2, 4, 2})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<int>);\n TEST_ON_TYPE(std::deque<int>);\n TEST_ON_TYPE(std::list<int>);\n}\n"}
18
  {"base_canonical_solution": "template <typename T>\nT how_many_times(std::string str, std::string substring) {\n T out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "base_prompt": "Make the following function generic for the return value.", "concepts_canonical_solution": "template <std::integral T>\nT how_many_times(std::string str, std::string substring) {\n T out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is an integer type.", "invalids": "int main() { how_many_times<float>(\"\", \"x\"); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nT how_many_times(std::string str, std::string substring) {\n T out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is an integer type.", "starter_code": "int how_many_times(std::string str, std::string substring) {\n int out = 0;\n if (str.length() == 0) return 0;\n for (int i = 0; i <= str.length() - substring.length(); i++)\n if (str.substr(i, substring.length()) == substring) out += 1;\n return out;\n}", "task_id": "HEP/18", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(how_many_times<_type_>(\"\", \"x\") == (_type_)0); \\\n ASSERT(how_many_times<_type_>(\"xyxyxyx\", \"x\") == (_type_)4); \\\n ASSERT(how_many_times<_type_>(\"cacacacac\", \"cac\") == (_type_)4); \\\n ASSERT(how_many_times<_type_>(\"john doe\", \"john\") == (_type_)1); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(unsigned);\n TEST_ON_TYPE(unsigned long long);\n TEST_ON_TYPE(short);\n}\n"}
19
+ {"base_canonical_solution": "template <typename T>\nstd::vector<T> find_closest_elements(std::vector<T> numbers) {\n std::vector<T> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "base_prompt": "Make the following function generic for the value type of the vector parameter and vector return value.", "concepts_canonical_solution": "template <std::floating_point T>\nstd::vector<T> find_closest_elements(std::vector<T> numbers) {\n std::vector<T> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a floating point type.", "invalids": "int main() { find_closest_elements(std::vector<int>{1, 2, 3, 4, 5}); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>\nstd::vector<T> find_closest_elements(std::vector<T> numbers) {\n std::vector<T> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a floating point type.", "starter_code": "std::vector<float> find_closest_elements(std::vector<float> numbers) {\n std::vector<float> out = {};\n for (int i = 0; i < numbers.size(); i++) {\n for (int j = i + 1; j < numbers.size(); j++) {\n if (out.size() == 0 ||\n std::abs(numbers[i] - numbers[j]) < std::abs(out[0] - out[1])) {\n out = {numbers[i], numbers[j]};\n }\n }\n }\n if (out[0] > out[1]) {\n out = {out[1], out[0]};\n }\n return out;\n}", "task_id": "HEP/20", "tests": "template <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (std::abs(a[i] - b[i]) > 1e-4) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 3.9, 4.0, 5.0, 2.2}), \\\n _type_{3.9, 4.0})); \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 5.9, 4.0, 5.0}), \\\n _type_{5.0, 5.9})); \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 3.0, 4.0, 5.0, 2.2}), \\\n _type_{2.0, 2.2})); \\\n ASSERT(issame(find_closest_elements(_type_{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}), \\\n _type_{2.0, 2.0})); \\\n ASSERT(issame(find_closest_elements(_type_{1.1, 2.2, 3.1, 4.1, 5.1}), \\\n _type_{2.2, 3.1})); \\\n \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(float);\n TEST_ON_TYPE(double);\n}\n"}
20
+ {"base_canonical_solution": "template <typename T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "base_prompt": "Make the following function generic for the value type of the vector parameter and vector return value.", "concepts_canonical_solution": "template <std::floating_point T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a floating point type.", "invalids": "int main() { rescale_to_unit(std::vector<int>{1, 2, 3}); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a floating point type.", "starter_code": "std::vector<float> rescale_to_unit(std::vector<float> numbers) {\n float min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "task_id": "HEP/21", "tests": "template <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (std::abs(a[i] - b[i]) > 1e-4) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 49.9}), _type_{0.0, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{100.0, 49.9}), _type_{1.0, 0.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{1.0, 2.0, 3.0, 4.0, 5.0}), \\\n _type_{0.0, 0.25, 0.5, 0.75, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 1.0, 5.0, 3.0, 4.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n ASSERT(issame(rescale_to_unit(_type_{12.0, 11.0, 15.0, 13.0, 14.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<float>);\n TEST_ON_TYPE(std::vector<double>);\n}\n"}