Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Samir_HG

#1
local BigNumber = {
    split_number = function(number) {
        local parts = [];
        local str = number.tostring();
        local len = str.len();
        local num_parts = ceil(len / 9.0);
        for (local i = 0; i < num_parts; i++) {
            local start = len - (i + 1) * 9;
            local end = len - i * 9;
            if (start < 0) start = 0;
            parts.append(str.slice(start, end).tointeger());
        }
        return parts;
    },

    add_arrays = function(a, b) {
        local result = [];
        local carry = 0;
        local len_a = a.len();
        local len_b = b.len();
        local max_len = (len_a > len_b) ? len_a : len_b;
        for (local i = 0; i < max_len; i++) {
            local sum = carry;
            if (i < len_a) sum += a[i];
            if (i < len_b) sum += b[i];
            result.append(sum % 1000000000);
            carry = sum / 1000000000;
        }
        if (carry > 0) result.append(carry);
        return result;
    },

    subtract_arrays = function(a, b) {
        local result = [];
        local borrow = 0;
        local len_a = a.len();
        local len_b = b.len();
        for (local i = 0; i < len_a; i++) {
            local diff = a[i] - borrow;
            if (i < len_b) diff -= b[i];
            if (diff < 0) {
                diff += 1000000000;
                borrow = 1;
            } else {
                borrow = 0;
            }
            result.append(diff);
        }
        while (result.len() > 1 && result[result.len() - 1] == 0) result.pop();
        return result;
    },

    multiply_arrays = function(a, b) {
        local result = [];
        local len_a = a.len();
        local len_b = b.len();
        for (local i = 0; i < len_a + len_b; i++) result.append(0);
        for (local i = 0; i < len_a; i++) {
            for (local j = 0; j < len_b; j++) {
                result[i + j] += a[i] * b[j];
                result[i + j + 1] += result[i + j] / 1000000000;
                result[i + j] %= 1000000000;
            }
        }
        while (result.len() > 1 && result[result.len() - 1] == 0) result.pop();
        return result;
    },

    divide_arrays = function(a, b) {
        if (b.len() == 1 && b[0] == 0) {
            print("Error: Division by zero");
            return [];
        }

        if (this.compare_arrays(a, b) < 0) return [0];
        local result = [];
        local remainder = [];

        for (local i = a.len() - 1; i >= 0; i--) {
            remainder.insert(0, a[i]);
            while (remainder.len() > 1 && remainder[remainder.len() - 1] == 0) remainder.pop();
            local digit_quotient = 0;
            while (this.compare_arrays(remainder, b) >= 0) {
                remainder = this.subtract_arrays(remainder, b);
                digit_quotient++;
            }
            result.insert(0, digit_quotient);
        }
        while (result.len() > 1 && result[result.len() - 1] == 0) result.pop();
        return result;
    },

    compare_arrays = function(a, b) {
        local len_a = a.len();
        local len_b = b.len();
        if (len_a < len_b) return -1;
        if (len_a > len_b) return 1;
        for (local i = len_a - 1; i >= 0; i--) {
            if (a[i] < b[i]) return -1;
            if (a[i] > b[i]) return 1;
        }
        return 0;
    },

    print_array = function(a) {
        local str = "";
        for (local i = a.len() - 1; i >= 0; i--) {
            if (i == a.len() - 1) str += a[i].tostring();
            else str += format("%09d", a[i]);
        }
        print(str);
    }
}

Usage:

local a = BigNumber.split_number("100000000000");
local b = BigNumber.split_number("1000000000000");
print("Addition: ");
local sum_result = BigNumber.add_arrays(a, b);
BigNumber.print_array(sum_result); // output "1100000000000"
print("Subtraction: ");
local sub_result = BigNumber.subtract_arrays(b, a);
BigNumber.print_array(sub_result); // output "900000000000"
print("Multiplication: ");
local mul_result = BigNumber.multiply_arrays(a, b);
BigNumber.print_array(mul_result); // output "100000000000000000000000"
print("Division: ");
local div_result = BigNumber.divide_arrays(b, a);
BigNumber.print_array(div_result); // output "10"

Output:


When using a value in these functions, please convert it to a string before
#2
Community Plugins / Re: Discord Plugin
Aug 18, 2022, 03:49 PM
Apparently it's a certificate issue.
#3
Nice script It worked perfectly. Thanks.
#4
Community Plugins / Re: Discord Plugin
Aug 04, 2022, 05:13 PM
I'm having this problem when trying to connect:
[2022-08-04 21:56:45] [connect] Successful connection
[2022-08-04 21:56:45] [error] handle_transport_init received error: TLS handshake failed
[2022-08-04 21:56:45] [info] asio async_shutdown error: asio.ssl:336462231 (shutdown while in init)
disconnect
[2022-08-04 21:56:45] [connect] Successful connection
[2022-08-04 21:56:45] [error] handle_transport_init received error: TLS handshake failed
[2022-08-04 21:56:45] [info] asio async_shutdown error: asio.ssl:336462231 (shutdown while in init)
disconnect

Plugin versions used: x32 and x86
Systems used: Windows 10 Pro 21H2 and Ubuntu 20.04 (both updated)
OpenSSL downloaded from https://slproweb.com/products/Win32OpenSSL.html
Tried all versions available on the website.

On Linux, I downloaded libssl-dev as instructed in this tutorial.

I'm using the exact same script that worked months ago.
As a precaution, I decided to create a new one with only the most basic functions as suggested in more recent tutorials and also the examples on GitHub pages.

Two different ISPs were used in the connection attempt. In all the above scenarios returns the same error.