generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Scripting challenge #5

Previous Thread :: Next Thread 
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
31 Mar 2013 04:15 AM
This challenge is divided in three parts.

a) Create a function that will receive a condition and a function and will execute the function if the condition is true.

b) Create a function that will receive two conditions or more and will return whether they are all true.

c) Create a function that will receive two conditions or more and will return whether one of them is true.

These three functions must be created without using any if statement and without using the 'and' and 'or' operators. You'll notice that the first corresponds to an if statement and that the two others correspond to these respective operators.
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
31 Mar 2013 04:49 AM
I forgot to mention that you couldn't use the break statement.
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
31 Mar 2013 04:52 AM
// All of these execute a function that was passed as a parameter if the conditions are met...

a)
void foo(bool condition,void (*bar)()){ if(condition){(*bar)();} }

b)
void foo(bool condition,bool condition2, void (*bar)()){if(condition){if(condition2){(*bar)();}}}

c)
"Create a function that will receive two conditions or more and will return whether one of them is true." (I assume you mean 'if' instead of 'whether')

void foo(bool condition,bool condition2, void (*bar)()){if(condition){(*bar)();}else if(condition2){(*bar)();}}

- DrHaximoose
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
31 Mar 2013 04:52 AM
Ok, I actually also forgot to mention that you couldn't use the return statement.

Fortunately, nobody posted yet.
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
31 Mar 2013 04:53 AM
Erm...
Me? :(

- DrHaximoose
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
31 Mar 2013 04:58 AM
@DrHaximus

Yeah, of course, the time I say nobody posted before, someone just has posted two seconds too early... :(

Anyway, you cannot use if statements, return statements, break statements or the 'or' and 'and' operators. That's true for all languages, including C and C++, although I'd prefer if you did the challenge in Lua.

Also, since it's impossible to think of preventing every single way to solve a challenge and to think of all the details to mention (oxcool1 generally just asks me to solve the challenge first before posting it, and I find like 4 easy ways to solve it while following his rules before I actually have to go seriously through the challenge), I'll just make people run out of solutions gradually in my future challenges.
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
31 Mar 2013 05:09 AM
how about:

jmp main
main:
     push argument
     call func
     ; eax=returned value
func:
     pop ecx
     mov edx, p1
     cmp ecx
     je equal
     ret p2
equal:
     ret p1

p1 db 0x1
p2 db 0x0
argument db 0x1

- DrHaximoose
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
31 Mar 2013 05:32 AM
@DrHaximus

Hum... ok, well, that's a bit of a special case... I guess...
Report Abuse
GigsD4X is not online. GigsD4X
Joined: 06 Jun 2008
Total Posts: 3794
31 Mar 2013 06:05 AM
function runIf(cond, func)
for i = 1, ({[true] = 1, [false] = 0})[not not cond] do
func();
end;
end;


For the following, I doubt you meant to not use the return statement at all, but rather to just not use it to evaluate expressions.

function allTrue(...)
local args = table.pack(...);
local n = 0;
local bools = {[true] = 1, [false] = 0};
for i = 1, #args do
n = n + bools[not not args[i]];
end;
return n == #args;
end;

function anyTrue(...)
local args = table.pack(...);
local n = 0;
local bools = {[true] = 1, [false] = 0};
for i = 1, #args do
n = n + bools[not not args[i]];
end;
return n > 0;
end;
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
31 Mar 2013 06:13 AM
@GigsD4X

Those are pretty creative ways of solving it, and yes, I mean to not use the return statement to evaluate expressions.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
31 Mar 2013 07:35 AM
wtf

how do we return without return

is that even possible
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
31 Mar 2013 07:46 AM
local ret

function return(msg)
ret = msg
end

for _, v in pairs(workspace:GetChildren()) do
return(v.Name)
print(ret)
end

Variables.
Report Abuse
TeamDman is not online. TeamDman
Joined: 04 Dec 2009
Total Posts: 897
31 Mar 2013 08:28 AM
function a(Con,Fun)
if Con then Fun() end
end

local return = true
function b(i,v,...)
if not i or not v then return = false end
for _,v in pairs(...) do if not v then return = false end
end

local return = false
function c(i,v,...)
if i or v then return = true end
for _,v in pairs(...) do if v then return = true end
end

-- asd?
Report Abuse
ThePC8110 is not online. ThePC8110
Joined: 04 Jun 2011
Total Posts: 486
31 Mar 2013 08:30 AM
He said without "or", "and", and "if".
:)
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
31 Mar 2013 08:44 AM
A is easy to some extent:

local is
function if(cond)
is = cond==true
end


Example:

if(true)
if is then print("true!") end

But still, why would you even use a function to check if something is true?
Report Abuse
DjM4x is not online. DjM4x
Joined: 26 Mar 2013
Total Posts: 71
31 Mar 2013 09:23 AM
well im not a scripted but ama start scripting at www.robloxwiki.com
Report Abuse
DjM4x is not online. DjM4x
Joined: 26 Mar 2013
Total Posts: 71
31 Mar 2013 09:23 AM
scripting is impossible
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
31 Mar 2013 09:39 AM
DjM4x,

The site you are looking for is probably
wiki.roblox.com and not "robloxwiki"

Scripting isn't impossible, but rather just takes some time to learn. If you start small, you can work your way up to a few of the more advanced concepts within a few weeks. Experimenting is a great way to figure things out, and the output tab can help you locate any errors.
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
31 Mar 2013 10:22 AM
a)

    f = function(x,y) if x then y() end end

b)

    f = function(...)
        local args = {...}
        for _, v in ipairs(args) do
            if v then
                args[_] = 1
            else
                args[_] = 0
            end
        end
        return loadstring('return '..table.concat(args,'+'))() == #args*args[1]
    end

c)

    f = function(...)
        local args = {...}
        for _, v in ipairs(args) do
            if v then
                args[_] = 1
            else
                args[_] = 0
            end
        end
        return loadstring('return '..table.concat(args,'+'))() ​> 0
    end


I have no idea how you expect a function to return a value without using return.
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
31 Mar 2013 09:34 PM
Ok, it seems most people didn't understand the challenge.

Anyway, I did it using a while statement instead of the if statement in all cases where I'd have needed an if statement and I used coroutines to be able to make that while statement only execute once, by yielding it after the first execution.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
31 Mar 2013 09:44 PM
May I please request that your following challenges not reply upon locking up the API or code or something, but instead rely upon logical problem solving? That is, your write an algorithm to deal with it, not say "off limits" to part's of a programming language.

That would make it must more enjoyable. Thanks.

Report Abuse
RenderSettings is not online. RenderSettings
Joined: 16 Aug 2010
Total Posts: 2560
31 Mar 2013 09:58 PM
function runIf(con,func)
pcall(con and func or (function() end))
end

function allTrue(...)
local ret = 1
for _,v in next,{...} do
ret = ret + (v==true and 0 or 1)
end
return ret == 1
end


function anyTrue(...)
local ret = 1
for _,v in next,{...} do
ret = ret + (v==true and 0 or 1)
end
return ret > 1
end


Well there were easy. Expecially since 2 and 3 were essentially the same thing.
Report Abuse
RenderSettings is not online. RenderSettings
Joined: 16 Aug 2010
Total Posts: 2560
31 Mar 2013 10:00 PM
Ah, without and/or. Forgot about that...Lemme see what I can cook up.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
31 Mar 2013 10:13 PM
Presumably, this was the solution this:

local function a(condition, execution)
while (condition)
exec()
condition = not condition
end
end

local function b(...)
x = true
for _, Value in pairs({...}) do
while Value == false do
Value = not Value
x = false
end
end
return x
end

local function c(...)
x = false
for _, Value in pairs({...}) do
while Value == false do
Value = not Value
x = true
end
end
return x
end

AKA: Using a while loop as an if statement. Seriously. LOGICAL problems, this is "hack the API" problems.
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
31 Mar 2013 10:20 PM
my solution did not break any rules and used generic methods for the language.

unfortunately it was in assembly

- DrHaximoose
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image