-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathch2-power_unary.cpp
43 lines (38 loc) · 954 Bytes
/
ch2-power_unary.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <sstream>
#include <string>
#include "my_intrinsics.h"
#include "my_type_functions.h"
using namespace std;
template<typename F, typename N>
requires(Transformation(F) && Integer(N))
Domain(F) power_unary(Domain(F) x, N n, F f)
{
// Preconditions:
// - n >= 0
// - (forall i in N) 0 < i <= n implies f^i(x) is defined
while (n > N(0)) {
x = f(x);
n = n - N(1);
}
return x;
}
string heighway_dragon_step(string input) {
stringstream appender;
for (int i = 0; i < input.length(); i++) {
switch(input[i]) {
case 'a':
appender << "aRbFR";
break;
case 'b':
appender << "LFaLb";
break;
default:
appender << input[i];
}
}
return appender.str();
}
int main() {
cout << power_unary("Fa", 10, heighway_dragon_step).length() << endl;
}