27
\$\begingroup\$

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
\$\endgroup\$
9
  • 1
    \$\begingroup\$ Possible dupe of Plan your Sundays? This one is a specific year though. \$\endgroup\$
    – xnor
    Apr 13, 2017 at 3:19
  • 1
    \$\begingroup\$ I checked out Plan your Sundays before posting, but it asks to print the Sundays in a given month. @xnor \$\endgroup\$
    – smanna
    Apr 13, 2017 at 3:21
  • 1
    \$\begingroup\$ Any particular reason for that specific output format? You could open in up a bit. \$\endgroup\$
    – Riker
    Apr 13, 2017 at 3:22
  • 4
    \$\begingroup\$ I actually like this as an exact-text kolmogorov challenge. Getting the date formatting right has some interesting optimizations. \$\endgroup\$
    – xnor
    Apr 13, 2017 at 3:23
  • 5
    \$\begingroup\$ Anyways, I think the close votes should be retracted. \$\endgroup\$ Apr 13, 2017 at 8:28

50 Answers 50

1
2
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ long x=605000000 is shorter \$\endgroup\$
    – cliffroot
    Apr 13, 2017 at 13:30
  • \$\begingroup\$ @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.. \$\endgroup\$ Apr 13, 2017 at 13:45
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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%';
\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ 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;} \$\endgroup\$
    – gastropner
    Nov 23, 2017 at 13:04
  • \$\begingroup\$ Suggest 31-(m%2^m<8) instead of m%2^m<8?30:31 \$\endgroup\$
    – ceilingcat
    Sep 22, 2021 at 8:49
0
\$\begingroup\$

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…

\$\endgroup\$
0
\$\begingroup\$

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

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

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

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ this is the good idea, but you can save a few bytes using spt_values \$\endgroup\$ Jul 13, 2020 at 5:20
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ Why don't you use ⁽¥Ñ instead? New feature? \$\endgroup\$
    – DELETE_ME
    May 11, 2018 at 4:40
  • \$\begingroup\$ 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...). \$\endgroup\$ May 11, 2018 at 7:00
0
\$\begingroup\$

Tcl, 80 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

JavaScript, 80 bytes

(f=x=>x?[...f(--x),new Date(2017,0,x*7+1).toLocaleDateString()]:[])(53).join`
`
\$\endgroup\$
1
  • \$\begingroup\$ This looks like an auto-flag, so I'm reviewing Looks OK. \$\endgroup\$
    – Nissa
    May 12, 2018 at 0:24
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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