• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

##Confusing Code##

Status
Not open for further replies.
Hey, I thought it could be fun to fuck our brains if we just write some code for
a purpose or no certain purpose, or just a small/easy algorithm in a complex way.

You write a code, and people have to guess for example the purpose or solution of your code.
Try to write the code tricky and obfuscated, so people need to carefully think about it before they answer.

GUIDE ABOUT JOB ENSURANCE - PROPER CODE MAINTAINABILITY

Your code can be done in GUI or JASS. Does not matter,
but try to keep it in bounds, and don't paste 2000 lines.^^
If you find a solution please first contact the code-maintainer to not ruin it for others immediatly.

You also can post any code without having the last one solved.

I just start with an example, playing with booleans. What output will this code print? :
JASS:
scope CodeTest initializer init
    function foo_bar takes boolean NOT returns boolean
        if (NOT) then
            return not(NOT)
        elseif (TRUE == (bj_UNIT_FACING > 269.2121)) then
            return not((3)<2)
        else
            return not(true)
        endif
    endfunction

    function foo takes boolean fOO returns boolean
        return foo_bar(not(fOO))
    endfunction
   
    private function init takes nothing returns nothing
        local boolean fooo
        set fooo = not(foo(3==2))
        if not(true) == (-2>1) or foo_bar(false) != not(TRUE) and (((((((-1+(-1)*-1)==0) == fooo))))) then
            call BJDebugMsg("1")
        else
            call BJDebugMsg("2")
        endif
    endfunction
endscope
(Yes, you could run the code, but that's not the sense :D)
 
Last edited:
Some coders might already know this kind of programming, but what is the purpose of function myFunc
and what values will have the two integers after calling it in init?

JASS:
function myFunc takes integer i, integer j returns integer
    if(j == 0) then
        return i
    elseif (j > 0) then
        return (myFunc(i, j - 1)) + 1
    elseif (j < 0) then
        return (myFunc(i, j + 1)) - 1
    endif
endfunction

function init takes nothing returns nothing
    local integer int_1 = myFunc(3, 5)
    local integer int_2 = myFunc(3, -1)
endfunction

Edit:

It is a mathematical addition solved in a recursiv way.

So...
int_1 = 8
int_2 = 2
 
Last edited:
@Icemanbo, ugh, that's some ugly recursion math. I hate that when I was on Computer Olympiad.

@Everyone, Anyway, let me think of something VERY VERY easy...
JASS:
function A takes integer X, integer Y returns integer
 loop
 set X = X+Y
 set Y = Y+1
 if X mod Y = 0 then
  endloop
  return 1
 endif
endfunction

function onInit takes nothing returns nothing
 local integer EasyQuestion = A(5, 5)
endfunction
Note, I use pseudo Jass since I use mobile.
Just don't tell me you're calculating the whole code just to answer it xD

EDIT :
@Icemanbo
I would say it's 8 for int_1 and 2 for int_2.
hope my memories was correct.
Been awhile since I calculate like that.

EDIT :
Well, GhostThruster beats me to it.

EDIT :
Fixed the code in the post. I should have notice it earlier >.>

And the solution is clear anyway now :
in the old code, it can't be answered (infinite loop), and the new code means it result in 1
 
Last edited:
Edited my post with solution and pointed my own error.
My apologies.

I'll reread my code more carefully next time.
=========
JASS:
function X takes integer A, integer B, integer C returns integer
 set A = B
 set B = C
 set C = A

 if A mod B == B mod C then
  set C = A*B*C mod C
 else
  set C = A
 endif

 if A mod B = C
 then
 set A = B
 else
 set A = C
 endif

 return A+B+C
endfunction

function Test takes nothing returns nothing
 local Coordinate1 = X(1,2,3)
 local Coordinate2 = X(10,15,20)*X(20,30,40)
endfunction
Another pseudo code, but I'm sure this one doesn't get glitchy at all like the last one (since I avoid loops :D)
EDIT :
Added highlights :D
Now, answer it if you can :D
 
Last edited:
And the one who made the question forgot the answer :D

Let's just go to another code, shall we?

JASS:
function Main takes integer A returns integer
 integer B = A
 set A = A/2
 returns A*B
endfunction

function Main2 takes integer A returns integer
 integer B = A/2
 set A = Main(B)
 returns A-B
endfunction

function Q takes nothing returns integer
 integer A = Main2(20)
 returns A
endfunction

What is the output of Q?
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
I think you people miss the point.

The idea isn't to make obfuscated code that does nothing whatsoever. The idea is to make code that actually does something, but in a way that isn't immediately visible. Most questions I saw involved trees (insert, search, etc.), because those are the easiest kind of things to write in weird ways (incidentally, these are also the kind of questions you get when you begin to learn programming at university).

Finding a solution to the problems posted so far involves running them in your head for a minute. Where's the challenge of figuring the logic behind the code? That moment where seemingly random operations suddenly make sense, and it clicks.
 
Status
Not open for further replies.
Top