Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

2014 Code Golf Challenge

by tobyink (Canon)
on Jan 01, 2014 at 11:46 UTC ( [id://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

Replies are listed 'Best First'.
Re: 2014 Code Golf Challenge
by BrowserUk (Patriarch) on Jan 01, 2014 at 11:55 UTC
    [0] Perl> print ~'═¤╬╦';;

    2014


    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 LanX (Saint) 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)

      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 am getting 1024, too (reverse in list context). Fix:
        perl -lwe 'print~~reverse unpack HU,Ffman'
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

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

      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.

Re: 2014 Code Golf Challenge
by hdb (Monsignor) 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
Re: 2014 Code Golf Challenge
by snoopy (Curate) on Jan 01, 2014 at 21:15 UTC
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 (' ','',' ',' ')"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found