Author Topic: Decode This Puzzle  (Read 134 times)

0 Members and 1 Guest are viewing this topic.

Offline Infinimint

  • ***
  • Posts: 102
  • Gender: Male
  • Respect: +68
    • United Development
Decode This Puzzle
« on: August 31, 2012, 04:50:34 PM »
0
I got bored and made this in Java. If you already know Java, don't give away the answer :P

Question: a) What is the output of this? b) How does changing the value of the variables affect the result? c) Provide a visual representation of the output as well as an example with changed variables.
Rules: You cannot actually compile the code or anything similar. It's cheating. Honor code bro, honor code.

Quote

      int cMax = 5;
      int rMax = 5;
      int columns = 0;
      int rows = 0;

         while (rows < rMax) {
         if (columns == cMax) {
            System.out.println();
            columns = 0;
            rows++;
         } else {
            if (rows == 0 || rows == rMax - 1) {
               for (columns = 0; columns < cMax; columns++) {
                  System.out.print("*");
               }
            } else {
               if (columns >= 1 && columns <= cMax -2) {
                  System.out.print(" ");
                  columns++;
               } else {
                  System.out.print("*");
                  columns++;
               }
            }
         }
      }
« Last Edit: August 31, 2012, 06:20:20 PM by Infinimint »

Offline coolzeldad

  • ******
  • OwnerDonatorOld Forum MemberrNd DeveloperLinux UserWindows UserDog LoverLeague PlayerDWO Player
    View More Badges!

  • Posts: 3333
  • I eat ddos for breakfast OMNOMONOM
  • Respect: +2711
    • .:`=-~rANdOm~`-=:. Game Servers
Re: Decode This Puzzle
« Reply #1 on: August 31, 2012, 06:20:01 PM »
0
While this looks like a book problem... I'll answer cause I think its fun LOL I'm retarded.

Anyway I think this is how it works without looking at anythingz

Spoiler: dunlewkifnotwantanswer (click to show/hide)
 ▲
▲▲Big thanks to Marie for this awesome sprite! :3

Spoiler: Moar Imagez (click to show/hide)
pingaz
Thanks Cryptokid!

Thanks gamefreak!


-- My youtube: http://www.youtube.com/coolzeldad
-- My deviantart: http://coolzeldad.deviantart.com
-- My soundcloud: http://www.soundcloud.com/coolzeldad
-- My ustream: http://www.ustream.tv/channel/coolzeldapingaz
-- My twitchtv: http://www.twitch.tv/coolzeldad

-- rNd Wiki: http://wiki.randomgs.com
-- rNd Youtube: http://www.youtube.com/RandomgsProductions
-- rNd Steam Group: http://steamcommunity.com/groups/r_A_N_d_O_m

Spoiler: rNd Typography (click to show/hide)





Every time you download Garry's Mod illegally, Garry makes a bug.

When people ask me "Plz" because its shorter than "Please" I feel perfectly justified to answer "No" because its shorter than "Yes".

derp herp lerp perp kerp serp zerp - say faiv timez fazt


Offline Infinimint

  • ***
  • Posts: 102
  • Gender: Male
  • Respect: +68
    • United Development
Re: Decode This Puzzle
« Reply #2 on: August 31, 2012, 06:31:19 PM »
0
While this looks like a book problem... I'll answer cause I think its fun LOL I'm retarded.

Anyway I think this is how it works without looking at anythingz

Spoiler: dunlewkifnotwantanswer (click to show/hide)

Yep, you got it for the most part :P

Spoiler (click to show/hide)

Offline Sabb

  • ***
  • 2009 Snowball Competition WinnerWindows UserOld Forum MemberDedicated Summoner
    View More Badges!

  • Posts: 7378
  • Gender: Female
  • Respect: +2400
Re: Decode This Puzzle
« Reply #3 on: August 31, 2012, 07:54:21 PM »
0
Yep, you got it for the most part :P

Spoiler (click to show/hide)
His example does have 5 rows/columns? Just that the if statement checks when it's about to hit 6 total rows/columns, then outputs a new line and resets the value. But I'm not sure what you mean with the 0 not being accounted for. Zero is an integer so the variable isn't without value and an asterisk will be printed if the value is zero because the if statement basically says "if rows is equal to 0 or 4 (max [5] -1) then place an asterisk." So it still starts placing an asterisk at 0 technically making it 0,1,2,3,4 not 1,2,3,4,5. Unless I'm misunderstanding what you're trying to point out idk.


Lithuanian pride world wide!: sun doesnt revolve around the sun


Offline Infinimint

  • ***
  • Posts: 102
  • Gender: Male
  • Respect: +68
    • United Development
Re: Decode This Puzzle
« Reply #4 on: August 31, 2012, 08:23:40 PM »
0
To clarify, the visual counting on the front end with the variables does not take the zero into account, but like you guys mentioned, the backend  of how the code works itself does. So it is right to say that it counts starting from one if you were talking about the language, however the way that the variables are setup kinda just count to 5 :P

But yes, seeing how the first set must be less than 4, in order for it to cycle 5 times it must count 0,1,2,3,4.
However, in other cases, such as counting the columns, it goes all the way up to five since it makes decisions based upon the variable.

It's hard to explain from my perspective. Visually, the math doesn't appear to count from 0, but in reality the code does count from 0.


TL;DR My mind works weird and I see things differently, hence my hipster PC.
« Last Edit: September 01, 2012, 04:00:46 AM by Death M.D. »