コラッツ問題シミュレーター

Conjectures: P Versus NP Problem, Conjecture, Collatz Conjecture, Hilbert's Problems, Catalan's Conjecture, Sierpinski Number
pongeponge.hatenablog.jp


 コラッツ問題を気軽にできるように、Unityで作ってみた。
バグ多いけどね……。

こういうのってシミュレーターに入るんだろうか?
リゾルバーのほうがいいんだろうか?



使い方
1.数字を入力します
2.スタートボタンを押します
3.飽きるまで見ます
4.計算結果が1になったり、もういちどやりたくなったりしたらボタンを押す




言い訳1:変数名とかめんどくさかった

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class title : MonoBehaviour {

    public GameObject input;
    public GameObject param;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void OnClick()
    {

        this.param.GetComponent<Global>().num =  long.Parse(this.input.GetComponent<Text>().text);
        Application.LoadLevel(1);
    }
}
using UnityEngine;
using System.Collections;

public class Global : MonoBehaviour {

    public long num;

    //消えないようにする
    void Awake()
    {
        DontDestroyOnLoad(this);
    }

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
using UnityEngine;
using UnityEngine.UI;
using System.Collections;


public class korattu : MonoBehaviour {

    public GameObject tex;

    long n;
    Text t;
    bool continuef;

	// Use this for initialization
	void Start () {
        GameObject p = GameObject.Find("ParamBox");

        n = p.GetComponent<Global>().num;
        t = this.tex.GetComponent<Text>();

        this.continuef = true;
        t.text = n.ToString();

        StartCoroutine(korattuplay());
	}
	
	// Update is called once per frame
	void Update () {
        
	}

    IEnumerator korattuplay()
    {
        while (this.continuef)
        {
            yield return new WaitForSeconds(1.0f);
            if (n % 2 == 0) n = n / 2;
            else n = 3 * n + 1;
            
            t.text = n.ToString();

            if (n == 1) this.continuef = false;

        }

        yield return new WaitForSeconds(1.0f);
    }
}
using UnityEngine;
using System.Collections;

public class retry : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void OnClick()
    {
        GameObject p = GameObject.Find("ParamBox");
        Destroy(p);
        Application.LoadLevel(0);
    }
}


 シーン間の変数の受け渡しがよくわからなかったので、
1.空のGameObject(ParamBoxという名前にした)を作って、グローバルで使いたい変数を盛りだくさんにしたスクリプトをくっつける
2.スクリプトDontDestroyOnLoad()を追加しておく
3.シーンが変わってもGameObject.Find("ParamBox")で変数を取得できる


こんな感じにした。