nicolasff (owner)

Fork Of

gist: 113331 by highwind 청기백기 게임 명령문 Generator

Revisions

gist: 113370 Download_button fork
public
Public Clone URL: git://gist.github.com/113370.git
Embed All Files: show embed
README #
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
청기백기 게임 명령문 Generator.
 
So far implemented in ...
- Python 2.5
- Python 3.0
- Ruby
- Java
- Perl
 
 
To be implemented in ...
- C
- haskell
- lisp (maybe clojure?)
- objective c
- C#
- D
- Lua
 
 
Q&A
---
Q: What is this?
A: All the programs here outputs list of randomly generated Korean flag game commands.
 
Q: Why?
A: Because I needed it for my church picnic.
 
Q: I mean, why so many languages?
A: Why not? It's kinda fun.
 
Q: Can I suggest a language?
A: Sure.
 
Q: Can implement it in a language?
A: Sure.
 
Q: This Q&A seems pretty pointless.
A: That's not a question.
 
flags.2.5.py #
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/python
# This Python file uses the following encoding: utf-8
import sys, random, os
 
data = [[u"청기", u"백기", u"둘다"], [u"올", u"내"], [u"려",u"려",u"리지마"]]
 
try:
    for i in range(int(sys.argv[1])):
        print "".join([random.choice(d) for d in data])
except Exception, e:
    sys.stderr.write("Usage: python %s n\n" % os.path.basename(__file__))
 
flags.3.0.py #
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/local/bin/python3.0
from sys import argv
import random, os
 
data = [["청기", "백기", "둘다"], ["올", "내"], ["려","려","리지마"]]
 
try:
    for i in range(int(argv[1])):
        print(*[random.choice(d) for d in data], sep='')
except Exception as e:
    sys.stderr.write("Usage: python %s n\n" % os.path.basename(__file__))
 
flags.c #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char const* argv[]) {
    int n;
    if (argc < 2 || (n = strtol(argv[1], NULL, 10)) == 0) {
        perror("Usage: flags n");
    }
    for (n; n > 0; n--) {
 
    }
    
    return 0;
}
 
flags.hs #
1
2
3
4
5
6
7
8
9
10
11
12
import System.Random
import Codec.Binary.UTF8.String
 
flags = [["청기", "백기", "둘다"], ["올", "내"], ["려","려","리지마"]]
 
main = do
choices <- mapM getRandom flags
putStrLn $ concatMap encodeString choices
 
getRandom list = do
position <- randomRIO (0, length list - 1)
return $ list !! position
Flags.java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
 
public class Flags {
    public static void main (String [] args) {
        ArrayList<ArrayList> data = new ArrayList<ArrayList>();
        data.add(new ArrayList<String>(Arrays.asList("청기", "백기", "둘다")));
        data.add(new ArrayList<String>(Arrays.asList("올", "내")));
        data.add(new ArrayList<String>(Arrays.asList("려","려","리지마")));
        Random r = new Random();
        try {
            for (int i = 0; i < Integer.parseInt(args[0]); i++) {
                for (ArrayList d : data) {
                    System.out.print(d.get(r.nextInt(d.size())));
                }
                System.out.println();
            }
        } catch (Exception e) {
            System.err.println("Usage: java Flags n");
        }
    }
}
 
flags.pl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl
use File::Basename;
 
my @data = (["청기", "백기", "둘다"], ["올", "내"], ["려","려","리지마"]);
 
for my $i (1..$ARGV[0]) {
    foreach my $d (@data) { print $d->[rand @{ $d }]; }
    print "\n";
}
 
if (!($ARGV[0] =~ /^\d+$/)) {
    print STDERR "Usage: perl ", basename(__FILE__), " n\n";
}
 
flags.rb #
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/ruby
data = [["청기", "백기", "둘다"], ["올", "내"], ["려","려","리지마"]]
 
ARGV[0].to_i.times do
  data.each {|d| print d[rand(d.length)]}
  puts
end
 
$stderr.puts "Usage: ruby #{File.basename(__FILE__)} n" if ARGV[0].to_i == 0