August 2009 Programming Challenge : Give it a bash!

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

That sounds like a good one! Will work out the challenge rules and post it. Thanks Joe!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Already got a few good ideas with this one, but I think I'll wait on the official rules to make sure I'm not wasting effort. :D
  • George L.
  • Bronze Member
  • Bronze Member
  • George L.
  • Posts: 2209
  • Loc: Malaysia

Post 3+ Months Ago

UPSGuy wrote:
Batter up!

Perl:
Code: [ Select ]
 
sub convert {
     $_[0] =~ s/([a-z]|[0-9])/((ord($1)%39)>18)?uc(chr(ord($1)+13)):uc(chr(ord($1)+52))/eg && return $_[0];
}
 
  1.  
  2. sub convert {
  3.      $_[0] =~ s/([a-z]|[0-9])/((ord($1)%39)>18)?uc(chr(ord($1)+13)):uc(chr(ord($1)+52))/eg && return $_[0];
  4. }
  5.  

Hi UPSGuy, can you write the complete code? this is a real noob question I know, sorry guys. I am sure we have to write the string "8cdb2408-81e3-4b8c-9ba2-916c14927946" somewhere in your code? Thanks.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

I am under the impression that the string would be a parameter when calling the sub convert
  • George L.
  • Bronze Member
  • Bronze Member
  • George L.
  • Posts: 2209
  • Loc: Malaysia

Post 3+ Months Ago

I am not sure what do you mean, Rabid Dog..
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Code: [ Select ]
convert "8cdb2408-81e3-4b8c-9ba2-916c14927946"
  • George L.
  • Bronze Member
  • Bronze Member
  • George L.
  • Posts: 2209
  • Loc: Malaysia

Post 3+ Months Ago

Is it written before or after the sub convert?

Tried both, didn't work..
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

http://www.webreference.com/programming ... broutines/
  • IcyDragoon
  • Student
  • Student
  • IcyDragoon
  • Posts: 65

Post 3+ Months Ago

I am a C++ person, xD

CPP Code: [ Select ]
string guid2Str(string GUID){
    string result;
    for(int i = 0; i < GUID.size(); ++i)
        if(GUID[i] == '-')
            result += '-';
        else
            result += (GUID[i] < 58)?static_cast<char>(GUID[i]+20):static_cast<char>(GUID[i]-19);
    return result;
}
  1. string guid2Str(string GUID){
  2.     string result;
  3.     for(int i = 0; i < GUID.size(); ++i)
  4.         if(GUID[i] == '-')
  5.             result += '-';
  6.         else
  7.             result += (GUID[i] < 58)?static_cast<char>(GUID[i]+20):static_cast<char>(GUID[i]-19);
  8.     return result;
  9. }
  • IcyDragoon
  • Student
  • Student
  • IcyDragoon
  • Posts: 65

Post 3+ Months Ago

another one .... in C++

CPP Code: [ Select ]
string guid2Str2(string GUID){
    string result;
    char ch[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int i = 0; i < GUID.size(); ++i)
        if(GUID[i] == '-')
            result += '-';
        else
            result += (GUID[i] > '9')?ch[GUID[i]-84]:ch[GUID[i]-45];
    return result;
}
  1. string guid2Str2(string GUID){
  2.     string result;
  3.     char ch[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  4.     for(int i = 0; i < GUID.size(); ++i)
  5.         if(GUID[i] == '-')
  6.             result += '-';
  7.         else
  8.             result += (GUID[i] > '9')?ch[GUID[i]-84]:ch[GUID[i]-45];
  9.     return result;
  10. }


hmmm... I guess my 2 solutions are basically the same.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Hey George, sorry for the delay. Something like this is what you want. I added the 'input' and 'expected' line as I was working on the script. It helped me to know when I got it right.

PERL Code: [ Select ]
 
#!/usr/bin/perl -w
 
use strict;
 
my $sIn = '8cdb2408-81e3-4b8c-9ba2-916c14927946';
print "input:   $sIn\n";
print "expected: LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ\n";
print "output:  ".convert($sIn)."\n";
sub convert {
     $_[0] =~ s/([a-z]|[0-9])/((ord($1)%39)>18)?uc(chr(ord($1)+13)):uc(chr(ord($1)+52))/eg && return $_[0];
}
 
# EXECUTE COMMAND:
# ./challenge1.pl
#
# OUTPUT:
# input:    8cdb2408-81e3-4b8c-9ba2-916c14927946
# expected: LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ
# output:   LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ
 
  1.  
  2. #!/usr/bin/perl -w
  3.  
  4. use strict;
  5.  
  6. my $sIn = '8cdb2408-81e3-4b8c-9ba2-916c14927946';
  7. print "input:   $sIn\n";
  8. print "expected: LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ\n";
  9. print "output:  ".convert($sIn)."\n";
  10. sub convert {
  11.      $_[0] =~ s/([a-z]|[0-9])/((ord($1)%39)>18)?uc(chr(ord($1)+13)):uc(chr(ord($1)+52))/eg && return $_[0];
  12. }
  13.  
  14. # EXECUTE COMMAND:
  15. # ./challenge1.pl
  16. #
  17. # OUTPUT:
  18. # input:    8cdb2408-81e3-4b8c-9ba2-916c14927946
  19. # expected: LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ
  20. # output:   LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ
  21.  


Alternatively, you could have the script take the input as a parameter, like this:

PERL Code: [ Select ]
 
#!/usr/bin/perl -w
 
use strict;
 
my $sIn;
 
if(defined($ARGV[0])) {
    $sIn = $ARGV[0];
} else {
    print "Please provide the string to convert as the first parameter.\nExample: ./challenge1.pl 8cdb2408-81e3-4b8c-9ba2-916c1492794\n";
    exit(0);
}
 
print "output:  ".convert($sIn)."\n";
 
sub convert {
     $_[0] =~ s/([a-z]|[0-9])/((ord($1)%39)>18)?uc(chr(ord($1)+13)):uc(chr(ord($1)+52))/eg && return $_[0];
}
 
# EXECUTE COMMAND:
# ./challenge1.pl 8cdb2408-81e3-4b8c-9ba2-916c14927946
#
# OUTPUT:
# output:  LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ 
 
  1.  
  2. #!/usr/bin/perl -w
  3.  
  4. use strict;
  5.  
  6. my $sIn;
  7.  
  8. if(defined($ARGV[0])) {
  9.     $sIn = $ARGV[0];
  10. } else {
  11.     print "Please provide the string to convert as the first parameter.\nExample: ./challenge1.pl 8cdb2408-81e3-4b8c-9ba2-916c1492794\n";
  12.     exit(0);
  13. }
  14.  
  15. print "output:  ".convert($sIn)."\n";
  16.  
  17. sub convert {
  18.      $_[0] =~ s/([a-z]|[0-9])/((ord($1)%39)>18)?uc(chr(ord($1)+13)):uc(chr(ord($1)+52))/eg && return $_[0];
  19. }
  20.  
  21. # EXECUTE COMMAND:
  22. # ./challenge1.pl 8cdb2408-81e3-4b8c-9ba2-916c14927946
  23. #
  24. # OUTPUT:
  25. # output:  LPQOFHDL-LERG-HOLP-MONF-MEJPEHMFKMHJ 
  26.  


There's always more than one way to do something in perl, but these are good starter examples. I tried not to over simplify or obfuscate the code.
  • George L.
  • Bronze Member
  • Bronze Member
  • George L.
  • Posts: 2209
  • Loc: Malaysia

Post 3+ Months Ago

UPSGuy, Thanks very much I am late myself - reading this message.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

We're into September now, what say you all to wrapping this one up and moving on to another?
  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Posts: 239
  • Loc: Western Australia

Post 3+ Months Ago

Have some very quick and ugly code:

(I'm currently learning arrays in java, they're amazing)

JAVA Code: [ Select ]
    public String sampleMethod(String input)
    {
        String output = "";
        String[] parts = input.split("-");
        char[][] moreparts = new char[parts.length][0];
       
        for (int i = 0; i<parts.length; i++){
            moreparts[i] = parts[i].toCharArray();
           
            for(int j = 0; j<moreparts[i].length; j++){
               
                output += (char) (Integer.parseInt(moreparts[i][j]+"",16)  +68 );
           
            }
           
            if(i < parts.length - 1) output += "-";
        }
       
        return output;
    }
  1.     public String sampleMethod(String input)
  2.     {
  3.         String output = "";
  4.         String[] parts = input.split("-");
  5.         char[][] moreparts = new char[parts.length][0];
  6.        
  7.         for (int i = 0; i<parts.length; i++){
  8.             moreparts[i] = parts[i].toCharArray();
  9.            
  10.             for(int j = 0; j<moreparts[i].length; j++){
  11.                
  12.                 output += (char) (Integer.parseInt(moreparts[i][j]+"",16)  +68 );
  13.            
  14.             }
  15.            
  16.             if(i < parts.length - 1) output += "-";
  17.         }
  18.        
  19.         return output;
  20.     }
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Nice! I am working on a new challenege lads, just bear with me :)
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Rabid Dog wrote:
Nice! I am working on a new challenege lads, just bear with me :)


http://animals.timduru.org/dirlist/bear ... OnSnow.jpg
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

I see what you did there.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Thats not a bear
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Rabid Dog wrote:
Thats not a bear


I don't get it - is this one of those Crocodile Dundee things?

"That's not a bear! THIS is a bear..."

Image

Credit to reddit. I'm a poet and didn't know it.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

HAHHAHAHAHAHAH THAT IS A BEAR!

Post Information

  • Total Posts in this topic: 50 posts
  • Users browsing this forum: No registered users and 117 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.