Created
May 18, 2009 05:05
-
-
Save timothykim/113331 to your computer and use it in GitHub Desktop.
청기백기 게임 명령문 Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
청기백기 게임 명령문 Generator. | |
So far implemented in ... | |
- Python 2.5 : 3 lines | |
- Python 3.0 : 3 lines | |
- Ruby : 2 lines | |
- Java : 9 lines | |
- Perl : 3 lines | |
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 I implement it in a language? | |
A: Sure. | |
Q: This Q&A seems pretty pointless. | |
A: That's not a question. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# This Python file uses the following encoding: utf-8 | |
from sys import argv | |
import sys, random, re | |
if len(argv) < 2 or not re.match(r"^\d+$", sys.argv[1]): | |
sys.stderr.write("Usage: python %s n\n" % sys.argv[0]) | |
exit(1) | |
#code start | |
data = [[u"청기", u"백기", u"둘다"], [u"올", u"내"], [u"려",u"려",u"리지마"]] | |
for i in range(int(sys.argv[1])): | |
print "".join([random.choice(d) for d in data]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3.0 | |
from sys import argv | |
import random, re, sys | |
if len(argv) < 2 or not re.match(r"^\d+$", sys.argv[1]): | |
sys.stderr.write("Usage: python %s n\n" % sys.argv[0]) | |
exit(1) | |
#code start | |
data = [["청기", "백기", "둘다"], ["올", "내"], ["려","려","리지마"]] | |
for i in range(int(sys.argv[1])): | |
print(*[random.choice(d) for d in data], sep='') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
random_choice d = d!!length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Random; | |
import java.util.regex.Pattern; | |
public class Flags { | |
public static void main (String [] args) { | |
if (args.length < 1 || !Pattern.matches("^\\d+$", args[0])) { | |
System.err.println("Usage: java Flags n"); | |
System.exit(1); | |
} | |
//code start | |
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(); | |
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use File::Basename; | |
die "Usage: perl " , basename(__FILE__), " n\n" if (!($ARGV[0] =~ /^\d+$/)); | |
#code start | |
my @data = ([qw/청기 백기 둘다/],[qw/올 내/],[qw/려 려 리지마/]); | |
local $\ = "\n"; | |
print map { @$_[rand @$_] } @data for 1..$ARGV[0]; | |
#code credit to aero from KLDP - http://kldp.org/node/105514#comment-488207 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
abort "Usage: ruby #{File.basename(__FILE__)} n" if ARGV[0].to_i == 0 | |
#code start | |
data = [["청기", "백기", "둘다"], ["올", "내"], ["려","려","리지마"]] | |
ARGV[0].to_i.times {puts data.collect {|d| d[rand(d.length)]}.join} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment