Print all Sundays in 2017

27

4

Print the dates of all the Sundays in 2017 in the following format : dd.mm.yyyy.
Expected Output:

01.01.2017
08.01.2017
15.01.2017
22.01.2017
29.01.2017
05.02.2017
12.02.2017
19.02.2017
26.02.2017
05.03.2017
12.03.2017
19.03.2017
26.03.2017
02.04.2017
09.04.2017
16.04.2017
23.04.2017
30.04.2017
07.05.2017
14.05.2017
21.05.2017
28.05.2017
04.06.2017
11.06.2017
18.06.2017
25.06.2017
02.07.2017
09.07.2017
16.07.2017
23.07.2017
30.07.2017
06.08.2017
13.08.2017
20.08.2017
27.08.2017
03.09.2017
10.09.2017
17.09.2017
24.09.2017
01.10.2017
08.10.2017
15.10.2017
22.10.2017
29.10.2017
05.11.2017
12.11.2017
19.11.2017
26.11.2017
03.12.2017
10.12.2017
17.12.2017
24.12.2017
31.12.2017

ShinMigami13

Posted 2017-04-13T03:10:55.697

Reputation: 449

1

Possible dupe of Plan your Sundays? This one is a specific year though.

– xnor – 2017-04-13T03:19:47.157

1

I checked out Plan your Sundays before posting, but it asks to print the Sundays in a given month. @xnor

– ShinMigami13 – 2017-04-13T03:21:27.280

1Any particular reason for that specific output format? You could open in up a bit. – Rɪᴋᴇʀ – 2017-04-13T03:22:20.657

I'm newbie here, please help me add that @Riker – ShinMigami13 – 2017-04-13T03:22:36.167

@xnor was it a ninja edit? I don't see it in the rev history. And Patrick commented, is this some magic I don't know about? – Rɪᴋᴇʀ – 2017-04-13T03:22:46.797

4I actually like this as an exact-text kolmogorov challenge. Getting the date formatting right has some interesting optimizations. – xnor – 2017-04-13T03:23:07.027

@Riker There is a 5-minute grace period, so the edit could have ninja'd there, but then how does the top comment contain the [tag:code-golf] tag? Since comments override the grace period, it seems strange... unless there was a [tag:code-golf] tag before the comment, which seems strange again because OP's reply says "Added tags[...]". There might have been some 11 around, since mods can delete revisions, but then that's only used when there's an absolute emergency. Can't find an explanation, and the first revision does indeed have a [tag:code-golf] tag. Something's gone crazy... – Erik the Outgolfer – 2017-04-13T08:19:03.767

5Anyways, I think the close votes should be retracted. – Erik the Outgolfer – 2017-04-13T08:28:10.110

Is a trailing newline accepted? – IQuick 143 – 2018-05-12T06:11:57.637

Answers

16

Python 2, 81 bytes

x=0
exec"print'%05.2f.2017'%(x%30.99+1.01);x+=7+'0009ANW'.count(chr(x/7+40));"*53

Try it online!

No date libraries, computes the dates directly. The main trick is to treat the dd.mm as a decimal value. For example, 16.04.2017 (April 16) corresponds to the number 16.04. The number is printed formatted as xx.xx with .2017 appended.

The day and month are computed arithmetically. Each week adds 7 days done as x+=7. Taking x modulo 30.99 handles rollover by subtracting 30.99 whenever the day number gets too big. This combines -31 to reset the days with +0.01 to increment the month.

The rollover assumes each month has 31 days. Months with fewer days are adjusted for by nudging x upwards on certain week numbers with +[8,8,8,17,25,38,47].count(x/7). These list is of the week numbers ending these short months, with 8 tripled because February is 3 days short of 31.

This list could is compressed into a string by taking ASCII values plus 40. The shift of +40 could be avoided by using unprintable chars, and could be accessed shorter as a bytes object in Python 3.

xnor

Posted 2017-04-13T03:10:55.697

Reputation: 115 687

What a cool answer! '888z!}+'.count(chr(x%146)) saves one byte. – Lynn – 2018-05-11T07:51:51.607

10

PHP, 48 bytes

while($t<53)echo gmdate("d.m.2017
",605e3*$t++);

PHP, 46 bytes (for non-negative UTC offsets)

while($t<53)echo date("d.m.2017
",605e3*$t++);

user63956

Posted 2017-04-13T03:10:55.697

Reputation: 1 571

1Shouldn´t that be gmdate for timezone safety? It fails on onlinephpfunctions.com. Great work in all other aspects! – Titus – 2017-04-14T17:42:48.210

9

Python 2, 90 79 bytes

-5 bytes with the help of xnor (avoid counting the weeks themselves)
-1 byte thanks to xnor (add back in e for 605000 as 605e3)

from time import*
i=0
exec"print strftime('%d.%m.2017',gmtime(i));i+=605e3;"*53

Try it online!

0 seconds since epoch is 00:00:00 on the 1st of January 1970, which, like 2017 was not a leap year. 605000 seconds is 1 week, 3 minutes, 20 seconds. Adding 52 of these "weeks" does not take us beyond midnight.

Jonathan Allan

Posted 2017-04-13T03:10:55.697

Reputation: 67 804

Here's a shorter way to generate the arithmetic progression.

– xnor – 2017-04-13T05:37:02.930

@xnor Thanks, I was working on the same kind of thing and was trying to go lower, but 81 seems to much to go for with the library approach. – Jonathan Allan – 2017-04-13T06:00:00.907

@xnor ...or not. – Jonathan Allan – 2017-04-13T06:21:59.480

1Nice! The number can be 605e3. I have some ideas though :) – xnor – 2017-04-13T06:23:30.800

7

Bash + coreutils, 44 bytes

seq -f@%f 0 605e3 32e6|date -uf- +%d.%m.2017

may save 2 bytes -u if GMT is assumed

  • Thanks Digital Trauma point out -f paramter for date which saves 10 bytes;
  • And use 2017 in format string saves more bytes which idea is from the answer given by user63956

  • @0 is 1970-1-1
  • 605000 is one week (604800) plus 200 sec
    • 200 sec. should just work since there are only 52 weeks in a year
  • @32000000 is just a little more than a year

tsh

Posted 2017-04-13T03:10:55.697

Reputation: 13 072

seq -f@%1.f 14833e5 605e3 1515e6|date -uf- +%d.%m.%Y saves you 10 bytes. You should probably claim this as Bash + coreutils, though. – Digital Trauma – 2017-04-13T06:10:02.453

7

PowerShell, 51 47

0..52|%{date((date 2017-1-1)+7.*$_)-u %d.%m.%Y}

Fairly straightforward. 2017-01-01 is a Sunday, so is every following seven days. We can save two bytes if we only need the script to be working in my lifetime:

0..52|%{date((date 17-1-1)+7.*$_)-u %d.%m.%Y}

Joey

Posted 2017-04-13T03:10:55.697

Reputation: 12 260

1

You can save a few bytes if you, instead of a string, add a double representing number of days, i.e. (date 2017-1-1)+7.*$_ . See this answer

– Danko Durbić – 2017-04-13T14:00:59.603

@DankoDurbić: Oh, wow. I only knew of adding int for ticks and strings for days so far. Nice to know. – Joey – 2017-04-13T18:18:57.457

5

Excel VBA 106 91 79 bytes

Sub p()
For i = #1/1/2017# To #12/31/2017#
If Weekday(i) = 1 Then MsgBox i
Next
End Sub

saved 15 bytes thanks to @Radhato

Assuming 1/1/2017 is Sunday it will save 12 more bytes.

Sub p()
For i = #1/1/2017# To #12/31/2017#
MsgBox i
i = i + 6
Next
End Sub

Thanks @Toothbrush 66 bytes

Sub p:For i=#1/1/2017# To #12/31/2017#:MsgBox i:i=i+6:Next:End Sub

Edit: (Sub and End Sub is not necessary) 52 bytes

For i=#1/1/2017# To #12/31/2017#:MsgBox i:i=i+6:Next

Stupid_Intern

Posted 2017-04-13T03:10:55.697

Reputation: 373

Can be improved by chanching For i = 42736 To 43100 to For i = #1/1/2017# To #12/31/2017# and then removing Format(...) replacing with just i – Radhato – 2017-04-13T06:43:51.767

@Radhato but wouldn't that increase byte size? – Stupid_Intern – 2017-04-13T06:44:37.347

I think it reduces it to 96.. at least thats what I counted lol – Radhato – 2017-04-13T06:48:04.583

Yes it did. Thanks – Stupid_Intern – 2017-04-13T06:48:38.040

Using MsgBox (as you did) reduces it further to 91, if I didnt count wrong. And should be valid, since the OP just stated the output should contain every sunday.. not on how it is supposed to show up (i.e. MsgBox / Debug.Print) – Radhato – 2017-04-13T06:51:48.837

I know VB.NET will allow you to remove some spaces, I don't know if Excel VBA is as lenient. If so, you should be able to remove spaces around the =, to shave about 4 more bytes. – Brian J – 2017-04-13T18:01:04.323

@BrianJ Nope the VBA Editor inserts the space back if you remove it – Stupid_Intern – 2017-04-13T18:41:07.677

1@newguy Sub p:For i=#1/1/2017# To #12/31/2017#:MsgBox i:i=i+6:Next:End Sub is perfectly valid VBA code and is only 66 bytes. The fact that the VBA Editor adds in extra spaces is irrelevant. – Toothbrush – 2017-04-13T20:39:13.230

4

PHP, 67 bytes

Using the fact the PHP automatically assign value 1 to undeclared loop variables, and using Linux epoch times,

<?php for(;54>$t+=1;)echo date("d.m.Y\n",604800*($t)+1482624000);?>

ShinMigami13

Posted 2017-04-13T03:10:55.697

Reputation: 449

Welcome to PPCG! I believe this can be counted as 59 bytes (although I don't golf in PHP myself).

– Jonathan Allan – 2017-04-13T05:04:48.273

4<?for(;54>++$t;)echo date("d.m.Y\n",605e3*$t+148263e4); should just be ok – tsh – 2017-04-13T06:03:59.457

2Always nice to see some new PHP golfers ! You're allowed to use php -r so you don't need <?php and ?> and therefore can count this as 59 bytes like @JonathanAllan correctly said. You don't need the brackets around $t. A few other golfs and you end up with for(;++$t<54;)echo date("d.m.Y\n",605e3*$t+14827e5); for 51 bytes (in my time zone). You can replace "\n" with a real line break which is only 1 byte therefore it's 51 byte. – Christoph – 2017-04-13T12:05:24.787

1Thanks @Christoph I'm trying out another approach, will update soon – ShinMigami13 – 2017-04-13T15:55:24.140

Apart from all the other hints, you might want to use gmdate instead of date for timezone safety. – Titus – 2017-04-14T17:47:32.540

Is it possible to do 54>$t++ ? – sergiol – 2018-05-11T16:12:32.753

4

k6, 32 bytes

`0:("."/|"."\)'$2017.01.01+7*!53

Brief explanation:

                2017.01.01+7*!53 /add 0, 7, 14, ..., 364 to January 1st
   ("."/|"."\)'$                 /convert to string, turn Y.m.d into d.m.Y
                                 /   split by ".", reverse, join by "."
`0:                              /output to stdout (or stderr), line by line

Alas, this seems to only work in the closed-source, on-request-only interpreter.

Running the command in the closed-source interpreter.

zgrep

Posted 2017-04-13T03:10:55.697

Reputation: 1 291

4

Pyke, 26 24 bytes

53 Fy17y"RVs6)c"%d.%m.%Y

Try it online!

53 F                     - for i in range(53):, printing a newline between each
    y17y"                -  Create a time object with the year 2017. (Month and days are initialised to 1.)
         RV  )           -  Repeat i times:
           s6            -   Add 1 week
              c"%d.%m.%Y -  Format in "dd.mm.yyyy" time

Or 11 bytes

If allowed to ignore output format

y17y"52VDs6

Try it online!

y17y"       - Create a time object with the year 2017. (Month and days are initialised to 1.)
     52V    - Repeat 52 times:
        D   -  Duplicate the old time
         s6 -  Add 1 week

Blue

Posted 2017-04-13T03:10:55.697

Reputation: 26 661

3

JavaScript, 111 106 bytes

for(i=14833e8;i<1515e9;i+=605e6)console.log(new Date(i).toJSON().replace(/(....).(..).(..).*/,'$3.$2.$1'))

Note: Stack Exchange's console isn't long enough to display the entire list, so here's the first half as a separate snippet:

for(i=14833e8;i<15e11;i+=605e6)console.log(new Date(i).toJSON().replace(/(....).(..).(..).*/,'$3.$2.$1'))

The custom format costs me 40 bytes...

Neil

Posted 2017-04-13T03:10:55.697

Reputation: 95 035

3

R, 79 67 58 bytes

cat(format(seq(as.Date("2017/01/01"),,7,53),"\n%d.%m.%Y"))

First of January being a sunday, this snippet creates a sequence of days, every 7 days starting from the 01-01-2017 to the 31-12-2017, format them to the desired format and print them.

plannapus

Posted 2017-04-13T03:10:55.697

Reputation: 8 610

This should bring it down to 41 bytes print(as.Date("2017-01-01")+seq(7,365,7)) – count – 2017-04-22T22:17:54.323

@count Thanks but it wouldn't print the required output (i. e. "2017.01.01" instead of "2017/01/01") – plannapus – 2017-04-23T05:43:35.770

3

Befunge-98 (PyFunge), 99 95 93 85 bytes, Leaves trailing newline

All the optimizations were made by @JoKing many thanks to them

s :1g2/10g\%:d1p10g\`+:b`#@_:1\0d1g#;1+:a/'0+,a%'0+,'.,j;a"7102"4k,d1g7+
>8><><>><><>

Try it online!

I felt like we were missing out on some esostericity here so I made a solution in my favourite Esosteric language.

Explanation:
>8><><>><><> Encodes the length of the 12 months
s Store the old day in the blank space
:1g2/ Get an ASCII value from the bottom row and divide it by two this gives us the length of a given month Ex: 8 = 56 in ASCII => 56/2 = 28 => The month (February) has 28 days
10g\% Get the previously saved day and modulo it by the length of the month which allows us to transition the date into the next month
:d1p Save a copy of the new updated day
10g\`+ Test if old date > new date => we transitioned into the next month => add 1 to the month counter
:b` Test if month counter > 11 that means we reached the end of the year (using 0 indexing)
#@_ Based on the previous if terminate the program
:1\0d1g Reorder the stack so it looks like this: Month, 1, Month, 0, Day
# skip the next insctruction (duh)
1+:a/'0+,a%'0+,'., Convert the number to 1 indexing, print, add a . at the end
j; Use the 0 from the stack to not jump and use the ; to go to to the print schedule again then use the 1 to jump over the ; next time
a"7102"4k, Print 2017\n
d1g Get the day value again 7+ Add a week before repeating

IQuick 143

Posted 2017-04-13T03:10:55.697

Reputation: 1 229

@JoKing Omc such an obvious optimization! How could've I missed that one? Thank you. – IQuick 143 – 2018-05-12T11:51:41.820

1

A few more bytes off. Try it online! One from changing the -17 jump to a comment instead, one from using 0 based indexing for the month counter and one from changing it to a one-liner

– Jo King – 2018-05-12T12:54:38.433

@JoKing Wow that's a lot of golfing you did there. Lemme add it to the answer. – IQuick 143 – 2018-05-12T12:58:46.477

1

Hell, why not make the days 0 indexed as well, and save having to do any of the initialisation at all! 85 bytes

– Jo King – 2018-05-12T13:38:21.143

2

Perl 5, 64 bytes

use POSIX;print strftime"%d.%m.%Y\n",0,0,0,7*$_+1,0,117for 0..52

Try it online!

The task given was 2017, not any year, so I hardcoded in:

  • 117 (which is perlish for year 2017, 1900+117)
  • +1 because 1st of January is a sunday in 2017
  • 0..52 because 2017 have 53 sundays

POSIX is a core module and is always installed with Perl5. Doing the same without using modules in 101 bytes, removing whitespace:

$$_[5]==117&&printf"%02d.%02d.%d\n",$$_[3],$$_[4]+1,$$_[5]+1900
  for map[gmtime(($_*7+3)*86400)],0..1e4

Kjetil S.

Posted 2017-04-13T03:10:55.697

Reputation: 1 049

2

Mathematica 90 84 bytes

Fairly wordy. numbermaniac and Scott Milner saved 5 and 1 bytes, respectively.

Column[#~DateString~{"Day",".","Month",".","Year"}&/@DayRange["2017","2018",Sunday]]

DavidC

Posted 2017-04-13T03:10:55.697

Reputation: 24 524

Do you need the Most@? The output seems to be identical without it. – numbermaniac – 2017-04-22T11:51:19.520

1@numbermaniac, Thanks. Most was in there to avoid the first Sunday in 2018. I had originally tested the code, without Most, for years, 2011, 2012, in which case the first Sunday in 2012 is included in the output. (That's why I included it into the code.) Strangely, Most is not needed for 2017-18. Nor does Most have any apparent effect on the result. Mysterious! – DavidC – 2017-04-22T15:18:44.143

2

Ruby, 75 bytes

Straightforward solution to figure out the dates with Time.

t=Time.new 2017
365.times{puts t.strftime("%d.%m.%Y")if t.sunday?
t+=86400}

snail_

Posted 2017-04-13T03:10:55.697

Reputation: 1 982

1If you add a whole week(604800 seconds), then you don't need to check for a sunday, just repeat 53 times. – G B – 2017-04-13T13:38:05.937

1If you do the trick suggested by @GB and no longer check for Sunday, you can also initialize with t=Time.new 1 and then do t.strftime"%d.%m.2017" for -1 byte. – Value Ink – 2017-04-13T22:01:32.297

2

SAS, 52 50 bytes

Saved 2 bytes thanks to @user3490.

data;do i=20820to 21184 by 7;put i ddmmyyp10.;end;

J_Lard

Posted 2017-04-13T03:10:55.697

Reputation: 351

You don't need to specify a dataset - just use data; instead of data c; and that saves 2 bytes. I think you do need a run; though. – user3490 – 2017-04-13T15:31:54.877

@user3490 Thanks, I wasn't aware of that. I guess that's the equivalent of data _null_? Also, the run statement is implied if it's missing. – J_Lard – 2017-04-13T16:33:06.437

Not quite equivalent - you end up with an output dataset following the datan naming convention. – user3490 – 2017-04-18T22:17:25.577

1

C#, 138 111 102 bytes

Saved 9 more bytes thanks to Johan du Toit!

Saved 27 bytes thanks to Kevin Cruijssen's suggestions!

()=>{for(int i=0;i<53;)Console.Write(new DateTime(2017,1,1).AddDays(7*i++).ToString("dd.MM.yyyy\n"));}

Anonymous function which prints all Sundays in 2017.

Full program with ungolfed method:

using System;

class P
{
    static void Main()
    {
        Action f =
        ()=>
        {
            for (int i = 0; i < 53; )
                Console.Write(new DateTime(2017, 1, 1).AddDays(7 * i++).ToString("dd.MM.yyyy\n"));
        };



        f();
    }
}

adrianmp

Posted 2017-04-13T03:10:55.697

Reputation: 1 592

1Isn't it easier to just use .AddDays(7*i++)? Then there is no need for the .DayOfWeek<1 check. We know 01-01-2017 is a Sunday, and from there we can just keep adding 7 days. – Kevin Cruijssen – 2017-04-13T13:04:05.163

2Not sure about this -- in all code golfs I partake, I always used the complete namespace -- but aren't you missing some Systems in there -- System.DateTime and System.Console.Write? – auhmaan – 2017-04-13T13:32:00.580

Cool but you can save a couple of bytes: ()=>{for(int i=0;i<53;)Console.Write(new DateTime(2017,1,1).AddDays(7*i++).ToString("dd.MM.yyyy\n"));}; – Johan du Toit – 2017-04-13T20:39:12.457

@auhmaan: Yes, either full namespaces should be used, or the using statements should be included in the byte count. – raznagul – 2017-04-14T08:14:55.777

@adrianmp: You can save some bytes by eliminating i. (for(var d=new DateTime(2017,1,1);d.Year<2018;d=d.AddDays(7))Console.Write(d.ToString("dd.MM.yyyy\n"))). Also your current answer is 112 bytes not 111. – raznagul – 2017-04-14T08:18:05.163

@auhmaan: I've seen both forms. I consider it ok if it's a function and the standard System namespace was the only one used. – adrianmp – 2017-04-14T08:51:52.020

3

@adrianmp: Necessary using statements to run the code must be counted. See this Meta question: Do I need to use imports or can I call a class explicity?

– raznagul – 2017-04-14T10:12:49.853

1

VBA, 81 bytes (maybe 64)

Sub p()
For i = 0 To 52
MsgBox format(42736 + i * 7, "dd.mm.yyyy")
Next i
End Sub

My first post. Building on newguy's solution by removing the check for weekdays and just specifying every 7th day. Removing the dates saves 12 bytes a piece. 42736 is 1/1/2017. Output date format depends on system setting. Is that allowed? If so, it's 64 bytes because you don't need the format method.

MsgBox #1/1/2017# + i * 7

Broke Daddy

Posted 2017-04-13T03:10:55.697

Reputation: 11

You can also remove a lot of the white space that is autoformatted. For instance, and For i=0To 52 and Format(42736+i*7,"dd.mm.yyyy"). Also, you can just use Next instead of Next i.

– Engineer Toast – 2017-04-13T12:33:46.277

1

AHK, 67 bytes

d=20170101
Loop,52{
FormatTime,p,%d%,dd.MM.yyyy
Send,%p%`n
d+=7,d
}

Nothing magical happens here. I tried to find a shorter means than FormatTime but I failed.

Engineer Toast

Posted 2017-04-13T03:10:55.697

Reputation: 5 769

1

Java 8+, 104 100 99 bytes

()->{for(int t=0;t<53;)System.out.printf("%1$td.%1$tm.2017%n",new java.util.Date(t++*604800000L));}

Java 5+, 109 105 104 bytes

void f(){for(int t=0;t<53;)System.out.printf("%1$td.%1$tm.2017%n",new java.util.Date(t++*604800000L));}

Uses the date-capabilities of the printf format.

Test it yourself!

Savings

  1. 104 -> 100: changed the loop values and the multiplicand.
  2. 100 -> 99: golfed the loop

Olivier Grégoire

Posted 2017-04-13T03:10:55.697

Reputation: 10 647

1

T-SQL, 94 Bytes

DECLARE @ INT=0,@_ DATETIME='2017'W:SET @+=1SET @_+=7PRINT FORMAT(@_,'dd.MM.yyy')IF @<52GOTO W

if you don't like SQL GOTO or WHILE, here is a 122 bytes CTE solution

WITH C AS(SELECT CAST('2017'AS DATETIME)x UNION ALL SELECT x+7FROM C WHERE X<'12-31-17')SELECT FORMAT(x,'dd.MM.yyy')FROM C

WORNG ALL

Posted 2017-04-13T03:10:55.697

Reputation: 61

your first solution starts at 08.01.2017 not 01.01.2017 – grabthefish – 2017-04-14T09:10:40.650

1Very good tricks in your solution. Good job. I couldn't resist to borrow them. ;) – AXMIM – 2017-04-14T16:11:04.820

1

Ruby, 60+7 = 67 bytes

Uses the -rdate flag.

(d=Date.new 1).step(d+365,7){|d|puts d.strftime"%d.%m.2017"}

Value Ink

Posted 2017-04-13T03:10:55.697

Reputation: 10 608

1

Groovy, 81 77 63 60 56 bytes

d=new Date(0);53.times{printf('%td.%<tm.2017%n',d);d+=7}

The above can be run as groovy script.

My first code golf entry. Fortunately, the year 1970 was not a leap year, thus can use it as a base.

Thanks to Dennis, here's a: Try it online!

Krystian

Posted 2017-04-13T03:10:55.697

Reputation: 111

Welcome to Programming Puzzles & Code Golf! In case you're interested, here's a permalink: Try it online!

– Dennis – 2017-04-14T05:35:57.473

Thank you @Dennis I didn't know this existed :) – Krystian – 2017-04-14T06:05:31.947

You can save four bytes by moving the date inside the times block, 53.times{printf('%td.%<tm.2017%n',new Date(0)+it*7)}, 52 bytes. Defending groovy's honor here... – Matias Bjarland – 2018-05-12T10:36:26.240

1

C#, 110 109 bytes

using System;()=>{for(int i=42729;i<43100;Console.Write(DateTime.FromOADate(i+=7).ToString("dd.MM.yyy\n")));}

You can enjoy this program online here

In this soluion we :

  • Use OLE Automation Date (OADate) to avoid "AddDay()" from datetime.
    FromOADate() seem big but it's equal to new DateTime(2017,1,1)

  • Start the loop on the last sunday of 2016. to allow us to increment with operator += only. This operator return the value after the increment is done.

  • Increment by 7 days to jump from sunday to sunday before printing the date.

  • We stop once the last sunday of 2017 has been hit.

  • Use Debug instead of Console to save two characters

  • Avoid having explicit variable declaration and assignment

AXMIM

Posted 2017-04-13T03:10:55.697

Reputation: 209

Unless otherwise specified, our defaults say you should provide a function or program (i.e. not a snippet), and you need to qualify Debug and DateTime: I'd recommend adding using System; and switching to Console from Debug (which is a tad dodgy itself, but I can't find any commentary on meta regarding it).

– VisualMelon – 2017-04-14T08:08:19.717

1@VisualMelon I've complied with "provide a function" and I have also replace Debug for Console since Debug required a specific include. However, I didn't comply with the 'use system' because my competitor in this language doesn't do it. Also, you can't code outside a class which itself required to be defined within a namespace. I'm pretty sure most c# answer on this site doesn't include that. So what now, do we throw all these answers to the garbage? Do we downvote them all to force them to comply? If so, then the community might as well ban c# from codegolf altogether. – AXMIM – 2017-04-14T14:20:19.443

These 'rules' are just what the community has over time settled on (and documented on meta). We don't downvote answers, we comment and don't upvote them either. When they fix them, then we are free to upvote. Both other C# answers have comments suggesting they should add the using directive or fully qualify the methods and types, please don't take any of this personally. I'm a long time C# golfer, and I appreciate how arbitrary the rules seem, so I like to nudge people in the right direction when I can. I specifically 'target' C# answers because I'm relatively well informed on the matter. – VisualMelon – 2017-04-14T15:26:45.210

Just regarding the bit about code being required to be defined within a class (classes, by the way, do not need to be declared within a namespace), the idea of the rules isn't that it should compile as is, but that it should (ideally) be unambiguous, not too convoluted, and consistent (fair). Do please join the discussion on meta if you disagree! – VisualMelon – 2017-04-14T15:28:31.780

1@VisualMelon Fair enough, I'm just a passerby here anyway. So I shall accept your rules while I'm here. Therefore, I've attempted to make my answer comply this time. – AXMIM – 2017-04-14T17:13:54.397

1Looks good to me! +1 for the original approach. And you don't need the space after using System; (I assume that wasn't intentional) so that's 109 bytes. – VisualMelon – 2017-04-14T18:59:53.983

1

TSQL, 112 105 bytes

SELECT CONVERT(VARCHAR,DATEADD(d,number*7,42734),104)FROM master..spt_values WHERE type='p' AND number<53

Demo

T-SQL Convert Syntax

Salman A

Posted 2017-04-13T03:10:55.697

Reputation: 151

You can save 2 bytes by replacing DAY by d. It does the same. – AXMIM – 2017-04-14T14:53:19.230

+1 You can save another 3 bytes by replacing '20170101' with 42734. Dates are number. Time is the decimals part of the number. – AXMIM – 2017-04-14T15:08:29.017

1

T-SQL, 79 77 Bytes

After helping Salman A improve his answer. I decided to write my own using a loop and PRINT.

I ended with this 90 bytes solution.

DECLARE @d DATETIME=42734 WHILE @d<43100BEGIN PRINT CONVERT(VARCHAR,@d,104)SET @d=@d+7 END

Then I looked at the current leader in T-SQL which was 94 bytes from WORNG ALL with this answer. This guy had found very good tricks.

  1. Name the variable only @
  2. Loop with GOTO instead of actual LOOP
  3. Save one character using FORMAT instead of CONVERT. (SSMS2012+ only)

Using these tricks, this solution was trimmed down to the solution below which is 79 bytes.

DECLARE @ DATETIME=42734G:PRINT FORMAT(@,'dd.MM.yyy')SET @+=7IF @<43100GOTO G

AXMIM

Posted 2017-04-13T03:10:55.697

Reputation: 209

You can save 2 bytes by changing @=@+7 to @+=7 and by removing the space between the 7 and the IF. – WORNG ALL – 2017-05-09T20:42:32.627

In this post is where I got all the tricks, may help you too. – WORNG ALL – 2017-05-09T20:43:36.980

1@WORNGALL wonderfull, I was unaware we could do that. Thanks a lot. – AXMIM – 2017-05-10T14:42:44.517

1

JavaScript (ES6), 123 bytes

It's my first post here, hello!

a=x=>`0${x}.`.slice(-3);[].map.call('155274263153',(x,i)=>{for(j=0;j<4+(2633>>i&1);j++)console.log(a(+x+j*7)+a(i+1)+2017)})

This solution uses hardcoded data and is designed to work specifically for the year 2017. It relies on no date/time APIs.

As for the digits in the string 155274263153, each digit is a number of its own and denotes the first Sunday of each consecutive month. Output for the entire year can be generated by successively adding 7 to those.

What about the magic number, 2633, used in the loop?
Well... 2633 (decimal) is 101001001001 in binary. Now what could those 1s mean? Starting from the right, the 1st, 4th, 7th, 10th and 12th bit are set. This corresponds to months which happen to have five Sundays, as opposed to those that have only four. Golfed down to this neat expression, it initially looked like this: for(j=0;j<4+ +[0,3,6,9,11].includes(i);j++).

I guess the remaining parts are fairly self-explanatory.

rhino

Posted 2017-04-13T03:10:55.697

Reputation: 111

@SIGSEGV: I don't mind changing ECMAScript 2015 to Javascript (ES6), but... you broke my code and I had to revert it. – rhino – 2017-04-15T04:41:04.037

Oh, that's the community's consensus, having only the lambda part is allowed. – Matthew Roh – 2017-04-15T04:45:35.923

@SIGSEGV This is not the case here. This lambda contains only a small portion of the code, and I need that identifier to be able to use it elsewhere. Without the a= the code is actually broken. – rhino – 2017-04-15T04:51:43.527

1

Octave, 37 bytes

A lot shorter than all other non-golfing languages, and it's even tied with Jelly! Way to go Octave! :)

disp(datestr(367:7:737,'DD.mm.2017'))

Try it online!

Luckily, year 2 AD looks exactly the same as year 2017 AD. Both starts and ends at a Sunday, and neither is a leap year. This saves a lot of bytes, since 367:7:737 is quite a bit shorter than 736696:7:737060.

This converts the number of days since 01.01.0001, to a string on the format DD.mm, with a trailing .2017.

Stewie Griffin

Posted 2017-04-13T03:10:55.697

Reputation: 43 471

1

Haskell, 133 130 bytes

import Data.Time.Calendar
((\[f,g,h,i,j]->i:j:'.':f:g:".2017\n").drop 5.show)=<<take 53(iterate(addDays 7)$fromGregorian 2017 1 1)

Try it online!

Without a calendar library, 148 144 140 bytes

(\l->last l!l++length l!l++"2017\n").fst.span(>0).(<$>scanl((+).(+28))0[3,0,3,2,3,2,3,3,2,3,2]).(-)=<<[1,8..365]
a!_=['0'|a<=9]++show a++"."

This is funny since using an operator for the padding function saves two bytes even though the second argument is unused, because less parentheses are needed – p(last l) is longer than last l!l. Works by calculating day/month pairs by subtracting the cumulative month start dates from the day of the year. The month start dates are compressed as (scanl((+).(+28))0[3,0,3,2,3,2,3,3,2,3,2]). Month number is the number of positive elements and day number is the last positive element.

Try it online!

Angs

Posted 2017-04-13T03:10:55.697

Reputation: 4 825

0

C#, 116 114 113 bytes

for(long i=(long)636188256e9;i<636502857e9;i+=(long)605e10)Out.Write(‌​new DateTime(i).ToString("dd.MM.yyyy\n"));

Can be run in the interactive windows of Visual Studio (or any other C# REPL based on Roslyn)

Down to 113 bytes: thanks to Kevin Cruijssen.

rmrm

Posted 2017-04-13T03:10:55.697

Reputation: 9

1

Could you add a TryItNow link? Also, you can golf it a bit by using a for-loop instead of a while-loop: for(long i=(long)636188256e9;i<636502857e9;i+=(long)605e10)Out.Write(new DateTime(i).ToString("dd.MM.yyyy\n"));

– Kevin Cruijssen – 2017-04-13T11:57:01.903

@KevinCruijssen Unfortunaly I am not able to find an applicable compiler on the given page. Here is a link to the used technology if you want to get in touch with it: link. Anyway thanks for the new loop. :)

– rmrm – 2017-04-13T12:33:37.880

1

Unless otherwise specified, our defaults say you should provide a function or program (i.e. not a snippet), and you need to qualify Debug and DateTime: I'd recommend adding using System; and using Console.WriteLine(string)

– VisualMelon – 2017-04-14T08:11:58.860

0

Java 7, 145 144 142 bytes

void c(){for(long x=604800000,i=-x;i<52*x;)System.out.println(new java.text.SimpleDateFormat("dd.MM.2017").format(new java.util.Date(i+=x)));}

-2 bytes thanks to Cliffroot due to a stupid mistake of me..

Try it here.

Explanation:

void c(){                                  // Method
  for(long x=604800000,                    //  Initialize `x` as 604,800,000
           i=-x;                           //  Initialize `i` as `-x` / -604,800,000 as starting number
      i<52*x;)                             //  Loop over all 52 weeks
    System.out.println(new java.text.SimpleDateFormat("dd.MM.2017")
      .format(new java.util.Date(i+=x)));  //   Raise `i` by `x` and then print it in the format `dd.MM.2017`
                                           //  End of loop (implicit / single-line body)
}                                          // End of method

Kevin Cruijssen

Posted 2017-04-13T03:10:55.697

Reputation: 67 575

1long x=605000000 is shorter – cliffroot – 2017-04-13T13:30:30.763

@cliffroot Thanks. I really should just use the entire long from now on, and in case it can be shortened change it to (long)NeM.. I think this is already the second time you've corrected me on this.. – Kevin Cruijssen – 2017-04-13T13:45:24.140

0

SpecBAS - 61 bytes

1 FOR i=42736 TO 43100 STEP 7: ?DATE$(i,"dd.mm.yyyy"): NEXT i

Dates are a decimal number starting at 30-Dec-1899, so had to work out what 1 Jan 2017 and 31 Dec 2017 were, then just step through those values adding 7 days each time.

Brian

Posted 2017-04-13T03:10:55.697

Reputation: 1 209

0

Java 7, 126 bytes

void e(){for(int i=0,j=1,k;i<12;j%=k)for(k="(%('('(('('(".charAt(i++)-9;j<k+1;j+=7)System.out.format("%02d.%02d.2017\n",j,i);}

Computes everything manually. The string "(%('('(('('(" encodes number of days in month. Outer loop goes from 0 to 11 (number of months), inner loops goes until the number representing day is greater than number of days in this month.

See it online

cliffroot

Posted 2017-04-13T03:10:55.697

Reputation: 1 080

0

SQL (PostgreSQL), 74 Bytes

SELECT to_char(generate_series('170101'::date,'171231','7d'),'DD.MM.YYYY')

If output must be in a single string rather than individual records then the query can be run from psql with the -tA options, making it 76 bytes.

Richard

Posted 2017-04-13T03:10:55.697

Reputation: 331

0

REXX, 91 bytes

do n=1 to 365
  if date(w,n,d)='Sunday' then say left(translate(date(e,n,d),.,'/'),6)2017
  end

idrougge

Posted 2017-04-13T03:10:55.697

Reputation: 641

0

c, 119 116 114 bytes

y=2017,m=1,d=1,i=53,v;main(){for(;i--;)printf("%02d.%02d.%d\n",d,m,y),v=m^2?m%2^m<8?30:31:28,(d+=7)>v?++m,d-=v:0;}

Try it online

Johan du Toit

Posted 2017-04-13T03:10:55.697

Reputation: 1 524

103 bytes - d=1,i=53,v;main(m){for(;i--;(d+=7)>v?++m,d-=v:0)printf("%02d.%02d.2017\n",d,m),v=m^2?m%2^m<8?30:31:28;} – gastropner – 2017-11-23T13:04:35.620

0

SQL (Oracle), 137 bytes

select substr(d,1,10)
from (select to_char(sysdate-1e4+rownum,'DD.MM.YYYYdy') d from dual connect by rownum<=2e4)
where d like '%2017s%';

Kjetil S.

Posted 2017-04-13T03:10:55.697

Reputation: 1 049

0

Jelly,  38  37 bytes

-1 thanks to user202729 (use the quick I implemented about a month after this answer.)

Ḋ€;⁽¥Ñj”.
“£hṅ’ṃ“þœ÷‘R,€"J$;/m7+³DÇ€Y

Jelly currently has no date type or way of representing a date natively, so a purely numeric approach is required.

Try it online!

How?

Ḋ€;⁽¥Ñj”. - Link 1, format helper: list of lists   e.g. [[x,0,2],[x,0,7]] (for 2nd July)
Ḋ€        - dequeue €ach                                [[0,2],[0,7]]
   ⁽¥Ñ    - literal 2017                                2017
  ;       - concatenate                                 [[0,2],[0,7],2017]
       ”. - character '.'
      j   - join                                        [0,2,'.',0,7,'.',2017]
              which has the representation:             "02.07.2017"

“£hṅ’ṃ“þœ÷‘R,€"J$;/m7+³DÇ€Y - Main link: no arguments
“£hṅ’                       - base 250 compressed number 213991
      “þœ÷‘                 - code-page indexes [31,30,28]
     ṃ                      - base decompression: 213991 base length([31,30,28])
                                = [1,0,1,2,1,2,1,1,2,1,2,1]; indexed into [31,30,28]
                                = [31,28,31,30,31,30,31,31,30,31,30,31]
           R                - range (vectorises): [[1,2,...,31],[1,2,...,28],...]
                $           - last two links as a monad:
               J            -     range(length): [1,2,3,4,5,6,7,8,9,10,11,12]
              "             -     zip with:
            ,€              -         pair for €ach: [[[1,1],[2,1],...,[31,1]],[[1,2],[2,2],...,[28,2]],...]
                 ;/         - reduce with concatenation: [[1,1],[2,1],...,[31,1],[1,2],[2,2],...,[28,2],...]
                   m7       - every 7th item: [[1,1],[8,1],...,[24,12],[31,12]]
                      ³     - 100
                     +      - add (vectorises): [[101,101],[108,101],...[124,112],[131,112]]
                       D    - to decimal (vectorises): [[[1,0,1],[1,0,1]],[[1,0,8],[1,0,1]],...,[[1,2,4],[1,1,2]],[[1,3,1],[1,1,2]]]
                        Ç€  - call last link as a monad for €ach: [[0,1,'.',0,1,'.',2017],[0,8,'.',0,1,'.',2017],...,[2,4,'.',1,2,'.',2017],[3,1,'.',1,2,'.',2017]]
                          Y - join with line feeds: [0,1,'.',0,1,'.',2017,'\n',0,8,'.',0,1,'.',2017,'\n',...,'\n',2,4,'.',1,2,'.',2017,'\n',3,1,'.',1,2,'.',2017]
                            - implicit print

Jonathan Allan

Posted 2017-04-13T03:10:55.697

Reputation: 67 804

Why don't you use ⁽¥Ñ instead? New feature? – user202729 – 2018-05-11T04:40:44.320

This post was made about a month before I implemented . I will update it but I have not trawled through my old posts looking for golfs using newer language features (there are probably many that could use the quicks ƊƲɗʋ, a bunch that could use Ɲ, and a few that could use Ƥ or ÐƤ, and maybe more...). – Jonathan Allan – 2018-05-11T07:00:31.990

0

Python 3.6, 94 bytes

from datetime import*
for x in range(53):print(f"{datetime(1,1,1)+timedelta(x*7):%d.%m.2017}")

I wanted to try using high-level features. Well, it's still readable but not that short…

301_Moved_Permanently

Posted 2017-04-13T03:10:55.697

Reputation: 401

0

T-SQL, 141 bytes

SELECT FORMAT(d,'dd.MM.yyyy')FROM(SELECT DATEADD(ww,ROW_NUMBER()OVER(ORDER BY name)-1,'20170101')d FROM sys.stats)a WHERE 2017=DATEPART(yy,d)

Try it here

grabthefish

Posted 2017-04-13T03:10:55.697

Reputation: 161

0

k, 36 Bytes

Same approach as zgrep. 2017.01.01+0 7 14..., string it, split it on ".", reverse each and join back on "." - finally print the list of strings e.g. -1@("Print";"me");

-1@"."/:'|:'"."\:'$2017.01.01+7*!53;

Only showing a few

Chromozorz

Posted 2017-04-13T03:10:55.697

Reputation: 338

0

Oracle SQL, 89 bytes

    select to_char(to_date('25-DEC-16')+level*7,'DD.MM.YYYY') from dual connect by level < 54

Explanation: You can just add an integer to a date and it's treated as a number of days. Exploiting connect by we're generating 53 rows for the 53 sundays which occur in 2017. Setting the starting date as the last sunday of 2016 saves me two bytes because I don't have to subtract 7 to compensate level starting at 1.

Demonblack

Posted 2017-04-13T03:10:55.697

Reputation: 121

0

Microsoft Sql Server, 114 bytes

with v as(select 0 n union all select n+7 from v where n<364)select format(dateadd(d,n,'2017'),'dd.MM.yyyy')from v

Check It Online

Andrei Odegov

Posted 2017-04-13T03:10:55.697

Reputation: 939

0

05AB1E, 81 79 bytes

•8tåxвÓÈCм∞º²áÝViΣþ1₄ɨÅ9”ÓU2Èn¶äΔb'Î?™Íćεr$Ã]7¤¶¸M•11BR'A¡vy2ôN>".ÿ.2017"«})˜»

Try it online!

No date built-ins.


01081522A05121926A05121926A0209162330A07142128A04111825A0209162330A06132027A03101724A0108152229A05121926A0310172431

Is the compressed base-11 number at the beginning, when split on A's you get:

['01081522', '05121926', '05121926', '0209162330', '07142128', '04111825', '0209162330', '06132027', '03101724', '0108152229', '05121926', '0310172431']

Which is the days of each month that are Sundays, in order. Then, we split each one into pieces of two, and concatenate the index of those days plus 2017 to each.

Finally we just flatten and return the list separated by newlines.

Magic Octopus Urn

Posted 2017-04-13T03:10:55.697

Reputation: 19 422

0

Tcl, 80 bytes

time {puts [clock format [expr 1482624000+[incr i 604800]] -format %d.%m.%Y]} 53

Try it online!

sergiol

Posted 2017-04-13T03:10:55.697

Reputation: 3 055

0

Japt -R, 25 21 15 bytes

Locale dependent - You'll need to set your browser's locale to (among others, I'm sure) Romania (RO), Russia (RU) or Turkey (TR) for the dates to be formatted correctly.

#5ÆÐ#É7TX*7Ä s7

Test it


Explanation

Takes advantage of the fact that if you provide JavaScript's date construct a value for the day that's higher than the number of days in the month you've provided, it will rollover to the next month.

#5                        :53
  Æ                       :Create the range [0,53) and pass each integer X through a function
    #É7                   :  2017
       T                  :  0
        X*7Ä              :  X*7+1
   Ð                      :  new Date() with those 3 arguments as year, month & day
             s7           :  Convert to date string, locale formatted

Shaggy

Posted 2017-04-13T03:10:55.697

Reputation: 24 623

0

JavaScript, 80 bytes

(f=x=>x?[...f(--x),new Date(2017,0,x*7+1).toLocaleDateString()]:[])(53).join`
`

Shaggy

Posted 2017-04-13T03:10:55.697

Reputation: 24 623

This looks like an auto-flag, so I'm reviewing Looks OK. – Nissa – 2018-05-12T00:24:20.953

0

Pyth, 122 bytes

jm+X2d\.".2017"c+\0`i."0Z|´&ÓäßæÅJÈD@ßÍTû=´}¾}Zàe+ñðºâ$ðGzdüä#Ò×ûíO^©¢Q Óýo`Åi2ÓàÀ{9¢à>«+íø#o^Mý"36 4

Try it online!

The code uses unprintable characters that are not displayed properly on Stack Exchange. Use the link to get the working version.

Pyth doesn't have a way to check whether a date is a Sunday, so this is the Kolmogorov version.
It uses a MAGIC STRING which represents this integer.

Explanation:
jm+X2d\.".2017"c+\0`i."…"36 4 # Code with MAGIC STRING replaced with …
                   `          # String representation of
                      "…"     # THE MAGIC STRING
                     ."       # Decompressed
                    i    36   # To int from base 36
                +\0           # With a 0 in front
               c            4 # Chopped into strings of length 4 as a list
 m                            # With each member
   X2d\.                      #  with . inserted at index 2
  +     ".2017"               #  and appended with .2017
j                             # Joined with newlines

hakr14

Posted 2017-04-13T03:10:55.697

Reputation: 1 295

0

Red, 107 bytes

f: func[n][n: pad/left/with to-string n 2 #"0"]d: 1-1-2
loop 53[print rejoin[f d/3":"f d/4":"2017]d: d + 7]

Try it online!

Galen Ivanov

Posted 2017-04-13T03:10:55.697

Reputation: 13 815

0

Groovy, 52 bytes

53.times{printf('%td.%<tm.2017%n',new Date(0)+it*7)}

Building on Krystian's groovy answer above with an optimisation dropping another four bytes. Uses the fact that the epoch year 1970 matches 2017 weekdays and months.

Matias Bjarland

Posted 2017-04-13T03:10:55.697

Reputation: 420