Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Nested For loop help?

Name: Anonymous 2014-11-12 2:55

I need help with a For loop.

Using only For loops and a print function, let's say I wanted to print something like:

# # # # # #

Where the #'s and " "'s (spaces) are printed by a print function, one character at a time.

Notice how there's three spaces between the first and last sets of #'s?

How the heck can I get the For loops to only print three characters between the first and last #'s, but print six spaces for the inner ones?

Name: Anonymous 2014-11-12 9:15

I did this by experiment hope it helps :)
> (define (gen x) (+ (* 2.24429 (sin x)) (* -1.02712 (cos x)) 4.18379))
> (define (flip n) (if (= 0 (mod n 2)) floor ceiling))
> (define (pad n) (begin (write-char #\space) (if (> (- n 1) 0) (pad (- n 1 )))))
> (define (loop n) (begin (write-char #\#) (if (< n 5) (begin (pad ((flip n) (gen n))) (loop (+ n 1))))))
> (define (hashes) (loop 0))
> (hashes)
# # # # # #

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List