In Day 3 we are searching substrings for character matches. It is a Saturday morning, and I want to get this finished before I go about my day, so my first step is to write some C++:
// In AoC22BPFunctionLibrary.h
UFUNCTION(BlueprintCallable)
static TArray<int> D03_CountCharacters(const FString& TextIn);
// In AoC22BPFunctionLibrary.cpp
TArray<int> UAoC22BPFunctionLibrary::D03_CountCharacters(const FString& TextIn)
{
TArray<int> Result;
Result.SetNum(53);
for(auto c : TextIn)
{
if (c >= 'a' && c <='z')
{
c = 1 + (c - 'a');
}
else if (c >= 'A' && c <='Z')
{
c = 27 + (c - 'A');
}
ensure(c>=1 && c<=52);
Result[c]++;
}
return Result;
} This converts the letters into the elves priority system, and counts how many of each priority in a string. This is the foundation for everything else, and would be, let us just say inelegant in Blueprint.
Using this we can solve part 1 line by line:

And part 2 in a similar fashion:

Was it cheating to write some of this in C++? Perhaps. I appreciate that for a lot of people Unreal is Blueprint only, and going to C++ is not an option, but for programmers, knowing when to use Blueprint and when you should write some support code in C++ is an important part of Being Good at Unreal.
