Posted 12 March 2015 - 02:43 PM
Ok, I have a small problem that's not really related to computercraft only, it's more of a Lua thing. As I haven't got any Lua interpreter or similar installed on my computer I use Lua's demo thingy…. I've been messing around with quite an old idea of mine, to make a program that tests the "6174" thingy (for no reason at all). The thing with 6174 is that if you take a 4-digit number, arrange the integers from biggest to smallest and subtract with the opposite (smallest to biggest) you'll get a new number, then you do the same thing with that one. This goes on and on 'til you get any combination of 6174, if you do the same thing with that number, you'll just get 6174 again… This works for all 4-digit numbers (not 2222, 3333, 4444 etc…).
I made a program just for fun to test this, but there's one major issue, it just keep skipping the while-thingy, I've tried with an "if" and "else" and it skips to the else without doing anything.
The while should be triggered if "start" is NOT 6174, and to start with, it's 1234. But it behaves like it's the same number….
I made a program just for fun to test this, but there's one major issue, it just keep skipping the while-thingy, I've tried with an "if" and "else" and it skips to the else without doing anything.
The while should be triggered if "start" is NOT 6174, and to start with, it's 1234. But it behaves like it's the same number….
start = 1234
number = {}
while not start == 6174 do
number[4] = start - math.floor(start/10)*10;
number[3] = math.floor((start - math.floor(start/100)*100 - number[4])/10);
number[2] = math.floor((start - math.floor(start/1000)*1000 - number[4] - number[3]*10) / 100);
number[1] = math.floor(start/1000);
for i = 1, 4 do
print(number[i])
end
table.sort(number)
largest = number[4]*1000 + number[3]*100 + number[2]*10 + number[1]
smallest = number[1]*1000 + number[2]*100 + number[3]*10 + number[4]
print(largest.. " - " ..smallest)
start = largest - smallest
end
print("Done!")