[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/qM69avYY    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Dec 9:
; stepwise program development: a heuristic algorithm

(define-syntax while
  (syntax-rules ()
    ((while pred? body ...)
      (do () ((not pred?)) body ...))))

(define-syntax repeat
  (syntax-rules (while until)
    ((repeat body ... (while pred?))
      (let loop () body ...
        (when pred? (loop))))
    ((repeat body ... (until pred?))
      (let loop () body ...
        (unless pred? (loop))))))

(define (succ c)
  (integer->char
    (+ (char->integer c) 1)))

(define (wirth n)

  (let ((s (make-vector (+ n 1) #f))
        (m 0) (good #f))

    (define (extend)
      (set! m (+ m 1))
      (vector-set! s m #\1))

    (define (change)
      (while (char=? (vector-ref s m) #\3)
        (set! m (- m 1)))
      (vector-set! s m (succ (vector-ref s m))))

    (define (check)
      (let ((i 0) (l 0) (mhalf 0))
        (set! good #t)
        (set! l 0)
        (set! mhalf (quotient m 2))
        (while (and good (< l mhalf))
          (set! l (+ l 1))
          (set! i 0)
          (repeat
            (set! good
              (not (char=?
                (vector-ref s (- m i))
                (vector-ref s (- m l i)))))
            (set! i (+ i 1))
            (until (or good (= i l)))))))

    (define (print)
      (do ((i 1 (+ i 1))) ((< n i))
        (display (vector-ref s i)))
      (newline))

    (set! m 2)
    (vector-set! s 1 #\1)
    (vector-set! s 2 #\2)
    (set! good #t)
    (repeat
      (if good
          (if (= m n)
              (begin (print) (change))
              (extend))
          (change))
      (check)
      (until (= m 2)))))

(wirth 5) (newline)
(wirth 12) (newline)
(wirth 20)


Output:
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
12131
12132
12312
12313
12321

121312313212
121312313213
121312313231
121312321231
121312321312
121312321323
121321231213
121321231321
121321231323
121321232131
121321232132
121323121312
121323121321
121323123212
121323123213
121323132123
121323132131
123121312313
123121312321
123121321231
123121321232
123121323121
123121323123
123121323132
123132123121
123132123213
123132131213
123132131231
123132131232
123132312131
123132312132
123132312321
123212312131
123212312132
123212313212
123212313213
123212313231
123213121321
123213121323
123213123132
123213123212
123213231213
123213231232
123213231321

12131231321231213123
12131231321231213212
12131231321231213231
12131231321232131213
12131231321232131231
12131231321232131232
12131231321232132312
12131231321232132313
12131231321312132123
12131231321312132312
12131231321312132313
12131231321312321231
12131231321312321323
12131231323121312313
12131231323121312321
12131231323121321231
12131231323121321232
12131231323121323132
12131231323123212312
12131231323123212313
12131231323123213121
12131231323123213123
12131231323123213231
12131232123121312313
12131232123121312321
12131232123121321231
12131232123121321232
12131232123121323121
12131232123121323123
12131232123121323132
12131232123132123213
12131232123132131213
12131232123132131231
12131232123132131232
12131232123132312131
12131232123132312132
12131232123132312321
12131232131213212312
12131232131213212313
12131232131213212321
12131232131213231213
12131232131213231232
12131232131213231321
12131232132312131231
12131232132312131232
12131232132312132123
12131232132312321231
12131232132312321312
12131232132313212312
12131232132313212313
12131232132313212321
12131232132313213121
12131232132313213123
12132123121312313212
12132123121312313213
12132123121312313231
12132123121312321231
12132123121312321312
12132123121312321323
12132123121323123212
12132123121323123213
12132123121323132123
12132123121323132131
12132123132131213212
12132123132131213231
12132123132131231321
12132123132131231323
12132123132131232123
12132123132131232131
12132123132131232132
12132123132312131231
12132123132312131232
12132123132312132123
12132123132312132313
12132123132312321231
12132123132312321312
12132123132312321323
12132123213121321231
12132123213121321232
12132123213121323121
12132123213121323123
12132123213121323132
12132123213123132123
12132123213123132131
12132123213123132312
12132123213123212312
12132123213123212313
12132123213231213123
12132123213231213212
12132123213231232123
12132123213231232131
12132123213231232132
12132123213231321231
12132123213231321232
12132123213231321312
12132312131231321231
12132312131231321232
12132312131231321312
12132312131231323121
12132312131231323123
12132312131232123121
12132312131232123132
12132312131232131213
12132312131232132312
12132312131232132313
12132312132123121312
12132312132123121323
12132312132123132131
12132312132123132312
12132312132123213121
12132312132123213123
12132312132123213231
12132312321231213123
12132312321231213212
12132312321231213231
12132312321231321232
12132312321231321312
12132312321231323121
12132312321231323123
12132312321312132123
12132312321312132312
12132312321312132313
12132312321312313212
12132312321312313213
12132312321312313231
12132312321323121312
12132312321323121321
12132312321323121323
12132312321323132123
12132312321323132131
12132313212312131231
12132313212312131232
12132313212312132123
12132313212312132312
12132313212312132313
12132313212313231213
12132313212313231232
12132313212321312132
12132313212321312313
12132313212321312321
12132313212321323121
12132313212321323123
12132313212321323132
12132313213121321231
12132313213121321232
12132313213121323121
12132313213121323123
12132313213121323132
12132313213123132123
12132313213123132312
12132313213123212312
12132313213123212313
12132313213123213231
12312131231321231213
12312131231321232131
12312131231321232132
12312131231321312132
12312131231321312321
12312131231323121312
12312131231323121321
12312131231323121323
12312131231323123212
12312131231323123213
12312131232123121312
12312131232123121321
12312131232123121323
12312131232123132123
12312131232123132131
12312131232123132312
12312131232131213212
12312131232131213231
12312131232132312131
12312131232132312132
12312131232132312321
12312131232132313212
12312131232132313213
12312132123121312313
12312132123121312321
12312132123132131213
12312132123132131231
12312132123132131232
12312132123132312131
12312132123132312132
12312132123132312321
12312132123213121321
12312132123213121323
12312132123213123132
12312132123213123212
12312132123213231213
12312132123213231232
12312132123213231321
12312132312321231213
12312132312321231321
12312132312321231323
12312132312321312132
12312132312321312313
12312132312321323121
12312132312321323132
12312132313212312131
12312132313212312132
12312132313212313231
12312132313212321312
12312132313212321323
12312132313213121321
12312132313213121323
12312132313213123132
12312132313213123212
12312132313213123213
12313212312131231321
12313212312131231323
12313212312131232123
12313212312131232131
12313212312131232132
12313212312132123132
12313212312132123213
12313212312132312321
12313212312132313212
12313212312132313213
12313212321312132123
12313212321312132312
12313212321312132313
12313212321312313212
12313212321312313213
12313212321312313231
12313212321312321231
12313212321323121312
12313212321323121321
12313212321323121323
12313212321323123212
12313212321323123213
12313212321323132123
12313212321323132131
12313213121321231213
12313213121321231321
12313213121321231323
12313213121321232131
12313213121321232132
12313213121323121312
12313213121323123212
12313213121323123213
12313213121323132123
12313213121323132131
12313213123132123121
12313213123132123213
12313213123132312131
12313213123132312132
12313213123132312321
12313213123212312131
12313213123212312132
12313213123212313212
12313213123212313213
12313213123212313231
12313213123213231213
12313213123213231232
12313213123213231321
12313231213123132123
12313231213123132131
12313231213123132312
12313231213123212312
12313231213123212313
12313231213123213121
12313231213123213231
12313231213212312131
12313231213212312132
12313231213212313212
12313231213212313213
12313231213212313231
12313231213212321312
12313231213212321323
12313231213231321231
12313231213231321232
12313231213231321312
12313231232123121312
12313231232123121321
12313231232123121323
12313231232123132123
12313231232123132131
12313231232123132312
12313231232131213212
12313231232131213231
12313231232131231321
12313231232131231323
12313231232132312131
12313231232132312132
12313231232132313212
12313231232132313213
12321231213123132123
12321231213123132131
12321231213123132312
12321231213123212312
12321231213123212313
12321231213123213121
12321231213123213231
12321231213212313212
12321231213212313213
12321231213212313231
12321231213212321312
12321231213212321323
12321231213231232123
12321231213231232131
12321231213231232132
12321231213231321231
12321231213231321232
12321231213231321312
12321231321232131213
12321231321232131231
12321231321232131232
12321231321232132312
12321231321232132313
12321231321312132123
12321231321312132312
12321231321312132313
12321231321312313212
12321231321312313231
12321231321312321231
12321231321312321323
12321231323121312313
12321231323121312321
12321231323121321231
12321231323121321232
12321231323121323132
12321231323123212312
12321231323123212313
12321231323123213121
12321231323123213123
12321231323123213231
12321312132123121312
12321312132123121321
12321312132123121323
12321312132123132131
12321312132123132312
12321312132123213121
12321312132123213123
12321312132123213231
12321312132312131231
12321312132312131232
12321312132312321231
12321312132312321312
12321312132312321323
12321312132313212312
12321312132313212313
12321312132313212321
12321312132313213121
12321312132313213123
12321312313212312131
12321312313212312132
12321312313212321312
12321312313212321323
12321312313213121321
12321312313213121323
12321312313213123212
12321312313213123213
12321312313231213123
12321312313231213212
12321312313231213231
12321312313231232123
12321312313231232131
12321312313231232132
12321312321231213123
12321312321231213212
12321312321231213231
12321312321231321232
12321312321231321312
12321312321231323121
12321312321231323123
12321323121312313212
12321323121312313213
12321323121312313231
12321323121312321231
12321323121312321312
12321323121312321323
12321323121321231213
12321323121321231321
12321323121321231323
12321323121321232131
12321323121321232132
12321323123212312131
12321323123212312132
12321323123212313212
12321323123212313213
12321323123212313231
12321323123213121321
12321323123213121323
12321323123213123132
12321323132123121312
12321323132123121321
12321323132123121323
12321323132123132312
12321323132123213121
12321323132123213123
12321323132123213231
12321323132131213212
12321323132131213231
12321323132131231321
12321323132131231323
12321323132131232123
12321323132131232131
12321323132131232132


Create a new paste based on this one


Comments: