2010年4月8日 星期四

夢見彌勒佛續行菩薩道 兩樂透億元男 神氣活現|政治新聞|中

夢見彌勒佛續行菩薩道 兩樂透億元男 神氣活現|政治新聞|中

小P:人家夢見彌勒佛中兩億,前幾年,我在夢中夢見六個號碼,
不過沒有呆呆的去簽樂透,但還是追蹤一下樂透開獎,
結果只中一個數字,雖然沒簽,但是我不死心,繼續追綜樂透開獎,
結果下一期又只中一個數字,下下期也只中一個數字,
一直到下下下期,中了三個數字200元,
如果我真的去買,一直買四期也才中200元,
那麼四期各買一注也剛好200元了…
不賺也不賠,大概是上天要我不要作樂透夢了吧。

2010年3月7日 星期日

Richard Ramirez vs 宮崎勤

 

Ricardo Leyva Munoz Ramirez: Big deal. Death always went with the territory. I'll see you at Disneyland 

2009年12月12日 星期六

求職問題:數字拆解(using C#)

//題目:數字拆解
//題目是這樣的:
//3 = 2+1 = 1+1+1 所以3有三種拆法
//4 = 3 + 1 = 2 + 2 = 2 + 1 + 1 = 1 + 1 + 1 + 1 共五種
//5 = 4 + 1 = 3 + 2 = 3 + 1 + 1 = 2 + 2 + 1 = 2 + 1 + 1 + 1 = 1 + 1 +1 +1 +1 //共七種
//依此類推,請問一個指定數字NUM的拆解方法個數有多少個?

//#請計算出Num=40共多少解法,需花多少時間(須印出所有合法解法)
// num = 40, count = 37338, time = 1.188
//收到此信時, 請先回覆 email告知已成功接獲此信.

//請於三天內將撰寫好的程式碼 email 給我

//Answer:
//此code的缺點是速度慢
//C# code
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        public static int num = 40;
        public static int solution = 0;
        static void Main(string[] args)
        {
            DateTime StartTime = DateTime.Now;
            int[] ntable = new int[num];
            int index = 0, rindex = 0;
            int nlength = num;
            for (int i = 0; i < num; i++)
            {
                ntable[i] = 1;
            }
            print(ntable, nlength);
            // top = ntable[0]
            while (nlength != 1)
            {
                while (true)
                {
                    if (index < nlength - 1)//last two element
                    {
                        ntable[index]++;
                        if (0 == index) swapr(ntable, rindex, ref nlength);
                        index++;
                        fixdec(ntable, ref nlength);
                        print(ntable, nlength);
                    }
                    else break;
                }
                rindex = rsnotone(ntable, nlength);
                rindex = found(ntable, ntable[rindex], nlength);
                if (rindex < nlength - 1)//last two element
                {
                    ntable[rindex]++;
                    swapr(ntable, rindex, ref nlength);
                    index = rindex + 1;
                    fixdec(ntable, ref nlength);
                    print(ntable, nlength);
                }
                else if (rindex > 0 && ntable[rindex - 1] < ntable[0])
                {
                    rindex = found(ntable, ntable[rindex - 1], nlength);
                    ntable[rindex]++;
                    swapr(ntable, rindex, ref nlength);
                    index = rindex + 1;
                    fixdec(ntable, ref nlength);
                    print(ntable, nlength);
                }
                else
                {
                    index = 0;
                    rindex = 0;
                }
               
               
            }
            Console.Write("num = ");
            Console.Write(num);
            Console.Write(", count = ");
            Console.Write(solution);
            DateTime StopTime = DateTime.Now;
            TimeSpan duration = StopTime - StartTime;
            Console.Write(", time = ");
            Console.WriteLine(duration);
        }
        static int found(int[] ntable, int value, int nlength)
        {
            int i;
            for (i = 0; i < nlength; i++)
            {
                if(value == ntable[i])break;
            }
            return i;
        }
        //reverse scan and return index that value not equal 1
        static int rsnotone(int[] ntable, int nlength)
        {
            int i;
            for (i = nlength - 1; i >= 0; i--)
            {
                if (ntable[i] != 1) break;
            }
            return i;
        }
        //clean and fix length of ntable
        static void swapr(int[] ntable, int ri, ref int nlength)
        {
            int remain = num;
            for (int i = 0; i <= ri; i++)
            {
                remain -= ntable[i];
            }
            for (int i = ri + 1; i <= ri + remain; i++)
            {
                ntable[i] = 1;
            }
            nlength = ri + remain + 1;
            for (int i = nlength; i < num; i++)
            {
                ntable[i] = 0;
            }
        }
        static void fixdec(int[] ntable, ref int nlength)
        {
            int index=0;
            int remain = num;
            for (int i = 0; i < num; i++)
            {
                remain = remain - ntable[i];
                if (1 == ntable[i] || 0==remain)
                {
                    index = i;
                    break;
                }
            }
            if (remain > 0)
            {
                nlength = index + remain + 1;
                for (int i = index + 1; i < nlength; i++)
                {
                    ntable[i] = 1;
                }
                for (int i = nlength; i < num; i++)
                {
                    ntable[i] = 0;
                }
            }
            else
            {
                nlength = index + 1;
            }
        }
        static void print(int[] ntable, int nlength)
        {
            bool first = true;
            solution++;
            Console.Write("=");
            for(int i = 0; i < nlength; i++)
            {
                if(first)
                {
                    Console.Write(ntable[i]);
                    first = false;
                }
                else
                {
                    Console.Write("+"+ntable[i]);
                }
            }
            Console.Write("\n");
        }
    }
}

//num = 40, count = 37338, time = 00:00:06.1562500

// 2025/3/10
// ChatGPT 4 Python solution:
import time

def partition(n, max_num, path, result):
    """ 產生所有可能的數字拆分方式 """
    if n == 0:
        result.append("+".join(map(str, path)))  # 找到一種組合,加入結果
        return

    for i in range(min(n, max_num), 0, -1):  # 從 max_num 開始遞減,確保唯一性
        partition(n - i, i, path + [i], result)

def count_partitions(n):
    """ 計算 n 的所有拆分方法並列印 """
    start_time = time.time()
    result = []
    
    partition(n, n, [], result)  # 呼叫遞迴函數
    
    for r in result:
        print(r)  # 列出所有拆分組合

    print(f"\nnum = {n}, count = {len(result)}, time = {time.time() - start_time:.3f} sec")

# 測試
count_partitions(5)

2009年11月29日 星期日

輸棋八訣

棄車不擊殺,棄馬不疏通。
棄炮不機動,棄相不過河。
棄卒不保帥,棄兵不穩進。
棄士不阻攻,棄將不龜宮。

2009年9月20日 星期日

三人編寫小說系統:一百年的小說山

幾個星期前,聽到有個英文的萬人編寫小說系統上線了。
一開始聽說成效不太好,現在小說作者也大多為一個人,
覺得這是個不錯的開始,
但是wiki系統可能要經過一些修改,再拿來寫小說會比較適合。
如果我設計一個小說系統的話,我想我可能會以三個人為單位。
即一個小說只能有三個人同時在寫,
而目前wiki discussion頁可以在分成,
討論劇情架構、討論場景設定及材料可能用到的名言佳句及對話內容
並且在另外加個留言板,以討論其它的相關細節,或者可以在留言相約三個人出來見面,
一起喝咖啡討論劇情。
而管理方式,可以採用自願退出,
則可以在有人退出後補足人數到三人。
又可以另外規定,若是另一個人三天以上沒參加修改,則可以由另兩人投票請他退出。
又為了避免同時有兩個人以上沒在修改,
可以在加一條規則,若是某一個人超過一個月沒在修改,系統強制將其退出該編劇專案外。

2007年,一個英文的萬人編寫小說系統上線,
觸發我想以個人為單位來開發一個編寫小說系統
現在雖然我還沒實際動手來開發這個系統,
不過,我想將這個系統,命名為「一百年的小說」。
除了一開始以三個人為單位的構想外,
我想在加上這個系統中,某些文章、討論、材料…等,可以設成公開,某些可以設成隱藏
但是如果這個小說專案過了一百年之後,那就強迫把專案內所有的文章、討論、材料…等隱藏屬性的部份都設成新公開
這樣可以更完整看到一個小說的發展全貌。
至於這個編寫小說系統的經營模式,可以採用參與撰寫是完全免費的,
但是一個小說專案的性質對於讀者可以是免費收費
而網站系統經營者從收費模式中的小說專案來抽成(與編寫者拆帳),或當小說專案要發行紙本時,另外抽成。
當然經營者允許免費小說專案可變更成收費小說專案,以增加網站收入。
另外當發行紙本時,採報備制來另外抽成,如不報備就直接或小做修改發行成冊,
則要處以處罰性報復,可能是一筆鉅額的違約金,以嚇阻想偷雞的人。

以上文章,由以下兩篇整合而成(作者都為本人):

多人編寫小說系統

(原創)一百年的小說山

 





Basic Blind Chess的兩大問題 (Android version only)

Note: 以下指Andorid version pygame的 v0.8.2之前,後來Unity版出的已有改善 Basic Blind Chess已經好久沒更新了, Windows版可以獲得最好的遊戲体驗, 但是Android版的,不只是比較舊, 它其實存在兩大問題: 1. 拿...