View unanswered posts | View active topics It is currently Thu Jul 31, 2014 8:21 pm






Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Guess the code! 
Author Message
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Guess the code!
Whoever can guess what this code does gets 1,000,000 :shock: internetz points! (should this be in off-topic? It is about a program....)

Code:
void LookupColorText(int Color, int BrickLoc);

task main()
{
  typedef struct
  {
    bool ColorDefined;
    int WhereDoesColorBelong;
    string DoesColorBelong[6];
  }BRICK_STRUCT;

  BRICK_STRUCT BrickInfo[6];

  for(int i = 0; i <= 5; i++)
  {
    BrickInfo[i].ColorDefined = false;
    BrickInfo[i].WhereDoesColorBelong = 0;

    for(int x = 0; x <= 5; x++)
    {
      BrickInfo[i].DoesColorBelong[x] = "unknown";
    }
  }

  nxtDisplayTextLine(0, "Bk Bl Gr Yl Rd Wt");
  nxtDisplayCenteredTextLine(1, "1  2  3  4  5  6");

  while(true)
  {
    int RandomLoc = random[5];
    int BrickColor = random[5];

    if(BrickInfo[BrickColor].ColorDefined == true)
    {
      LookupColorText(BrickColor + 1, BrickInfo[BrickColor].WhereDoesColorBelong);
      wait1Msec(1000);
    }
    else
    {
      bool FoundUnkownLoc = false;

      while(FoundUnkownLoc == false)
      {
        if(BrickInfo[BrickColor].DoesColorBelong[RandomLoc] == "unknown")
        {
          FoundUnkownLoc = true;
        }
        else
        {
          RandomLoc = random[5];
        }
      }
      LookupColorText(BrickColor + 1, RandomLoc + 1);

      while(nNxtButtonPressed == kNoButton);

      if(nNxtButtonPressed == kLeftButton)
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].ColorDefined = true;
        BrickInfo[BrickColor].WhereDoesColorBelong = RandomLoc + 1;
        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "yes";

        for(int y = 0; y <= 5; y++)
        {
          if(BrickInfo[y].DoesColorBelong[RandomLoc] == "unknown")
          {
            BrickInfo[y].DoesColorBelong[RandomLoc] = "no";
          }
        }
      }
      else
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "no";
      }
    }
  }
}

void LookupColorText(int Color, int BrickLoc)
{
  string ColorText;

  switch (Color)
  {
    case 1:
      ColorText = "Black";
    break;
    case 2:
      ColorText = "Blue";
    break;
    case 3:
      ColorText = "Green";
    break;
    case 4:
      ColorText = "Yellow";
    break;
    case 5:
      ColorText = "Red";
    break;
    case 6:
      ColorText = "White";
    break;
  }

  nxtDisplayCenteredTextLine(3, ColorText + " goes in");
  nxtDisplayCenteredTextLine(4, "bin:  " + BrickLoc);
  nxtDisplayCenteredTextLine(7, "Yes          No");
}


Go ahead, guess! :mrgreen:

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun Apr 22, 2012 9:38 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Thu Dec 22, 2011 7:42 am
Posts: 43
Post Re: Guess the code!
mmm, it's a kind of IQ test that checks if user understand color abbreviation ?

_________________
Visit my project RainBot v0.11 on source forge, a 6 wheels robot featuring A* & Dijkstra's path finding, motors & sensors emulation, small font, fifo & sorted list libraries, using Xander's drivers for HT Compass, and documented with doxygen.


Sun Apr 22, 2012 11:03 am
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
miki wrote:
mmm, it's a kind of IQ test that checks if user understand color abbreviation ?


Nope! Guess again! Here's a hint: On-brick proof-of-concept for a l****ing ***** ******

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun Apr 22, 2012 11:30 am
Profile WWW
Rookie

Joined: Fri Jan 27, 2012 6:57 pm
Posts: 40
Post Re: Guess the code!
It looks like some sort of game where the user has to guess what color goes in which bin. (Kind of like mastermind perhaps?)


Tue Apr 24, 2012 3:50 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
sumasmreq wrote:
It looks like some sort of game where the user has to guess what color goes in which bin. (Kind of like mastermind perhaps?)


Close, but not quite!

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Tue Apr 24, 2012 4:45 pm
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
Does anyone want another hint?

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Wed Apr 25, 2012 5:30 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Thu Dec 22, 2011 7:42 am
Posts: 43
Post Re: Guess the code!
Hi NextGen,
While all our friends go nuts trying to guess what's the ultimate purpose of your code (I'd bet on 42), it's my turn to launch a game :-).
The challenge is : Can you optimize you code to be smaller and faster with exactly the same inputs and outputs?
Miki.

PS: this message will not self-destruct in 15 seconds. ... I hope.

_________________
Visit my project RainBot v0.11 on source forge, a 6 wheels robot featuring A* & Dijkstra's path finding, motors & sensors emulation, small font, fifo & sorted list libraries, using Xander's drivers for HT Compass, and documented with doxygen.


Thu Apr 26, 2012 4:23 am
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
miki wrote:
Hi NextGen,
While all our friends go nuts trying to guess what's the ultimate purpose of your code (I'd bet on 42), it's my turn to launch a game :-).
The challenge is : Can you optimize you code to be smaller and faster with exactly the same inputs and outputs?
Miki.

PS: this message will not self-destruct in 15 seconds. ... I hope.


Well, sure, I probably could. But, I don't really have time because BrickWorld Chicago is less than two months away. They're having several competitions, and I needz to buildz ROBOTZ!!!!


P.S. Just wondering..... Has anybody actually tried running this code?

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Thu Apr 26, 2012 9:11 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Thu Dec 22, 2011 7:42 am
Posts: 43
Post Re: Guess the code!
Me at least. I have a lot of time since my main computer is still out of order ;-)

Miki.

_________________
Visit my project RainBot v0.11 on source forge, a 6 wheels robot featuring A* & Dijkstra's path finding, motors & sensors emulation, small font, fifo & sorted list libraries, using Xander's drivers for HT Compass, and documented with doxygen.


Thu Apr 26, 2012 11:35 am
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
Ok, your mission: Figure out what this code does by the time the weekend ends, that is Monday, or else I'm just going to tell you. And that wouldn't be any fun.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Fri Apr 27, 2012 9:05 pm
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
I'm warning you: If nobody has guessed correctly by 5:00PM, US Central Time, Monday, I will post a solution video.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun Apr 29, 2012 6:38 pm
Profile WWW
Novice
User avatar

Joined: Sat Jul 10, 2010 3:06 pm
Posts: 86
Location: Roanoke, VA
Post Re: Guess the code!
NeXT-Generation wrote:
Nope! Guess again! Here's a hint: On-brick proof-of-concept for a learning brick sorter

My guess...

Am I right?

//Andrew

_________________
Check out my website! www.RoboDesigners.com

VRC Team 2190

Twitter: @RoboDesigners


Sun Apr 29, 2012 7:38 pm
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
RoboDesigners wrote:
NeXT-Generation wrote:
Nope! Guess again! Here's a hint: On-brick proof-of-concept for a learning brick sorter

My guess...

Am I right?

//Andrew


Annnd...... That is correct!!!!! Here's your prize!!! *hands over 1,000,000 symbolic internetz points* Thank you, and come again to play *fictional audience shouting* "Guess.... That..... Code!!!".

For those of you who don't know, here's some commented code explaining how it works. Each comment will be explaining the line(s) of code it's on, and all those above it until the next comment:

Code:
void LookupColorText(int Color, int BrickLoc);

task main()
{
  typedef struct
  {
    bool ColorDefined;
    int WhereDoesColorBelong;
    string DoesColorBelong[6];
  }BRICK_STRUCT;

  BRICK_STRUCT BrickInfo[6];

  for(int i = 0; i <= 5; i++)
  {
    BrickInfo[i].ColorDefined = false;
    BrickInfo[i].WhereDoesColorBelong = 0;

    for(int x = 0; x <= 5; x++)
    {
      BrickInfo[i].DoesColorBelong[x] = "unknown";
    }
  }

  nxtDisplayTextLine(0, "Bk Bl Gr Yl Rd Wt");
  nxtDisplayCenteredTextLine(1, "1  2  3  4  5  6");//Initialization procedure.  Structure, and structure array created.  All elements of array initialized.

  while(true)
  {
    int RandomLoc = random[5];
    int BrickColor = random[5];//I don't think I need to explain these.

    if(BrickInfo[BrickColor].ColorDefined == true)
    {
      LookupColorText(BrickColor + 1, BrickInfo[BrickColor].WhereDoesColorBelong);
      wait1Msec(1000);
    }//Checks if the color is known.  If it is, then go directly to the known location.  If not, then engage learning procedure (below).
    else
    {
      bool FoundUnkownLoc = false;

      while(FoundUnkownLoc == false)
      {
        if(BrickInfo[BrickColor].DoesColorBelong[RandomLoc] == "unknown")
        {
          FoundUnkownLoc = true;
        }
        else
        {
          RandomLoc = random[5];
        }
      }//This loop applies a random number to put the brick in.  But, we don't want it trying spaces that have already proven to be false.  So, it keeps trying random numbers until it finds an unknown space.
      LookupColorText(BrickColor + 1, RandomLoc + 1);//Displays the brick color and randomly chosen location.

      while(nNxtButtonPressed == kNoButton);

      if(nNxtButtonPressed == kLeftButton)
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].ColorDefined = true;
        BrickInfo[BrickColor].WhereDoesColorBelong = RandomLoc + 1;
        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "yes";

        for(int y = 0; y <= 5; y++)
        {
          if(BrickInfo[y].DoesColorBelong[RandomLoc] == "unknown")
          {
            BrickInfo[y].DoesColorBelong[RandomLoc] = "no";
          }
        }
      }//If you press yes, then it sets ColorDefined to true, the location of the color to the randomly chosen location, that you confirmed, and that same slot in all the other color arrays to "no".
      else
      {
        while(nNxtButtonPressed != kNoButton);

        BrickInfo[BrickColor].DoesColorBelong[RandomLoc] = "no";
      }//If you said no, then it simply sets that slot to "no".
    }
  }
}

void LookupColorText(int Color, int BrickLoc)
{
  string ColorText;

  switch (Color)
  {
    case 1:
      ColorText = "Black";
    break;
    case 2:
      ColorText = "Blue";
    break;
    case 3:
      ColorText = "Green";
    break;
    case 4:
      ColorText = "Yellow";
    break;
    case 5:
      ColorText = "Red";
    break;
    case 6:
      ColorText = "White";
    break;
  }

  nxtDisplayCenteredTextLine(3, ColorText + " goes in");
  nxtDisplayCenteredTextLine(4, "bin:  " + BrickLoc);
  nxtDisplayCenteredTextLine(7, "Yes          No");
}//This function simply takes two variables, the brick color and the location, and displays them with the proper additions.


P.S. Here's the demo video anyway.


Sorry if I rambled. I was a bit tired when I took this.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun Apr 29, 2012 8:27 pm
Profile WWW
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Guess the code!
Cool stuff again, as usual. When will the .LDD file be up ? :)

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon Apr 30, 2012 12:24 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Guess the code!
Spiked3 wrote:
Cool stuff again, as usual. When will the .LDD file be up ? :)


Umm, I think your joking, right? This was just running on the virtual emulator. It was just the code, with no physical interface.

P.S. Thanks! :wink:

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Mon Apr 30, 2012 12:34 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 24 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.