This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gheotic's profile picture

Calculation problem (Need Help)

Started by gheotic, 28 January 2013 - 08:47 AM
gheotic #1
Posted 28 January 2013 - 09:47 AM
Im trying to figure out a homework calculations thingy that i have to solve for tomorrow :)/>

here what i need to solve:

you get the same result when you minus the the number with 11 then times the rest with 11 then add minus 21 and times the rest with 21

so something like

i try with the number 10

10 - 11*11-21*21 = the result

i know that this is not correctly done, but i hope you get the point


so here what i have done with this script


local x = 13.0
local y = x

term.clear()
term.setCursorPos(1,1)
while true do
x = x + 0.01
term.clear()
term.setCursorPos(1,1)

y = x
y = y - 11
y = y * 11
y = y - 21
y = y * 21
term.clear()
term.setCursorPos(1,1)
term.write("trying with =")
print(x)
term.write("answer was: ")
term.write(y)
sleep(1)

if y == x then
term.clear()
term.write("The answer is: ")
print(y)
sleep(10)
else
term.setCursorPos(1,1)
print("That wasn't right")
--sleep(0)
end

end


i think the error might be that the y is something like 14.0 and not 14, but im not sure


any help would be appreciated =)

btw don't give me the answer i just want this to work xD
ikke009 #2
Posted 28 January 2013 - 09:56 AM
What is the error you're getting?

try this though
y = x
(((y-11)*11)-21)*21
if y == x then
blablabla
remiX #3
Posted 28 January 2013 - 09:58 AM
Could you explain a bit more of what you're trying to do?
gheotic #4
Posted 28 January 2013 - 10:03 AM
i get this error trying that bios:338: [string "math"]:19: ambiguous syntax (function call x new statement)
gheotic #5
Posted 28 January 2013 - 10:05 AM
i try to explain my task a bit better
you need to find a number and when you minus that number with 11 then times it with 11 and then minus it with 21 and then times 21 then it should give the same number again :)/>
ikke009 #6
Posted 28 January 2013 - 10:21 AM
btw try thinking outside of the box more..
if the variable left and right of the equation is the same and the output is the same then
x = (((x-11)*11)-21)*21
so if you simplify that equation
x = ((11x - 121)-21)*21
x = (11x - 142)*21
x = 231x - 2984

so thats pretty easy to solve for x now… the answer has many many decimals and is impossible to solve numerical (the way you're doing it) unless you make steps of 0.000000000001 or something..

answer is in spoiler
Spoiler1491/115
Orwell #7
Posted 28 January 2013 - 10:23 AM
Why are you writing a program for it? It's just a one degree polynomial… I have the answer and it's irrational, so it has an endless amount of decimals. Thus x=x+0.01 won't give you great accuracy :P/>

Edit: ninja'd. I don't see how that's thinking out of the box though. :P/> it's kinda obvious to solve it as an equation… because, well, it is an equation…
ikke009 #8
Posted 28 January 2013 - 11:30 AM
well if you look at the question and how gheotic tried to solve it, he had an idea but it was never going to work. at moments like that you have to think outside of the box to get the answer… (not saying you or i had to think outside of the box in order to solve it :P/>)