Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

2014 Code Golf Challenge

by tobyink (Abbot)
on Jan 01, 2014 at 11:46 UTC ( #1068852=obfuscated: print w/ replies, xml ) Need Help??

There's a 2014 themed golf competition on Stack Exchange. The challenge is to print the characters "2014" without using any digits in your source code.

Sadly using the N'Ko letter "ka" is ruled out because it would require use utf8 (which includes the digit "8").

My solution is 17 characters. If you swap print for die you can reduce it by two characters, but I consider that to be a cheat.

print RPQT^'````'

Can anyone improve upon it?

Update: a one character improvement:

print'````'^RPQT
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Comment on 2014 Code Golf Challenge
Select or Download Code
Re: 2014 Code Golf Challenge
by BrowserUk (Pope) on Jan 01, 2014 at 11:55 UTC

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I've not been able to make that work in any character set supported by any of my text editors, but I believe I understand the principle. "" seems to work in ISO-8859-1 and ISO-8859-15.

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
        I've not been able to make that work in any character set supported by any of my text editors

        My console defaults to code page 850 (see the pic.)

        What I did was print:
        [0] Perl> print ~'2014';;
        ═╬╦

        And then c&p the output back inside the string:
        [0] Perl> print ~'═╬╦';;
        2014

        Presumably if you do the same thing on your local console you should be able to get the same effect although the displayed glyphs will be different. (Though I guess it won't work for Unicrap consoles :)


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: 2014 Code Golf Challenge
by snoopy (Deacon) on Jan 01, 2014 at 21:15 UTC
Re: 2014 Code Golf Challenge
by LanX (Canon) on Jan 01, 2014 at 21:27 UTC
    well not the shortest, but funnily obfuscated and maybe an inspiration =)

    DB<115> (hex hex e) . (hex e) => 2014

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    BTW: "Hexe" means "witch"/"hag" in German, maybe an omen for supernatural things to come? :)

Re: 2014 Code Golf Challenge
by ambrus (Abbot) on Jan 02, 2014 at 20:44 UTC

    Not very short, but works:

    print reverse$/,unpack HU,Ffman

    Update: ok, make that

    print~~reverse$/,unpack HU,Ffman
    (thanks, choroba)

      Care to explain that one? And more interestingly; how you discovered it? )

      (I thought I was pretty oh-fay with un pack, but that ...? )

        unpack "C", "f" or unpack "c", "f" or unpack "U", "f" or ord "f" all give the character code of "f", which is 102. unpack "H", "A" gives "4", and you can replace the "A" with any other letter between "@" and "O". Thus, unpack "HC", "Af" returns ("4", 102). If you concatenate and reverse that list, you get "2014". From there, I just had to modify the strings until it gave something meaningful instead of random letters.

      Just a shame it depends on the underlying architecture or how perl was built. Beautiful though. I get:

      $ perl -we'print reverse$/,unpack HU,Ffman' 1024

      on all my current boxes, including Windows 7, and with all versions of perl from 5.6.0 .. 5.19.6. (5.005 and 5.004 don't know "U", so they print 1 and 5.003_07 prints 4)


      Enjoy, Have FUN! H.Merijn

        I don't think it depends on the architecture on anything else.

        I am getting 1024, too (reverse in list context). Fix:
        perl -lwe 'print~~reverse unpack HU,Ffman'
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: 2014 Code Golf Challenge
by rje (Deacon) on Jan 06, 2014 at 17:22 UTC
    Mine are too long, not clever, and not obfuscated. Does participation count?
    perl -e "print length(' '), length(''), length(' '), length(' ')" or perl -e "print length for (' ','',' ',' ')"
Re: 2014 Code Golf Challenge
by hdb (Prior) on Jan 07, 2014 at 08:16 UTC

    The source must not contain any digits, but if you name your script '2014', then the following does the job ;)

    print${$|}

      That's clever. I must admit that it took me a while to figure out what was going on there.

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://1068852]
Approved by BrowserUk
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-25 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls