This post has been edited 1 times, last edit by "jbr" (Jan 18th 2011, 6:43pm)
Source code |
|
1 2 3 4 5 6 7 8 9 10 |
(define (zahlListe zahl) (define (helper zahl res) (if (= zahl 0) res (helper (quotient zahl 10) (cons (remainder zahl 10) res)) ) ) (helper zahl'()) ) (zahlListe 12345) |
Source code |
|
1 2 3 4 5 6 7 8 9 10 |
(define (digit n pos) (let ((n-ziffern (remainder n(expt 10 pos)))) (quotient n-ziffern (expt 10 (- pos 1))) ) ) (define (zahlListe_ zahl) (reverse (map (lambda (i) (digit zahl (+ i 1))) (build-list (string-length (number->string zahl)) *))) ) (zahlListe_ 12345) |
Source code |
|
1 2 3 4 |
(define (zahlListe__ zahl) (map string->number (map string (string->list (number->string zahl)))) ) (zahlListe__ 12345) |
This post has been edited 3 times, last edit by "vogelj" (Jan 19th 2011, 1:05am)
Ok soweit sogut, nur dreht er die liste hierbei nicht um =(
Source code
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 #lang scheme (define (zahlListe zahl) (define (helper zahl res) (if (= zahl 0) res (helper (quotient zahl 10) (cons (remainder zahl 10) res)) ) ) (helper zahl'()) ) (zahlListe 12345) (define (digit n pos) (let ((n-ziffern (remainder n(expt 10 pos)))) (quotient n-ziffern (expt 10 (- pos 1))) ) ) (define (zahlListe_ zahl) (reverse (map (lambda (i) (digit zahl (+ i 1))) (build-list (string-length (number->string zahl)) *))) ) (zahlListe_ 12345) (define (zahlListe__ zahl) (map string->number (map string (string->list (number->string zahl)))) ) (zahlListe__ 12345)
Anzumerken dass das Verhalten von 0 und negativen Zahlen als Eingang unterschiedlich sein müsste.
Source code |
|
1 2 3 4 5 6 7 8 9 10 |
(define (zahlListe zahl) (define (helper zahl res) (if (= zahl 0) (reverse res) (helper (quotient zahl 10) (cons (remainder zahl 10) res)) ) ) (helper zahl'()) ) (zahlListe 123475) |
Source code |
|
1 2 3 4 5 6 7 8 9 10 |
(define (digit n pos) (let ((n-ziffern (remainder n(expt 10 pos)))) (quotient n-ziffern (expt 10 (- pos 1))) ) ) (define (zahlListe_ zahl) (map (lambda (i) (digit zahl (+ i 1))) (build-list (string-length (number->string zahl)) *)) ) (zahlListe_ 123475) |
Source code |
|
1 2 3 4 |
(define (zahlListe__ zahl) (reverse (map string->number (map string (string->list (number->string zahl))))) ) (zahlListe__ 123475) |
Source code |
|
1 2 3 4 |
(digit 1234 1) ;4 (digit 1234 2) ;3 (digit 1234 3) ;2 (digit 1234 4) ;1 |
Source code |
|
1 2 3 4 5 6 7 |
(define (digit_ n pos) (string->number (string (string-ref (number->string n) pos))) ) (digit_ 1234 0) ;1 (digit_ 1234 1) ;2 (digit_ 1234 2) ;3 (digit_ 1234 3) ;4 |
This post has been edited 3 times, last edit by "vogelj" (Jan 19th 2011, 1:05am)
wie wäre es mit
(define (zahl->liste n)
(if (= 0 n) '()
(cons (remainder n 10) (zahl->liste (quotient n 10)))))
oder, wenn die Reihenfolge anders herum sein sollte
(define (zahl->liste n)
(if (= 0 n) '()
(append (zahl->liste (quotient n 10)) (list (remainder n 10)))))
Ist doch gar nicht so schwer, oder??
Source code |
|
1 2 3 |
zahlZuListe 0 = [] zahlZuListe n = let(q, r) = n `quotRem` 10 in zahlZuListe q ++ [r] |
This post has been edited 2 times, last edit by "kiLLroy" (Jan 19th 2011, 1:01am)
Quoted
Man findet immer dort besonders viel Chaos, wo man nach Ordnung sucht. Das Chaos besiegt die Ordnung, weil es besser organisiert ist.
This post has been edited 1 times, last edit by "Kaos" (Jan 19th 2011, 3:54pm)