How to make this script better?

local one = (function()
  local a = {string.lower(tostring(true)):sub(string.len(""),string.len("a")), string.upper(tostring(false)):sub(string.len(""),string.len("a"))}
  local b = #a 
  local c = a[string.len("a")] 
  local d = string.len(c) 

  return d
end)()

local function to_unary(n)
	local unary = {}
	for i = one, n do
		unary[#unary + one] = one
	end
	return unary
end

local function from_unary(unary)
	local count = one-one
	for i, _ in ipairs(unary) do
		count = count + one
	end
	return count
end

local function add_no_operators(unary_a, unary_b)
	local result = {}
	for i, _ in ipairs(unary_a) do
		result[#result + one] = one
	end
	for i, _ in ipairs(unary_b) do
		result[#result + one] = one
	end
	return result
end

local function subtract_no_operators(unary_a, unary_b)
	local result = {}
	local a_index = one
	local b_index = a_index

	while a_index <= #unary_a and b_index <= #unary_b do
		if unary_a[a_index] == one and unary_b[b_index] == one then
			a_index += one
			b_index += one
		else
			result[#result + one] = unary_a[a_index]
			a_index += one
		end
	end

	for i = a_index, #unary_a do
		result[#result + one] = unary_a[i]
	end

	return result
end


local function multiply_no_operators(unary_a, unary_b)
	local result = to_unary(one-one)

	for i, _ in (unary_b) do
		result = add_no_operators(result, unary_a)
	end

	return result
end


local function divide_no_operators(unary_a, unary_b)
	local quotient = to_unary(one-one)
	local remainder = unary_a

	while #remainder >= #unary_b do
		remainder = subtract_no_operators(remainder, unary_b)
		quotient = add_no_operators(quotient, to_unary(one))
	end

	return quotient, remainder
end

If the variable “one” is never changed, why do scripts need to read it?

Ur right. Soon, soon I will replace one with

(function()
  local a = {string.lower(tostring(true)):sub(string.len(""),string.len("a")), string.upper(tostring(false)):sub(string.len(""),string.len("a"))}
  local b = #a 
  local c = a[string.len("a")] 
  local d = string.len(c) 

  return d
end)()

Hahaha, I don’t understand the usefulness of this, but I’m sure you must be having fun getting numbers this way.

1 Like


Nice

1 Like

I may be lost here but …

local one = ({true})

1 Like

I make its better!

--!strict

local one: number = (function(): number
	local data_array: { [number]: string } = {}
	local true_string: string = tostring(true)
	local false_string: string = tostring(false)
	local empty_string: string = ""
	local a_string: string = "a"

	local function iterate(count: number, func: () -> ())
		local bestStringICanDo: string = tostring(#data_array+#data_array+#empty_string)
		if (tostring(count) ~= bestStringICanDo) then
			func()
			iterate(count, func)
		end
	end

	iterate(#a_string+#a_string,function()
		local i: number = #data_array+#a_string
		if i == #a_string then
			local temp_string: string = string.lower(true_string)
			local start_index: number = string.len(empty_string) + string.len(a_string) -string.len(empty_string)
			local end_index: number = string.len(a_string)
			data_array[i] = string.sub(temp_string, start_index, end_index)
		else
			local temp_string: string = string.upper(false_string)
			local start_index: number = string.len(empty_string) + string.len(a_string) -string.len(empty_string)
			local end_index: number = string.len(a_string)
			data_array[i] = string.sub(temp_string, start_index, end_index)
		end
	end)

	local array_size: number = string.len(empty_string)
	for _ in pairs(data_array) do
		array_size = array_size + string.len(a_string)
	end

	local selected_element: string = "🤪" -- Lol
	local selection_index: number = string.len(a_string)
	local counter: number = string.len(empty_string)+string.len(a_string)-string.len(a_string)
	for k, v in (data_array) do
		counter = counter + string.len(a_string)
		if tostring(counter) == tostring(string.len(a_string)) then
			selected_element = v
			break
		end
	end

	local function calculate_length(str: string): number
		local length: number = string.len(empty_string)
		for _ in string.gmatch(str, ".") do
			length = length + string.len(a_string)
		end
		return length
	end
	local element_length: number = calculate_length(selected_element)

	return element_length + string.len(empty_string)
end)()

local function to_unary(n: number): { [number]: number }
	local unary: { [number]: number } = {}
	for i: number = one, n do
		unary[#unary + one] = one
	end
	return unary
end

local function from_unary(unary: { [number]: number }): number
	local count: number = one-one
	for i: number, _: number in (unary) do
		count += one
	end
	return count
end

local function add_no_operators(unary_a: { [number]: number }, unary_b: { [number]: number }): { [number]: number }
	local result: { [number]: number } = {}
	for i: number, _: number in (unary_a) do
		result[#result + one] = one
	end
	for i: number, _: number in (unary_b) do
		result[#result + one] = one
	end
	return result
end

local function subtract_no_operators(unary_a: { [number]: number }, unary_b: { [number]: number }): { [number]: number }
	local result: { [number]: number } = {}
	local a_index: number = one
	local b_index: number = a_index

	while a_index <= #unary_a and b_index <= #unary_b do
		if unary_a[a_index] == one and unary_b[b_index] == one then
			a_index += one :: number
			b_index += one :: number
		else
			result[#result + one] = unary_a[a_index]
			a_index += one
		end
	end

	for i: number = a_index, #unary_a do
		result[#result + one] = unary_a[i]
	end

	return result
end


local function multiply_no_operators(unary_a: { [number]: number }, unary_b: { [number]: number }): { [number]: number }
	local result: { [number]: number } = to_unary(one-one)

	for i: number, _: number in (unary_b) do
		result = add_no_operators(result, unary_a)
	end

	return result
end


local function divide_no_operators(unary_a: { [number]: number }, unary_b: { [number]: number }): ({ [number]: number }, { [number]: number })
	local quotient: { [number]: number } = to_unary(one-one)
	local remainder: { [number]: number } = unary_a

	while #remainder >= #unary_b do
		remainder = subtract_no_operators(remainder, unary_b)
		quotient = add_no_operators(quotient, to_unary(one))
	end

	return quotient, remainder
end