(newLISP) 로또 번호 생성 In newLISP (slice (randomize (sequence 1 45)) 0 6) ; 로또 1등이 얼마나 되기 어려운지 실험 (define (lotto) (slice (randomize (sequence 1 45)) 0 6)) (let (i 0) (while (!= n '(1 2 3 4 5 6)) (++ i) (setq n (lotto)) (println i " " n))) My Computer Programs 2013.07.26
(Paren) 로또 번호 생성 In Paren (set contains? (fn (x lst) (set found false) (set i (dec (length lst))) (while (&& (>= i 0) (! found)) (when (== x (nth i lst)) (set found true)) (-- i)) found)) (set lotto (fn () (set r (list)) (while (< (length r) 6) (set x (inc (int (* (rand) 45)))) (when (! (contains? x r)) (set r (cons x r)))) (prn r))) (lotto) My Computer Programs 2013.07.09
(Parenjs) 로또 번호 생성 In Parenjs (set nums []) (set r []) (while (< r.length 6) (set n (floor (inc (* (rand) 45)))) (when (! nums[n]) (set nums[n] true) (r.push n))) (r.sort -) My Computer Programs 2013.06.17
(Racket) 로또 번호 생성 #lang racket (let loop ([r (set)]) (cond [(>= (set-count r) 6) (display r)] [else (loop (set-add r (add1 (random 45))))])) My Computer Programs 2012.09.01
(Go) 로또 번호 생성 package main import ( "fmt" "math/rand" "time" ) func main() { r := map[int]bool{} rand.Seed(time.Now().UnixNano()) for len(r) < 6 { r[rand.Intn(45)+1] = true } for x := range r { fmt.Println(x) } } My Computer Programs 2012.08.27
(Javascript) 로또 번호 생성 nums = []; r = []; while (r.length < 6) { n = Math.floor(Math.random() * 45 + 1); if (!nums[n]) { nums[n] = true; r.push(n); } } r.sort(function(a,b){return a-b}); document.writeln(r); Output: My Computer Programs 2012.08.27
(Python) 로또 번호 생성 import random; print(sorted(random.sample(range(1,46),6))) My Computer Programs 2012.08.26
(Java) 로또 번호 생성 import java.util.TreeSet; public class Lotto { public static void main(String[] args) { for (int x : lottoNums()) System.out.print(x + " "); } public static TreeSet lottoNums() { TreeSet r = new TreeSet(); while (r.size() < 6) r.add((int) (Math.random() * 45 + 1)); return r; } } My Computer Programs 2012.08.26