Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This repository is intended as:
* A interview‑prep playground
* A reference for **concurrency, synchronization, low‑level and modern C++ techniques**
* A growing set of **self‑contained, buildable examples**
* A collection of more useful examples than leetcode puzzles.
* A collection of more useful examples (and CLI tools) than leetcode puzzles.

Examples include (and will expand to):

Expand All @@ -28,6 +28,8 @@ Examples include (and will expand to):
* Performance‑oriented C++ idioms
* Algorithms
* [integer-factorization](./integer-factorization/)
* Encoding
* [rot47](./rot47/)
* OOP
* [virtual-interface](./virtual-interface/)

Expand Down
30 changes: 30 additions & 0 deletions rot47/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# pull in shared compiler settings
include ../common.mk

# per-example flags
# CXXFLAGS += -pthread

## get it from the folder name
TARGET := $(notdir $(CURDIR))
SRCS := $(wildcard *.cpp)
OBJS := $(SRCS:.cpp=.o)

all: $(TARGET)

$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

run: $(TARGET)
./$(TARGET) $(ARGS)

clean:
rm -f $(OBJS) $(TARGET)

# Delegates to top-level Makefile
check-format:
$(MAKE) -f ../Makefile check-format DIR=$(CURDIR)

.PHONY: all clean run check-format
32 changes: 32 additions & 0 deletions rot47/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <string>
#include <string_view>
#include <ranges>

[[nodiscard]]
std::string
rot47(std::string_view input)
{
auto transform = [](char c) { return (c >= 33 && c <= 126) ? static_cast<char>(33 + ((c - 33 + 47) % 94)) : c; };

std::string output;
output.reserve(input.size());

for (char c : input | std::views::transform(transform)) {
output.push_back(c);
}

return output;
}

int
main(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i) {
std::cout << rot47(argv[i]);

if (i + 1 < argc) {
std::cout << ' ';
}
}
}
12 changes: 12 additions & 0 deletions rot47/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -ex

./rot47

helloworld=$(./rot47 'w6==@ (@C=5P')

if [ "$helloworld" != "Hello World!" ]; then
echo "Test failed: expected 'Hello World!' but got '$helloworld'"
exit 1
fi
Binary file removed virtual-interface/virtual-interface
Binary file not shown.