Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code Golf: produce the number 2014 without any numbers in your source code

    Stata fun activity: produce the number 2014 without any numbers in your source code (motivated by http://codegolf.stackexchange.com/q/17005/29454).

    Brute force: 2014 is the current year, so it should be a part of the current date (33 characters, unstable, only works this year):
    Code:
    di `: word `=floor(_pi)' of $S_DATE'
    Stable: uses conversion of Stata dates, and circumvents some rounding to get there (37 characters):
    Code:
    di ceil(year(exp(_pi*_pi))+sqrt(_pi))
    The gold standard data set (36 characters, counting 2 CRs; depends on set varabbrev on, and exploits display weight being interpreted by Stata as display weight[1]):
    Code:
    sysuse auto, clear
    di w-l*(h+h)+tr+r
    Last edited by skolenik; 16 Jul 2014, 01:15.
    -- Stas Kolenikov || http://stas.kolenikov.name
    -- Principal Survey Scientist, Abt SRBI
    -- Opinions stated in this post are mine only


  • #2
    Code:
    di strlen("AAAA...AA")
    guess how many times?
    Easily modified for 2015 too.

    Another one:
    Code:
    mata ascii("cabe")-ascii("aaaa")
    Another one:
    Code:
    fromroman "MMXIV"
    -fromroman- is not in base Stata's installation and to fulfil Statalist's requirements, here is the reference to where it is described:
    http://www.stata-journal.com/sjpdf.h...iclenum=dm0054
    Sergiy Radyakin

    Comment


    • #3
      How about something like the following?
      Code:
      inten `=length(c(Mons))' GE
      I'm not sure whether Stata stores handy constants anywhere else but the creturns.

      Comment


      • #4
        I was thinking along the same lines as Sergiy in his second example, but since he cheated and produced a vector instead of a scalar, here is something similar that produces a scalar:

        Code:
        mata (ascii("x")-ascii("d"))*ascii("d")+ascii("r")-ascii("d")

        Comment

        Working...
        X