繁体   English   中英

C ++中Tupper的自引用公式无法按预期工作?

[英]Tupper’s Self-Referential Formula in C++ not working as expected?

我正在尝试使用TTMath在C ++中编写Tuppers公式来存储大整数。 但是我的输出只是一团糟,而不是应该显示的图片。 我无法解决造成这种情况的原因。

#include <iostream>
#include <fstream>
#include <ttmath/ttmath.h>

int main(int argsm, int** args)
{
    const ttmath::Int<1> HEIGHT = 17;
    const ttmath::Int<1> WIDTH = 106;
    ttmath::Big<300, 300> a, b, c, d, e, f, g, h, i, j, k, l, y;
    std::ofstream newFile;

    char matrix[107][18];

    newFile.open("image.txt");

    for (ttmath::UInt<3> x = 0; x < WIDTH; ++x)
    {
        y = ttmath::Big<1, 200>("9609393799189588849716729621278527547150043396601293066515055192717028023952664246896428421743507 18121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719");
        for (ttmath::UInt<2> v = 0; v <= HEIGHT; ++v)
        {
            k = y;
            a = y;
            a.Mod(17);
            b = a;
            c = x;
            c.Mul(17);
            b.Mul(1);
            d = c + b;
            d.Pow(2);
            e = d;
            k.Div(17);
            f = k ;
            g = f;
            g.Div(e);
            h = g;
            h.Mod(2);
            j = h;
            j > 0.5 ? matrix[stoi(x.ToString())][stoi(v.ToString())] = '\u2588' : matrix[stoi(x.ToString())][stoi(v.ToString())] = ' ';
            y.Add(1);
        }
    }

    for (signed int h = 0; h < std::stoi(HEIGHT.ToString()); ++h)
    {
        for (signed int w = 0; w < std::stoi(WIDTH.ToString()); ++w)
        {
            newFile << matrix[w][h];
        }
        newFile << "\n";
    }
    newFile.close();
    return 0;
}

除了评论中指出的其他一些问题外,主要问题似乎是该行

d.Pow(2);

当您想要的是2^d时,计算d^2

关于您评论中的第二个问题:为了将生成的图像上下颠倒,您所要做的就是使用

newFile << matrix[w][HEIGHT-h-1];

在您的输出行中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM