เรียงสีกิลด์ต่างๆให้ต่อกัน

Magic: The Gathering มี 5 สี จับคู่กันได้ 5 * 4 / 2 = 10 guilds

สำหรับนักสะสมที่ต้องการจะวางการ์ดสองสี ให้เรียงต่อกันอย่างสวยงาม เช่น Boros (Red White) ต่อด้วย Azorius (White blUe) ต่อด้วย Dimir (blUe Black) ต่อด้วย Golgari (Black Green) … สามารถนำผลจากโปรแกรมนี้ไปใช้ได้เลยครับ

import java.util.*;

public class GuildChain {
  public static void main(String[] args) {
    new GuildChain().search();
  }

  String[] a = new String[10];

  void search() {
    a[0] = "WU";
    search(1);
  }

  String[] guild = {
    "WU", "WB", "UB", "UR", "BR", "BG", "RW", "RG", "GW", "GU"
  };

  void search(int depth) {
    if (depth == 10) {
      System.out.println(Arrays.toString(a));
    } else {
      for (String g : guild) {
        if (a[depth - 1].charAt(1) == g.charAt(0) && notIn(g, depth)) {
          a[depth] = g;
          search(depth + 1);
        }
      }
    }
  }
  
  boolean notIn(String g, int depth) {
    for (int i = 0; i < depth; i++) {
      if (a[i].equals(g))
        return false;
    }
    return true;
  }
}

[WU, UB, BR, RW, WB, BG, GU, UR, RG, GW]
[WU, UB, BR, RG, GW, WB, BG, GU, UR, RW]
[WU, UB, BR, RG, GU, UR, RW, WB, BG, GW]
[WU, UB, BG, GW, WB, BR, RG, GU, UR, RW]
[WU, UB, BG, GU, UR, RW, WB, BR, RG, GW]
[WU, UB, BG, GU, UR, RG, GW, WB, BR, RW]
[WU, UR, RW, WB, BR, RG, GU, UB, BG, GW]
[WU, UR, RW, WB, BG, GU, UB, BR, RG, GW]
[WU, UR, RG, GW, WB, BG, GU, UB, BR, RW]
[WU, UR, RG, GU, UB, BR, RW, WB, BG, GW]
[WU, UR, RG, GU, UB, BG, GW, WB, BR, RW]

[WB, BR, RW, WU, UB, BG, GU, UR, RG, GW]
[WB, BR, RW, WU, UR, RG, GU, UB, BG, GW]
[WB, BR, RG, GW, WU, UB, BG, GU, UR, RW]
[WB, BR, RG, GU, UB, BG, GW, WU, UR, RW]
[WB, BR, RG, GU, UR, RW, WU, UB, BG, GW]
[WB, BG, GW, WU, UB, BR, RG, GU, UR, RW]
[WB, BG, GW, WU, UR, RG, GU, UB, BR, RW]
[WB, BG, GU, UB, BR, RW, WU, UR, RG, GW]
[WB, BG, GU, UB, BR, RG, GW, WU, UR, RW]
[WB, BG, GU, UR, RW, WU, UB, BR, RG, GW]
[WB, BG, GU, UR, RG, GW, WU, UB, BR, RW]

[UB, BR, RW, WU, UR, RG, GW, WB, BG, GU]
[UB, BR, RW, WB, BG, GW, WU, UR, RG, GU]
[UB, BR, RW, WB, BG, GU, UR, RG, GW, WU]
[UB, BR, RG, GW, WU, UR, RW, WB, BG, GU]
[UB, BR, RG, GW, WB, BG, GU, UR, RW, WU]
[UB, BR, RG, GU, UR, RW, WB, BG, GW, WU]
[UB, BG, GW, WU, UR, RW, WB, BR, RG, GU]
[UB, BG, GW, WB, BR, RW, WU, UR, RG, GU]
[UB, BG, GW, WB, BR, RG, GU, UR, RW, WU]
[UB, BG, GU, UR, RW, WB, BR, RG, GW, WU]
[UB, BG, GU, UR, RG, GW, WB, BR, RW, WU]

[UR, RW, WU, UB, BR, RG, GW, WB, BG, GU]
[UR, RW, WU, UB, BG, GW, WB, BR, RG, GU]
[UR, RW, WB, BR, RG, GW, WU, UB, BG, GU]
[UR, RW, WB, BR, RG, GU, UB, BG, GW, WU]
[UR, RW, WB, BG, GW, WU, UB, BR, RG, GU]
[UR, RW, WB, BG, GU, UB, BR, RG, GW, WU]
[UR, RG, GW, WU, UB, BR, RW, WB, BG, GU]
[UR, RG, GW, WB, BR, RW, WU, UB, BG, GU]
[UR, RG, GW, WB, BG, GU, UB, BR, RW, WU]
[UR, RG, GU, UB, BR, RW, WB, BG, GW, WU]
[UR, RG, GU, UB, BG, GW, WB, BR, RW, WU]

[BR, RW, WU, UB, BG, GU, UR, RG, GW, WB]
[BR, RW, WU, UR, RG, GW, WB, BG, GU, UB]
[BR, RW, WU, UR, RG, GU, UB, BG, GW, WB]
[BR, RW, WB, BG, GW, WU, UR, RG, GU, UB]
[BR, RW, WB, BG, GU, UR, RG, GW, WU, UB]
[BR, RG, GW, WU, UB, BG, GU, UR, RW, WB]
[BR, RG, GW, WU, UR, RW, WB, BG, GU, UB]
[BR, RG, GW, WB, BG, GU, UR, RW, WU, UB]
[BR, RG, GU, UB, BG, GW, WU, UR, RW, WB]
[BR, RG, GU, UR, RW, WU, UB, BG, GW, WB]
[BR, RG, GU, UR, RW, WB, BG, GW, WU, UB]

[BG, GW, WU, UB, BR, RG, GU, UR, RW, WB]
[BG, GW, WU, UR, RW, WB, BR, RG, GU, UB]
[BG, GW, WU, UR, RG, GU, UB, BR, RW, WB]
[BG, GW, WB, BR, RW, WU, UR, RG, GU, UB]
[BG, GW, WB, BR, RG, GU, UR, RW, WU, UB]
[BG, GU, UB, BR, RW, WU, UR, RG, GW, WB]
[BG, GU, UB, BR, RG, GW, WU, UR, RW, WB]
[BG, GU, UR, RW, WU, UB, BR, RG, GW, WB]
[BG, GU, UR, RW, WB, BR, RG, GW, WU, UB]
[BG, GU, UR, RG, GW, WU, UB, BR, RW, WB]
[BG, GU, UR, RG, GW, WB, BR, RW, WU, UB]

[RW, WU, UB, BR, RG, GW, WB, BG, GU, UR]
[RW, WU, UB, BG, GW, WB, BR, RG, GU, UR]
[RW, WU, UB, BG, GU, UR, RG, GW, WB, BR]
[RW, WU, UR, RG, GW, WB, BG, GU, UB, BR]
[RW, WU, UR, RG, GU, UB, BG, GW, WB, BR]
[RW, WB, BR, RG, GW, WU, UB, BG, GU, UR]
[RW, WB, BR, RG, GU, UB, BG, GW, WU, UR]
[RW, WB, BG, GW, WU, UB, BR, RG, GU, UR]
[RW, WB, BG, GW, WU, UR, RG, GU, UB, BR]
[RW, WB, BG, GU, UB, BR, RG, GW, WU, UR]
[RW, WB, BG, GU, UR, RG, GW, WU, UB, BR]

[RG, GW, WU, UB, BR, RW, WB, BG, GU, UR]
[RG, GW, WU, UB, BG, GU, UR, RW, WB, BR]
[RG, GW, WU, UR, RW, WB, BG, GU, UB, BR]
[RG, GW, WB, BR, RW, WU, UB, BG, GU, UR]
[RG, GW, WB, BG, GU, UB, BR, RW, WU, UR]
[RG, GW, WB, BG, GU, UR, RW, WU, UB, BR]
[RG, GU, UB, BR, RW, WB, BG, GW, WU, UR]
[RG, GU, UB, BG, GW, WU, UR, RW, WB, BR]
[RG, GU, UB, BG, GW, WB, BR, RW, WU, UR]
[RG, GU, UR, RW, WU, UB, BG, GW, WB, BR]
[RG, GU, UR, RW, WB, BG, GW, WU, UB, BR]

[GW, WU, UB, BR, RW, WB, BG, GU, UR, RG]
[GW, WU, UB, BR, RG, GU, UR, RW, WB, BG]
[GW, WU, UB, BG, GU, UR, RW, WB, BR, RG]
[GW, WU, UR, RW, WB, BR, RG, GU, UB, BG]
[GW, WU, UR, RW, WB, BG, GU, UB, BR, RG]
[GW, WU, UR, RG, GU, UB, BR, RW, WB, BG]
[GW, WB, BR, RW, WU, UB, BG, GU, UR, RG]
[GW, WB, BR, RW, WU, UR, RG, GU, UB, BG]
[GW, WB, BR, RG, GU, UR, RW, WU, UB, BG]
[GW, WB, BG, GU, UB, BR, RW, WU, UR, RG]
[GW, WB, BG, GU, UR, RW, WU, UB, BR, RG]

[GU, UB, BR, RW, WU, UR, RG, GW, WB, BG]
[GU, UB, BR, RW, WB, BG, GW, WU, UR, RG]
[GU, UB, BR, RG, GW, WU, UR, RW, WB, BG]
[GU, UB, BG, GW, WU, UR, RW, WB, BR, RG]
[GU, UB, BG, GW, WB, BR, RW, WU, UR, RG]
[GU, UR, RW, WU, UB, BR, RG, GW, WB, BG]
[GU, UR, RW, WU, UB, BG, GW, WB, BR, RG]
[GU, UR, RW, WB, BR, RG, GW, WU, UB, BG]
[GU, UR, RW, WB, BG, GW, WU, UB, BR, RG]
[GU, UR, RG, GW, WU, UB, BR, RW, WB, BG]
[GU, UR, RG, GW, WB, BR, RW, WU, UB, BG]

ผมชอบ

[GW, WU, UR, RG, GU, UB, BR, RW, WB, BG]
[RG, GW, WU, UR, RW, WB, BG, GU, UB, BR]
[RW, WU, UR, RG, GW, WB, BG, GU, UB, BR]
[RW, WU, UR, RG, GU, UB, BG, GW, WB, BR]
[RG, GU, UR, RW, WU, UB, BG, GW, WB, BR]
[GU, UR, RG, GW, WU, UB, BR, RW, WB, BG]

MTG กิลด์คิวบ์

หากจะนำข้อความหรือโค้ดไปใช้ ต้องแสดงที่มา และต้องอนุญาตแบบเดียวกัน

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s