6
\$\begingroup\$

I would like to propose a new kind of challenge: Anti Code Golf! (as anti-golf, not anti-code). The idea is to write the longest program you can write to do something.

That would be Code Bowling, as pointed out by ProgramFOX.

Rules

  • No ridiculously unnecessary whitespace (e.g. 3 lines between each statement, etc. indentation is OK, just don't overuse).

  • Score is awarded by number of bytes used to work * (in source code, input data or output data) memory usage doesn't count.

  • Highest score wins. In the event of a tie, most upvoted wins. In the event of a voting tie a randomly chosen answer wins.

  • You may not read from a external resource, such as a file or web service, except (when possible) the program's own source code and/or a file/service provided by the program itself.

  • The program must run in a reasonable time (< 5 minutes) except where otherwise specified.

.* Comments do not count for length.


Now, onto the challenge itself:

Write a program that prints the full date of tomorrow to stdout (or equivalent) in ASCII encoding. It may or not receive any arguments, but the current date must not be input directly by the user.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ That's called a "Code Bowling", not a "Anti Code Golf". Such challenges already exist. I updated your question. Also, an important hint: forbid comments and network access. \$\endgroup\$
    – ProgramFOX
    Jan 14, 2014 at 18:24
  • \$\begingroup\$ Sorry for that, should have searched more thoroughly first. Good idea about network access and comments \$\endgroup\$
    – Kroltan
    Jan 14, 2014 at 18:27
  • \$\begingroup\$ I'm a bit confused: a program that starts with "int a=1, b=2, c=3,..... " up to 1.000.000 counts as millions of bytes? \$\endgroup\$
    – friol
    Jan 14, 2014 at 18:53
  • 1
    \$\begingroup\$ I never really got the meaning of code-bowling. For example solution like this is allowed or not? pastebin.com/Km0tD0v0 \$\endgroup\$
    – manatwork
    Jan 14, 2014 at 19:44
  • 3
    \$\begingroup\$ I’m voting to close this question because code bowling requires an additional objective validity criterion in order to make sense as a scoring criterion. \$\endgroup\$ Apr 11 at 14:58

7 Answers 7

9
\$\begingroup\$

C# - ~500Kb -

Don't you love nested if's? Used to work only for 2014 dates, but successfully refactored to work for any date :)

Cannot post code here, I just receive an error...

http://pastebin.com/azGr3JSz

(Will probably hang your browser, sorry)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Damn it, you crashed my browser. I guess that means you win :P \$\endgroup\$
    – Cheezey
    Jan 16, 2014 at 3:38
  • 1
    \$\begingroup\$ I like how the final else to make it "work for any date" is the only useful part of the code :-). \$\endgroup\$ Jan 16, 2014 at 5:32
  • 1
    \$\begingroup\$ Well, your answer may be easily improved, but I think you should post a code which generated your answer, or maybe you wrote everything yourself? :D \$\endgroup\$
    – ST3
    Jan 17, 2014 at 13:43
  • \$\begingroup\$ Can't find the generating code, sorry :( \$\endgroup\$ Jan 17, 2014 at 13:55
5
\$\begingroup\$

JavaScript, 2015 chars (all reasonably useful)

I believe this is in the spirit of the question. ;)

Based on one of my previous answers

// we all know that OOP == good
function TomorrowManager() {
    // constants == good too
    this.values = {
        ERROR: 1, // value on error
        UNINITIALIZED:  2, // value when not initialized yet
        OK: 0 // desired value
    }
    this.consts = {
        HOURS_IN_DAY: 24,
        MINUTES_IN_HOUR: 60,
        SECONDS_IN_MINUTE: 60,
        MILLISECONDS_IN_SECOND: 1000
    }
    this.value = this.values.UNINITIALIZED
}
TomorrowManager.prototype.setValue = function(num) {
    if (typeof num !== 'number') throw new Error('cannot set value to non-number')
    if (!this.value) this.value = this.values.ERROR // oh noes
    else this.value = num
}
// initialize the value
TomorrowManager.prototype.initialize = function() {
    this.setValue(this.values.OK) // set the value to ONE
    return true // return true for success
}
// get the value
TomorrowManager.prototype.getValue = function() {
    if (this.value == this.values.ERROR) { // if the value is ERROR
        throw new Error('value not initialized')
    } else return this.value // return the value
}
TomorrowManager.prototype.getTomorrow = function() {
    return new Date(new Date().getTime() + this.consts.HOURS_IN_DAY * this.consts.MINUTES_IN_HOUR * this.consts.SECONDS_IN_MINUTE * this.consts.MILLISECONDS_IN_SECOND)
}

function TomorrowManagerFactory() {}
TomorrowManagerFactory.prototype.getTomorrowManager = function() {
    return new TomorrowManager()
}

function getTomorrow() {
    var m = new TomorrowManagerFactory().getTomorrowManager() // make a TomorrowManager
    var success = m.initialize() // initialize the value
    if (success) {
        if (m.getValue() === m.values.OK) {
            return m.getTomorrow()
        } else {
            throw new Error('bad value')
        }
    }
    else {
        // there was an error in the initialization
        var retVal = m.values.ERROR // we will return an error
        delete m // maybe it's corrupted
        throw new Error('corrupted TomorrowManager')
        return retVal // return an error in case the throw didn't work
    }
}

alert(getTomorrow())
\$\endgroup\$
2
  • \$\begingroup\$ Seems awesome! But I must say, OOP instanceof Good. Exactly the kind of answer expected, very long and verbose, yet without random code not related to the functionality. \$\endgroup\$
    – Kroltan
    Jan 14, 2014 at 22:15
  • \$\begingroup\$ Putting the "Java" in JavaScript. \$\endgroup\$
    – Mark Reed
    Apr 11 at 15:40
5
\$\begingroup\$

Lua - 7159

-- Let's begin by implementing OOP
-- Lua does not have OOP but it has the tools to implement it

local class = {}

function class:inherit()
    local class = {}
    class.class = class
    class.__index = self
    class.ancestor = self
    return setmetatable(class, class)
end
function class:new(initializer)
    local object = initializer or {}
    object.__index = self
    setmetatable(object, object)
    if self.__init  then
        self.__init(object)
    end
    return object
end
function class:super(meth, ...)
    local ancestor = self.ancestor
    local class = self.class
    local __index = self.__index
    self.__index = class.ancestor
    self.class = class.ancestor
    self.ancestor = class.ancestor.ancestor
    return (function(...)
        self.ancestor = ancestor
        self.class = class
        self.__index = __index
        return ...
    end)(self[meth](self, ...))
end

-- Now let's create a few classes used for counting

local counter = class:inherit()
counter.value = 1
function counter:setValue(value)
    self.value = value
end
function counter:getValue()
    return self.value
end
function counter:increment()
    self:setValue(self:getValue() + 1)
end

local boundedCounter = counter:inherit()
counter.maxbound = 1
counter.minbound = 1
function boundedCounter:setMaxbound(value)
    self.maxbound = value
end
function boundedCounter:getMaxbound()
    return self.maxbound
end
function boundedCounter:setMinbound(value)
    self.minbound = value
end
function boundedCounter:getMinbound()
    return self.minbound
end
function boundedCounter:increment()
    self:super"increment"
    if self:getValue() > self:getMaxbound() then
        self:setValue(self:getMinbound())
    end
end

local signalingBoundedCounter = boundedCounter:inherit()
counter.signal = function() end
function signalingBoundedCounter:setSignal(value)
    self.signal = value
end
function signalingBoundedCounter:getSignal()
    return self.signal
end
function signalingBoundedCounter:setUservalue(value)
    self.uservalue = value
end
function signalingBoundedCounter:getUservalue()
    return self.uservalue
end
function signalingBoundedCounter:increment()
    self:super"increment"
    if self:getValue() == 0 then
        self:getSignal()(self:getUservalue())
    end
end

-- Other miscelaneous classes we will need

local formatStringBuilder = class:inherit()
formatStringBuilder.string = ""
function formatStringBuilder:appendString(string)
    self.string = self.string .. string:gsub("%%", "%%%%")
end
function formatStringBuilder:appendFormat(specifier, length, decimals)
    length = tonumber(length)
    decimals = tonumber(decimals)
    specifier = tostring(specifier)
    local format = "%"
    if length then
        if length < 0 then
            format = format .. "0" .. -length
        else
            format = format .. length
        end
    end
    if decimals then
        format = format .. "." .. decimals
    end
    format = format .. specifier
    self.string = self.string .. format
end

function formatStringBuilder:getString()
    return self.string
end
function formatStringBuilder:format(...)
    return self.string:format(...)
end

local applicationFunction = class:inherit()
function applicationFunction:__call()
    return self.callback(unpack(self.arguments))
end
function applicationFunction:__init()
    self.__call = self.__call -- DO NOT REMOVE OR IT WILL NOT WORK
end

local case = class:inherit()
function case:__init()
    self.cases = {}
    self.handlers = {}
end
function case:addCase(case, handler)
    self.cases[#self.cases + 1] = case
    self.handlers[#self.handlers + 1] = handler
end
function case:execute(value)
    for iterator, case in ipairs(self.cases) do
        if case == value then
            self.handlers[case]()
            break
        end
    end
end

-- The main code:

local yearsFormat = formatStringBuilder:new()
yearsFormat:appendFormat"Y"
local monthsFormat = formatStringBuilder:new()
monthsFormat:appendFormat"m"
local daysFormat = formatStringBuilder:new()
daysFormat:appendFormat"d"
local todaysYear = tonumber(os.date(yearsFormat:getString()))
local todaysMonth = tonumber(os.date(monthsFormat:getString()))
local todaysDay = tonumber(os.date(daysFormat:getString()))

-- Let's store the year as a four-digit number

local thousandsOfYearsCounter = counter:new()
thousandsOfYearsCounter:setValue(0)
local hundredsOfYearsCounter = signalingBoundedCounter:new()
hundredsOfYearsCounter:setMaxbound(9)
hundredsOfYearsCounter:setMinbound(0)
hundredsOfYearsCounter:setValue(0)
hundredsOfYearsCounter:setSignal(thousandsOfYearsCounter.increment)
hundredsOfYearsCounter:setUservalue(thousandsOfYearsCounter)
local tensOfYearsCounter = signalingBoundedCounter:new()
tensOfYearsCounter:setMaxbound(9)
tensOfYearsCounter:setMinbound(0)
tensOfYearsCounter:setValue(0)
tensOfYearsCounter:setSignal(hundredsOfYearsCounter.increment)
tensOfYearsCounter:setUservalue(hundredsOfYearsCounter)
local yearsCounter = signalingBoundedCounter:new()
yearsCounter:setMaxbound(9)
yearsCounter:setMinbound(0)
yearsCounter:setValue(0)
yearsCounter:setSignal(tensOfYearsCounter.increment)
yearsCounter:setUservalue(tensOfYearsCounter)

for interator = 1, todaysYear do
    yearsCounter:increment()
end

local monthsCounter = signalingBoundedCounter:new()
monthsCounter:setMaxbound(12)
monthsCounter:setMinbound(1)
monthsCounter:setValue(0)
monthsCounter:setSignal(yearsCounter.increment)
monthsCounter:setUservalue(yearsCounter)

for interator = 1, todaysMonth do
    monthsCounter:increment()
end

local daysCounter = signalingBoundedCounter:new()

-- Depending on the months, there's different amount of days
 
local monthDaysCase = case:new()
monthDaysCase:addCase(1, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 31}})
monthDaysCase:addCase(2, function()
    if todaysYear % 4 == 0 then
        if todaysYear % 100 == 0 then
            if todaysYear % 400 == 0 then
                daysCounter:setMaxbound(29)
            else
                daysCounter:setMaxbound(28)
            end
        else
            daysCounter:setMaxbound(29)
        end
    else
        daysCounter:setMaxbound(28)
    end
end)
monthDaysCase:addCase(3, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 31}})
monthDaysCase:addCase(4, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 30}})
monthDaysCase:addCase(5, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 31}})
monthDaysCase:addCase(6, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 30}})
monthDaysCase:addCase(7, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 31}})
monthDaysCase:addCase(8, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 31}})
monthDaysCase:addCase(9, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 30}})
monthDaysCase:addCase(10, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 31}})
monthDaysCase:addCase(11, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 30}})
monthDaysCase:addCase(12, applicationFunction:new{callback = daysCounter.setMaxbound, arguments = {daysCounter, 31}})
monthDaysCase:execute(todaysMonth)

daysCounter:setMinbound(1)
daysCounter:setValue(0)
daysCounter:setSignal(monthsCounter.increment)
daysCounter:setUservalue(monthsCounter)

for interator = 1, todaysDay do
    daysCounter:increment()
end

daysCounter:increment()

local tomorrowsYear = thousandsOfYearsCounter:getValue() * 1000 + hundredsOfYearsCounter:getValue() * 100 + tensOfYearsCounter:getValue() * 10 + yearsCounter:getValue()
local tomorrowsMonth = monthsCounter:getValue()
local tomorrowsDay = daysCounter:getValue()

local dateFormat = formatStringBuilder:new()
dateFormat:appendFormat"d"
dateFormat:appendString"/"
dateFormat:appendFormat("d", -2)
dateFormat:appendString"/"
dateFormat:appendFormat("d", -2)
local tomorrowsDateString = dateFormat:format(tomorrowsYear, tomorrowsMonth, tomorrowsDay)
print(tomorrowsDateString)

Scoring: perl -pe 's/--.*\n//g;s/\s/ /mg;s/ */ /g;s/(\W) (\S)/$1$2/g;s/(\S) (\W)/$1$2/g;' < nextday.lua|wc -c (basically remove all whitespace that can be removed)

Also do not remove the DO NOT REMOVE marked line, it really will not work

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I don't know Lua but the line that essentially looks to me like 1=1 --DO NOT REMOVE OR IT WILL NOT WORK made me laugh, +1. \$\endgroup\$
    – FGreg
    Jan 15, 2014 at 22:23
  • \$\begingroup\$ @FGreg Roughly speaking it has an overridden field access operation, which tells it to fallback on the class table. What this does is get the value of self.__call using the overridden operation (i.e basically fetches it from the class table), and then sets it as a field in object table. \$\endgroup\$
    – mniip
    Jan 15, 2014 at 23:22
2
\$\begingroup\$

C#: 33,053 characters

I had to post the code on Pastebin because it was too long to post here in an answer:
http://pastebin.com/SwwB30Jy

How it works: the byte array actually contains the following code:

using System;namespace GetDateOfTomorrow{public static class Tomorrow{public static string GetDateOfTomorrow(){ return DateTime.Today.AddDays(1).ToShortDateString();}}}

Then, you compile that code to a new assembly and execute the GetDateOfTomorrow() method.

\$\endgroup\$
1
\$\begingroup\$

Mathematica 958

The following returns tomorrow's date, including the day of week.

date = "Date";
command1 = ToExpression[date <> ToString[Head["Calendar"]]]
ClearAll[a, b, c, d]
TreeForm[a + b^2 + c^3 + d]
command2 = ToExpression[date <> ToString[Part[%, 0]]]
months = {"January", "February", "March", "April", "May", "June", 
  "July", "August", "September", "October", "November", "December"}
command3 = ToExpression[date <> ToString[Head[months]]]
daysOfTheWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", 
  "Thursday", "Friday", "Saturday"} 
days = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
    19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
command4 = 
 ToExpression[
  StringJoin[
   Take[Characters[
      Part[daysOfTheWeek[[RandomInteger[{1, 7}]]]]], -3] /. {char1_, 
      char2_, char3_} :> 
     StringJoin["", {ToUpperCase[char1], char2, char3}], 
   ToString[Head[days]]]]
AstrologicalSigns = {"Aries", "Taurus", "Gemini", "Cancer", "Leo", 
  "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius",
   "Pisces"}

Testing

command1[command2[command3[TimeZone -> $TimeZone], 
  Fibonacci[7] - Length[AstrologicalSigns]], {"DayName", ", ", 
  "MonthName", " ", "Day", ", ", "Year"}]

"Wednesday, January 15, 2014"

\$\endgroup\$
1
\$\begingroup\$

JAVA (2910 4406 characters)

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Date;

public class Tomorrow {
    
    private static class DayOfMonth {
        
        private int value;
        
        public DayOfMonth(int value) {
            this.value = value;
        }
        
        public void setValue(int value) {
            this.value = value;
        }
        
        public int getValue() {
            return value;
        }
        
        @Override
        public String toString() {
            return Integer.toString(value);
        }
        
    }
    
    private static class MonthOfYear {
        
        private int value;
        
        public MonthOfYear(int value) {
            this.value = value;
        }
        
        public void setValue(int value) {
            this.value = value;
        }
        
        public int getValue() {
            return value;
        }
        
        @Override
        public String toString() {
            return new DateFormatSymbols().getMonths()[this.getValue()];
        }
        
    }
    
    private static class YearOfEverything {
        
        private int value;
        
        public YearOfEverything(int value) {
            this.value = value;
        }
        
        public void setValue(int value) {
            this.value = value;
        }
        
        public int getValue() {
            return value;
        }
        
        @Override
        public String toString() {
            return new StringBuilder("").append(Math.abs(value)).append(' ').append((value < 0) ? "BCE" : (value == 0) ? "" : "CE").toString();
        }
        
    }
    
    private static class DateManager {
        
        private DayOfMonth day;
        private MonthOfYear month;
        private YearOfEverything year;
        
        public DateManager() {
            this.day = null;
            this.month = null;
            this.year = null;
        }
        
        public void setDayOfMonth(int day) {
            this.day = new DayOfMonth(day);
        }
        
        public void setMonthOfYear(int month) {
            this.month = new MonthOfYear(month);
        }
        
        public void setYearOfEverything(int year) {
            this.year = new YearOfEverything(year);
        }
        
        public DayOfMonth getDayOfMonth() {
            return day;
        }
        
        public MonthOfYear getMonthOfYear() {
            return month;
        }
        
        public YearOfEverything getYearOfEverything() {
            return year;
        }
        
        @Override
        public String toString() {
            return new StringBuilder("").append(this.getMonthOfYear().toString()).append(' ').append(this.getDayOfMonth().toString()).append(", ").
                       append(this.getYearOfEverything().toString()).toString();
        }
        
    }
    
    public static final int MONTHS_PER_YEAR = 12;
    
    public static boolean isLeapYear(YearOfEverything year) {
        int yearNum = year.getValue();
        if ((yearNum % 4 == 0) && (yearNum % 100 != 0))
            return true;
        else if (yearNum % 400 == 0)
            return true;
        else
            return false;
    }
    
    public static int getDaysInMonth(MonthOfYear month, YearOfEverything year) {
        if (month.getValue() == 1) {
            if (isLeapYear(year))
                return 29;
            else
                return 28;
        } else if ((month.getValue() == 3) || (month.getValue() == 5) || (month.getValue() == 8) || (month.getValue() == 10)) {
            return 30;
        } else {
            return 31;
        }
    }
    
    public static void main(String[] args) {
        
        DateManager manager = new DateManager();
        Calendar calendar = Calendar.getInstance();
        manager.setDayOfMonth(calendar.get(Calendar.DATE));
        manager.setMonthOfYear(calendar.get(Calendar.MONTH));
        manager.setYearOfEverything(calendar.get(Calendar.YEAR));
        
        manager.getDayOfMonth().setValue(manager.getDayOfMonth().getValue() + 1);
        if (manager.getDayOfMonth().getValue() > getDaysInMonth(manager.getMonthOfYear(), manager.getYearOfEverything())) {
            manager.setDayOfMonth(1);
            manager.getMonthOfYear().setValue(manager.getMonthOfYear().getValue() + 1);
            if (manager.getMonthOfYear().getValue() >= MONTHS_PER_YEAR) {
                manager.setMonthOfYear(1);
                manager.getYearOfEverything().setValue(manager.getYearOfEverything().getValue() + 1);
            }
        }
        
        System.out.println(manager.toString());
        
    }
    
}
\$\endgroup\$
4
  • \$\begingroup\$ Whitespace should be counted too. \$\endgroup\$
    – Kroltan
    Jan 15, 2014 at 9:42
  • \$\begingroup\$ Please use Markdown for formatting instead of HTML. A large part of your code was not displayed due to < operator: in Markdown code block they get transformed into HTML character entities automatically, but in HTML <pre> block you have to take care of them. \$\endgroup\$
    – manatwork
    Jan 15, 2014 at 18:10
  • \$\begingroup\$ Sorry about that. Just found it easier than indenting each line, I suppose. I'll keep that in mind. And I fixed the count. Thanks, @Kroltan, for letting me know. \$\endgroup\$ Jan 19, 2014 at 6:22
  • \$\begingroup\$ You not have to indent each line manually. Select the code block then either press Ctrl-K or click the “{}” button in the answer form's toolbar. \$\endgroup\$
    – manatwork
    Jan 19, 2014 at 15:22
-1
\$\begingroup\$

Hippopotomonstrosesquipedalian 2, ~66.6MB

Code (Your browser WILL hang)

Compiler

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.