File tree Expand file tree Collapse file tree 5 files changed +77
-1
lines changed
Expand file tree Collapse file tree 5 files changed +77
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ This repository is intended as:
88* A interview‑prep playground
99* A reference for ** concurrency, synchronization, low‑level and modern C++ techniques**
1010* A growing set of ** self‑contained, buildable examples**
11- * A collection of more useful examples than leetcode puzzles.
11+ * A collection of more useful examples (and CLI tools) than leetcode puzzles.
1212
1313Examples include (and will expand to):
1414
@@ -28,6 +28,8 @@ Examples include (and will expand to):
2828* Performance‑oriented C++ idioms
2929* Algorithms
3030 * [ integer-factorization] ( ./integer-factorization/ )
31+ * Encoding
32+ * [ rot47] ( ./rot47/ )
3133* OOP
3234 * [ virtual-interface] ( ./virtual-interface/ )
3335
Original file line number Diff line number Diff line change 1+ # pull in shared compiler settings
2+ include ../common.mk
3+
4+ # per-example flags
5+ # CXXFLAGS += -pthread
6+
7+ # # get it from the folder name
8+ TARGET := $(notdir $(CURDIR ) )
9+ SRCS := $(wildcard * .cpp)
10+ OBJS := $(SRCS:.cpp=.o )
11+
12+ all : $(TARGET )
13+
14+ $(TARGET ) : $(OBJS )
15+ $(CXX ) $(CXXFLAGS ) -o $@ $^
16+
17+ % .o : % .cpp
18+ $(CXX ) $(CXXFLAGS ) -c $< -o $@
19+
20+ run : $(TARGET )
21+ ./$(TARGET ) $(ARGS )
22+
23+ clean :
24+ rm -f $(OBJS ) $(TARGET )
25+
26+ # Delegates to top-level Makefile
27+ check-format :
28+ $(MAKE ) -f ../Makefile check-format DIR=$(CURDIR )
29+
30+ .PHONY : all clean run check-format
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < string>
3+ #include < string_view>
4+ #include < ranges>
5+
6+ [[nodiscard]]
7+ std::string
8+ rot47 (std::string_view input)
9+ {
10+ auto transform = [](char c) { return (c >= 33 && c <= 126 ) ? static_cast <char >(33 + ((c - 33 + 47 ) % 94 )) : c; };
11+
12+ std::string output;
13+ output.reserve (input.size ());
14+
15+ for (char c : input | std::views::transform (transform)) {
16+ output.push_back (c);
17+ }
18+
19+ return output;
20+ }
21+
22+ int
23+ main (int argc, char * argv[])
24+ {
25+ for (int i = 1 ; i < argc; ++i) {
26+ std::cout << rot47 (argv[i]);
27+
28+ if (i + 1 < argc) {
29+ std::cout << ' ' ;
30+ }
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -ex
4+
5+ ./rot47
6+
7+ helloworld=$( ./rot47 ' w6==@ (@C=5P' )
8+
9+ if [ " $helloworld " != " Hello World!" ]; then
10+ echo " Test failed: expected 'Hello World!' but got '$helloworld '"
11+ exit 1
12+ fi
You can’t perform that action at this time.
0 commit comments