Bookmark Topic Watch Topic
  • New Topic

Competition : Win a ticket to GeeCON Prague 2014  RSS feed

 
Tim Cooke
Marshal
Posts: 3840
221
Clojure IntelliJ IDE Java
  • Likes 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
CodeRanch is offering 1 free ticket (yes, a free ticket!) to GeeCON Prague 2014 which is scheduled for 23 - 24 October 2014.

The event boasts Java and JVM based technologies, dynamic languages, enterprise architectures, patterns, distributed computing, software craftsmanship, mobile and much more...

To stand a chance of winning the ticket, all you have to do is enter our fun programming competition, posting your solutions in this very thread. You can even post more than once. The solution that we, the CodeRanch staff, think is the best will win the ticket to GeeCON Prague 2014. Also, as an added bonus, the winner will have the opportunity to meet one of our esteemed Marshal's Ulf Dittmer who will be attending the conference too.

The contest ends Friday 10th October, with the winner announced by Saturday 11th October. Good luck, and have fun!!

The Competition: Java obfuscated word occurrence counter

The Problem
  • Write a program that takes a sentence, a String with words delimited by whitespace, and returns the occurrence of each word as a Map of words (key) to occurrence count (value).

  • The Criteria
  • Write a program that solves the problem, while being as unreadable to the human eye as possible. (Obfuscation)
  • Bonus points for achieving it in the least amount of code. (Code Golf)

  • The Rules
  • The sentence is a String delimited by single whitespace characters. Assume no punctuation.
  • Words are case insensitive. "CodeRanch" is the same as "coderanch"
  • Words are mapped in lowercase form. "CodeRanch" is mapped as "coderanch"
  • Java SE only. No third party libraries allowed.
  • Must compile and run with Java8 JDK and JRE
  • Must comply with the following method signature


  • For example
    The sentence (String) "I really REALLY love CodeRanch" returns the occurrence (Map) {i=1, really=2, love=1, coderanch=1}

    A test harness to get you started
    Provided is a simple Java class with the skeleton method signature and a couple of tests that you can use to verify the correct functionality. For writing your solution you are only interested in the method skeleton on lines 6 - 9, this is where you complete the method with your solution to make it function correctly.

    How to run the test harness
    Take a copy of this code and paste it into a file called GeeConComp.java.

    Compile it

    javac GeeConComp.java

    Run it

    java GeeConComp

    Initially the output will report test failures, which is expected as the solution has not been written yet.

    CodeRanch GeeCON Prague 2014 competition
    ========================================
    Test FAIL :(
    Expected: {love=1, coderanch=1, i=1, really=2}
    Actual : null
    Test FAIL :(
    Expected: {better=3, never=1, rest=1, may=1, and=1, i=1, best=2, until=1, is=1, my=2, good=2}
    Actual : null


    What you want to see is passing tests

    CodeRanch GeeCON Prague 2014 competition
    ========================================
    Test PASS :)
    Test PASS :)


    That's it! Enjoy.
     
    M Ga
    Greenhorn
    Posts: 1
    • Likes 1
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Robert LaValley
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Report post to moderator

     
    Jakub Milkiewicz
    Greenhorn
    Posts: 2
    • Likes 1
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Using pure reduction



    or using grouping

     
    Joanne Neal
    Rancher
    Posts: 3742
    16
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Seems like a good way to attract people to the ranch.
    Three attempts so far - two from newly registered people and one that's a first post from someone who registered two and a half years ago.
     
    Tim Cooke
    Marshal
    Posts: 3840
    221
    Clojure IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Joanne Neal wrote:one that's a first post from someone who registered two and a half years ago.

    Yea who does that! (ActiveStaff#timcooke)
    Tim Cooke wrote:Tim joined CodeRanch in 2008 but didn't post a single thing until early 2013. Nobody knows why

    Remember, obfuscation is the name of the game in this competition. We're looking for the most unreadable code you can muster while being functionally correct.
     
    Pawel Szulc
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Jim Young
    Greenhorn
    Posts: 6
    Linux Netbeans IDE Oracle
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Not so obscure but my first attempt.

     
    D Tom
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Campbell Ritchie
    Sheriff
    Posts: 55351
    157
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Welcome to the Ranch all of you.
     
    Pawel Szulc
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I've entered the competition but I still am amazed that you promote "unreadable" code. Whenever at any conference I see companies promoting them selves with contests like "what this Java puzzler do" or "what will be the output of that function" I simply scream and run away. Would you really like to work in a place were you are promoted for understanding unreadable code?

    I like the idea of the "golf rule" as concise code can be still comprehensible. But "unreadable" code by its nature will not.

     
    Campbell Ritchie
    Sheriff
    Posts: 55351
    157
    • Mark post as helpful
    • send pies
    • Report post to moderator
    We do not believe that anybody would produce unreadable code in real life, but wanted to try something along the lines of the famous International Obfuscated C Contests.
     
    Joe Harry
    Ranch Hand
    Posts: 10128
    3
    Eclipse IDE Mac PPC Ubuntu
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Assuming that I can call a Scala method from a Java file, here is my scalafied version:

     
    Tim Cooke
    Marshal
    Posts: 3840
    221
    Clojure IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Joe, remember the rules:
  • Java SE only. No third party libraries allowed.
  • Must compile and run with Java8 JDK and JRE

  • That means no Scala. Sorry Joe.
     
    Joe Harry
    Ranch Hand
    Posts: 10128
    3
    Eclipse IDE Mac PPC Ubuntu
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I will give it another try with Java SE!
     
    Tim Cooke
    Marshal
    Posts: 3840
    221
    Clojure IntelliJ IDE Java
    • Likes 1
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Pawel Szulc wrote:I've entered the competition but I still am amazed that you promote "unreadable" code.

    Hi Pawel. None of us here at the Ranch would ever promote that you write unreadable code in the real world. But for this competition we wanted to make it fun and interesting by getting you thinking a little differently and have you write the most obscure code you can come up with that still solves a simple problem.

    @Joe Harry, You can enter as many times as you like, so go nuts.
     
    Joe Harry
    Ranch Hand
    Posts: 10128
    3
    Eclipse IDE Mac PPC Ubuntu
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Here is my obfuscated version:

     
    Joe Harry
    Ranch Hand
    Posts: 10128
    3
    Eclipse IDE Mac PPC Ubuntu
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I can already see that my obfuscated version fails the test for a String input



    Of course, I can obfuscate it further and fix it. Is it necessary?
     
    Adalberto Toledo
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Adalberto Toledo
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Adalberto Toledo
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Campbell Ritchie
    Sheriff
    Posts: 55351
    157
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Please don't use this thread to develop your applications. Please only post the final versions here.
    If you want to discuss what happens if you post "Campbell Ritchie     is a dreadful nuisance" please go to one of the Java fora.

    Don't copy‑and‑paste this post.
     
    Adalberto Toledo
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Adalberto Toledo
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Sorry, I only was uploading some versions, so you can check which one match the best with the criteria...
     
    Tim Cooke
    Marshal
    Posts: 3840
    221
    Clojure IntelliJ IDE Java
    • Likes 2
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Joe Harry wrote:I can already see that my obfuscated version fails the test for a String input



    Of course, I can obfuscate it further and fix it. Is it necessary?

    No.
    The Rules wrote:The sentence is a String delimited by single whitespace characters. Assume no punctuation.

    That means you don't have to handle multiple whitespace. You can assume it never happens.

    As a general note to all. Please don't forget to UseCodeTags when posting code. Omitting their use does not qualify as a valid obfuscation technique.
     
    Campbell Ritchie
    Sheriff
    Posts: 55351
    157
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Adalberto Toledo wrote: . . . which one match the best with the criteria...
    If the code fulfils the rules of the contest compiles and produces a PASS result from Tim's test harness, each would count as a separate entry. Multiple entries are welcomed
     
    Campbell Ritchie
    Sheriff
    Posts: 55351
    157
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Adalberto Toledo wrote:
    This does not comply with the rules that only standard JavaSE classes may be used. I suggest you resubmit with that import removed. Consider StringJoiner instead.
     
    Adalberto José Toledo
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    vamsee priya
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    Adalberto Toledo
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Campbell Ritchie wrote:
    Adalberto Toledo wrote:
    This does not comply with the rules that only standard JavaSE classes may be used. I suggest you resubmit with that import removed. Consider StringJoiner instead.


    You are right however, my solution is only the wordOccurrence method, that library is only used in the Main method, just for running the program and convert the arguments passed by the Command Line Interface (CLI), to a String delimited by a single whitespace.

    Anyway, I appreciate your suggestion and I will consider the StringJoiner Class instead of the StringUtils Class.

    Please, try to evaluate only my wordOccurrence method because that is my solution.

    Before that solution, I submitted a solution without the Main method and it doesn't have that library imported, do you want me to submit it again?

    Thanks a lot

    Best Regards
     
    Tim Cooke
    Marshal
    Posts: 3840
    221
    Clojure IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Adalberto Toledo wrote:that library is only used in the Main method

    Noted. Solution accepted.
     
    Piotr Kalinowski
    Greenhorn
    Posts: 6
    Eclipse IDE Java Linux
    • Likes 3
    • Mark post as helpful
    • send pies
    • Report post to moderator
     
    subh kumar
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Report post to moderator
    //soln by subh71@gmail.com
     
    subh kumar
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Report post to moderator
    subh kumar wrote://soln by subh71@gmail.com
     
    subh kumar
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Report post to moderator
    subh kumar wrote:
    subh kumar wrote://soln by subh71@gmail.com
     
    subh kumar
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Report post to moderator
    subh kumar wrote:
    subh kumar wrote:
    subh kumar wrote://soln by subh71@gmail.com
     
    subh kumar
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Report post to moderator
    subh kumar wrote:
    subh kumar wrote:
    subh kumar wrote:
    subh kumar wrote://soln by subh71@gmail.com
     
      Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!