Stop PB1, go to 2
This commit is contained in:
parent
8a1eb79841
commit
a892885241
@ -7,7 +7,7 @@ find_package(PkgConfig REQUIRED)
|
|||||||
|
|
||||||
pkg_check_modules(Jemalloc REQUIRED jemalloc)
|
pkg_check_modules(Jemalloc REQUIRED jemalloc)
|
||||||
|
|
||||||
set(LINKER_OPTIONS -Wl,--sort-common,--as-needed,--gc-sections,--strip-all)
|
set(LINKER_OPTIONS -Wl,--sort-common,--as-needed#[[,--gc-sections,--strip-all]])
|
||||||
|
|
||||||
set(COMPILE_FLAGS
|
set(COMPILE_FLAGS
|
||||||
-pipe
|
-pipe
|
||||||
@ -18,24 +18,27 @@ set(COMPILE_FLAGS
|
|||||||
-Wall
|
-Wall
|
||||||
-Wextra
|
-Wextra
|
||||||
-Wpedantic
|
-Wpedantic
|
||||||
-ffunction-sections
|
|
||||||
-fdata-sections
|
|
||||||
-funroll-loops
|
-funroll-loops
|
||||||
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
-fuse-ld=gold
|
||||||
|
|
||||||
)
|
)
|
||||||
set(LINKER_OPTIONS
|
set(LINKER_OPTIONS
|
||||||
${LINKER_OPTIONS}
|
${LINKER_OPTIONS}
|
||||||
-fuse-ld=gold
|
-fuse-ld=gold
|
||||||
)
|
)
|
||||||
|
|
||||||
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
set(LINKER_FLAGS stdc++)
|
||||||
set(COMPILE_FLAGS -stdlib=libc++ -Wmove ${COMPILE_FLAGS} -fwhole-program-vtables)
|
|
||||||
set(LINKER_OPTIONS ${LINKER_OPTIONS} -fwhole-program-vtables)
|
if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
|
||||||
set(LINKER_FLAGS ${LINKER_FLAGS} c++)
|
set(COMPILE_FLAGS
|
||||||
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
${COMPILE_FLAGS}
|
||||||
set(COMPILE_FLAGS ${COMPILE_FLAGS} -fuse-ld=gold -fdevirtualize-at-ltrans)
|
-ffunction-sections
|
||||||
|
-fdata-sections
|
||||||
|
-fdevirtualize-at-ltrans
|
||||||
|
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
||||||
|
)
|
||||||
set(LINKER_OPTIONS ${LINKER_OPTIONS} -fdevirtualize-at-ltrans)
|
set(LINKER_OPTIONS ${LINKER_OPTIONS} -fdevirtualize-at-ltrans)
|
||||||
set(LINKER_FLAGS ${LINKER_FLAGS} stdc++)
|
set(LINKER_FLAGS ${LINKER_FLAGS} ${Jemalloc_LIBRARIES})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
@ -51,9 +54,15 @@ set_target_properties(AdventOfCode2023 pb_1 PROPERTIES
|
|||||||
INTERPROCEDURAL_OPTIMIZATION ON
|
INTERPROCEDURAL_OPTIMIZATION ON
|
||||||
UNITY_BUILD ON
|
UNITY_BUILD ON
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(AdventOfCode2023 PUBLIC $<$<AND:$<CONFIG:Debug>,$<STREQUAL:$<CXX_COMPILER_ID>,GNU>>:_GLIBCXX_DEBUG>)
|
target_compile_definitions(AdventOfCode2023 PUBLIC $<$<AND:$<CONFIG:Debug>,$<STREQUAL:$<CXX_COMPILER_ID>,GNU>>:_GLIBCXX_DEBUG>)
|
||||||
target_compile_definitions(pb_1 PUBLIC $<$<AND:$<CONFIG:Debug>,$<STREQUAL:$<CXX_COMPILER_ID>,GNU>>:_GLIBCXX_DEBUG>)
|
target_compile_definitions(pb_1 PUBLIC $<$<AND:$<CONFIG:Debug>,$<STREQUAL:$<CXX_COMPILER_ID>,GNU>>:_GLIBCXX_DEBUG>)
|
||||||
target_compile_options(AdventOfCode2023 PUBLIC ${COMPILE_OPTIONS})
|
|
||||||
|
target_compile_options(AdventOfCode2023 PUBLIC ${COMPILE_FLAGS})
|
||||||
|
target_compile_options(pb_1 PUBLIC ${COMPILE_FLAGS})
|
||||||
|
|
||||||
target_link_options(AdventOfCode2023 PUBLIC ${LINKER_OPTIONS})
|
target_link_options(AdventOfCode2023 PUBLIC ${LINKER_OPTIONS})
|
||||||
target_link_libraries(AdventOfCode2023 PUBLIC pb_1 ${Jemalloc_LIBRARIES})
|
target_link_options(pb_1 PUBLIC ${LINKER_OPTIONS})
|
||||||
target_link_libraries(pb_1 PUBLIC ${Jemalloc_LIBRARIES})
|
|
||||||
|
target_link_libraries(AdventOfCode2023 PUBLIC pb_1 ${LINKER_FLAGS})
|
||||||
|
target_link_libraries(pb_1 PUBLIC ${LINKER_FLAGS})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
abcone2threexyz
|
|
||||||
two1nine
|
|
||||||
eightwothree
|
eightwothree
|
||||||
|
two1ninethr
|
||||||
|
abcone2threexyz
|
||||||
xtwone3four
|
xtwone3four
|
||||||
4nineeightseven2
|
4nineeightseven2
|
||||||
zoneight234
|
zoneight234
|
||||||
|
@ -96,33 +96,45 @@ namespace pb1 {
|
|||||||
line_with_numbers.reserve(toSearch.size());
|
line_with_numbers.reserve(toSearch.size());
|
||||||
word.reserve(sizeof("seven") - 1);
|
word.reserve(sizeof("seven") - 1);
|
||||||
for (int i = 0; i < toSearch.size(); ++i) {
|
for (int i = 0; i < toSearch.size(); ++i) {
|
||||||
const int second_letter = i + 1, third = i + 2, fourth = i + 3, fifth = i + 4, sixth = i + 5;
|
const std::uint32_t nb_characters_remaining = toSearch.size() - i;
|
||||||
const std::uint32_t nb_characters_remaining = toSearch.size() - i - 1;
|
|
||||||
switch (toSearch[i]) {
|
switch (toSearch[i]) {
|
||||||
case 'o': {
|
case 'o': {
|
||||||
if (nb_characters_remaining < digitLetters[0].size()) {
|
if (nb_characters_remaining >= digitLetters[0].size()) {
|
||||||
line_with_numbers.append(toSearch.substr(i));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
word.append(toSearch.substr(i, digitLetters[0].size()));
|
word.append(toSearch.substr(i, digitLetters[0].size()));
|
||||||
if (!numbersSet.contains(word)) {
|
if (numbersSet.contains(word)) {
|
||||||
const auto pos = word.find_first_of(digits);
|
|
||||||
if (pos != std::string::npos) {
|
|
||||||
line_with_numbers.push_back(word[pos]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
line_with_numbers.push_back(numbersSet.at(word));
|
line_with_numbers.push_back(numbersSet.at(word));
|
||||||
++i;
|
}
|
||||||
}
|
}
|
||||||
word.clear();
|
word.clear();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 't': {
|
case 't': {
|
||||||
if (nb_characters_remaining < digitLetters[2].size()) {
|
if (nb_characters_remaining >= digitLetters[1].size()) {
|
||||||
|
// TODO: problème si on a two mais là ça ajoute + de caractère…
|
||||||
|
const auto number_two = toSearch.substr(i, digitLetters[1].size());
|
||||||
|
const auto number_three = [&]() -> std::string_view {
|
||||||
|
const auto tmp = toSearch.substr(i);
|
||||||
|
if (tmp.size() <= digitLetters[2].size()) {
|
||||||
|
return toSearch.substr(i);
|
||||||
|
} else {
|
||||||
|
return toSearch.substr(i, digitLetters[2].size());
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
if (numbersSet.contains(number_two) or numbersSet.contains(number_three)) {
|
||||||
|
word.append(numbersSet.contains(number_two) ? number_two : number_three);
|
||||||
|
line_with_numbers.push_back(numbersSet.at(word));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
word.clear();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'f': {
|
||||||
|
// length five and four are equal
|
||||||
|
if (nb_characters_remaining < digitLetters[3].size()) {
|
||||||
line_with_numbers.append(toSearch.substr(i));
|
line_with_numbers.append(toSearch.substr(i));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
word.append(toSearch.substr(i, digitLetters[2].size()));
|
word.append(toSearch.substr(i, digitLetters[3].size()));
|
||||||
if (!numbersSet.contains(word)) {
|
if (!numbersSet.contains(word)) {
|
||||||
const auto pos = word.find_first_of(digits);
|
const auto pos = word.find_first_of(digits);
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
@ -130,24 +142,79 @@ namespace pb1 {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
line_with_numbers.push_back(numbersSet.at(word));
|
line_with_numbers.push_back(numbersSet.at(word));
|
||||||
i += 2;
|
|
||||||
}
|
}
|
||||||
word.clear();
|
word.clear();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 's': {
|
||||||
|
if (nb_characters_remaining < digitLetters[6].size()) {
|
||||||
|
line_with_numbers.append(toSearch.substr(i));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto number_six = toSearch.substr(i, digitLetters[5].size());
|
||||||
|
const auto number_seven = toSearch.substr(i, digitLetters[6].size());
|
||||||
|
if (!numbersSet.contains(number_six) and !numbersSet.contains(number_seven)) {
|
||||||
|
const auto pos = number_seven.find_first_of(digits);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
line_with_numbers.push_back(word[pos]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
line_with_numbers.push_back(numbersSet.at(word));
|
||||||
|
}
|
||||||
|
word.clear();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 'e': {
|
||||||
|
if (nb_characters_remaining < digitLetters[7].size()) {
|
||||||
|
line_with_numbers.append(toSearch.substr(i));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
word.append(toSearch.substr(i, digitLetters[7].size()));
|
||||||
|
if (!numbersSet.contains(word)) {
|
||||||
|
const auto pos = word.find_first_of(digits);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
line_with_numbers.push_back(word[pos]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
line_with_numbers.push_back(numbersSet.at(word));
|
||||||
|
}
|
||||||
|
word.clear();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'n': {
|
||||||
|
if (nb_characters_remaining < digitLetters.back().size()) {
|
||||||
|
line_with_numbers.append(toSearch.substr(i));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
word.append(toSearch.substr(i, digitLetters.back().size()));
|
||||||
|
if (!numbersSet.contains(word)) {
|
||||||
|
const auto pos = word.find_first_of(digits);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
line_with_numbers.push_back(word[pos]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
line_with_numbers.push_back(numbersSet.at(word));
|
||||||
|
}
|
||||||
|
word.clear();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9':
|
||||||
|
line_with_numbers.push_back(toSearch[i]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ((toSearch[i] - '0') < 10) {
|
if ((toSearch[i] - '0') < 10) {
|
||||||
line_with_numbers.push_back(toSearch[i]);
|
line_with_numbers.push_back(toSearch[i]);
|
||||||
}
|
}
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!line_with_numbers.empty()) {
|
if (!line_with_numbers.empty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user