So, funktioniert genau so wie meine anderen beiden Versionen, ist nur im Gegensatz zu denen auch schnell.

Ich hab, gerad bei der "Erweiterungsfunktion" nicht drauf geachtet, ob Überläufe passieren oder nicht, dazu hatte ich nun keine Lust. mehr =)
Läuft aber trotzdem.

Kommentare hab ich weggelassen, bei Fragen fragen, oder meine anderen Versionen anschauen.

Code c:
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
 
 
struct turtle_config {
    unsigned width;
    unsigned height;
    char *sequence;
    
    struct {
        float angle;
        float forward;
    } step;
    
    struct {
        float x, y;
    } start;
    
    char *rules[26];
};
 
 
struct turtle_state {
    float angle;
    float x;
    float y;
};
 
 
void polyline_begin( float x, float y ) {
    printf( "<polyline points=\"%f %f", x, y );
}
 
 
void polyline_end() {
    printf( "\" />" );
}
 
 
void polyline_point( float x, float y ) {
    printf( ",%f %f", x, y );
}
 
 
void svg_begin( unsigned width, unsigned height ) {
    printf(
        "<?xml version='1.0' ?>"
        "<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'"
        "  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>"
        "\n"
        "<svg xmlns='http://www.w3.org/2000/svg' version='1.1'"
        "  width='%u' height='%u' stroke='black' fill='none'>\n",
        width, height );
}
 
void svg_end() {
    printf("</svg>" );
}
 
 
void run( struct turtle_config config ) {
    struct turtle_state state;
    struct turtle_state *memory = NULL;
    
    int memory_size = 0;
    int memory_top = -1;
    
    state.angle = 0;
    state.x = config.start.x;
    state.y = config.start.y;
    
    svg_begin( config.width, config.height );
    polyline_begin( state.x, config.height - state.y );
    
    const char *sequence = config.sequence;
    while( *sequence ) {
        switch( *(sequence++) ) {
            case '+':
                state.angle += config.step.angle;
                break;
            
            case '-':
                state.angle -= config.step.angle;
                break;
            
            case 'F':
                state.x += cos( state.angle ) * config.step.forward;
                state.y += sin( state.angle ) * config.step.forward;
                polyline_point( state.x, config.height - state.y );
                break;
            
            case '[':
                if( memory_top + 1 >= memory_size ) {
                    memory_size += 16;
                    memory = realloc( memory, memory_size * sizeof( struct turtle_state ) );
                }
                
                memory[ ++memory_top ] = state;
                break;
            
            case ']':
                if( memory_top < 0 ) {
                    fprintf( stderr, "Oops, ']' unerwartet, Stack ist leer.\n" );
                    exit( 1 );
                }
                state = memory[ memory_top-- ];
                
                polyline_end();
                polyline_begin( state.x, config.height - state.y );
                
                break;
                
        }
    }
    polyline_end();
    svg_end();
}
 
 
int main( int argc, char *argv[] ) {
    
    struct turtle_config config;
    memset( &config, 0, sizeof( config ) );
    
    scanf( "%u %u\n", &config.width, &config.height );
    scanf( "%f %f\n", &config.start.x, &config.start.y );
    scanf( "%f\n%f\n", &config.step.forward, &config.step.angle );
    
    config.step.angle *= (3.141592f / 180.f);
    
    int length = 1024 * 1024, i = 0;
    config.sequence = malloc( length );
    fgets( config.sequence, length, stdin );
    
    unsigned iterations = 0;
    scanf( "%u\n", &iterations );
    if( iterations ) {
        char *buffer = malloc( length );
        fgets( buffer, length, stdin );
        
        // Simple Regel
        if( buffer[1] != ' ' ) {
            config.rules[ 'F' - 'A' ] = strdup( buffer );
        }
        else
        while( !feof( stdin ) ) {
            char name = buffer[0];
            if( name < 'A' || name > 'Z' || buffer[1] != ' ' )
                break;
            
            if( config.rules[ name - 'A' ] )
                free( config.rules[ name - 'A' ] );
            
            config.rules[ name - 'A' ] = strdup( buffer + 2 );
            fgets( buffer, length, stdin );
        }
        
        
        for( i = 0; i < iterations; i++ ) {
            buffer[0] = 0;
            int index = 0;
            const char *seq = config.sequence;
            
            while( *seq ) {
                if( *seq >= 'A' && *seq <= 'Z' && config.rules[*seq - 'A'] ) {
                
                    strcpy( buffer + index, config.rules[*seq - 'A'] );
                    index += strlen( config.rules[ *seq - 'A' ] );
                    
                } else {
                    buffer[ index++ ] = *seq;
                }
                
                ++seq;
            }
            
            free( config.sequence );
            config.sequence = strdup( buffer );
        }
        
    }
    
    run( config );
    
    free( buffer );
    free( config.sequence );
    for( i = 0; i < 26; i++ )
        free( config.rules[i] );
    
    return 0;
}