Problem of the Day
A new programming or logic puzzle every Mon-Fri

Problem of the Day Golf

Building on yesterday's problem, take your solution and cut the amount of code used by at least 25%. That means that if your solution was 100 characters your new one should be no more than 75 characters. New line, tab, and space characters all count towards your character total.

Permalink: http://problemotd.com/problem/problem-of-the-day-golf/

Comments:

  • Lash - 10 years, 6 months ago

    I didn't do it yesterday but I made a fairly short one in Java. Obviously it could be a little shorter if you really wanted.

    public static void main (String[] args) {
            for (int i = 1; i < 101; i++) {
                System.out.println("problem" + (i%5==0?"of":"") + (i%25==0?"the":"") + 
                        (i%100==0?"day":""));
            }
        }
    

    reply permalink

  • bumbleguppy - 10 years, 6 months ago

    javascript. Didn't submit a solution yesterday, but this one logs in at ~144 characters.

    I would rather have each iteration do a console,log, but my substring length computation went all wonky every time I tried to do it there. so I resorted to a primitive string-builder. bleh.

    function o(){for(var i=1,s='';i<101;i++){s+='problem of the day'.substr(0,(7+(!!(i%5)?0:3)+(!!(i%25)?0:4)+(!!(i%100)?0:4)))+'\n'}console.log(s)}
    

    reply permalink

Content curated by @MaxBurstein