36
\$\begingroup\$

Python is the fastest-growing major programming language today. It is the most wanted language for the third year in a row, meaning that developers who do not yet use it say they want to learn it.[1]

The reason for Python's popularity is its many versions.[citation needed] There are in fact 116 versions of Python, including two development versions.

Your task is to output/print a list of all the Python versions, in whatever order you like, and on whatever format you like. You may not use any built-in functions that have this information stored.

You are free to choose the output format, but each version must be identified on the standard way: 1.1, 2.3.0, 2.7.10 and so on.

The complete list2 of Python versions, comma-separated is shown below:

1.1, 1.2, 1.3, 1.4, 1.5, 1.5.1, 1.5.2, 1.6, 2.0, 2.0.1, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.2, 2.2.1, 2.2.2, 2.2.3, 2.3, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.4, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.5, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5, 2.6.6, 2.6.7, 2.6.8, 2.6.9, 2.7, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.7.5, 2.7.6, 2.7.7, 2.7.8, 2.7.9, 2.7.10, 2.7.11, 2.7.12, 2.7.13, 2.7.14, 2.7.15, 2.7.16, 3.0, 3.0.1, 3.1, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.2 , 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.2.6, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4, 3.3.5, 3.3.6, 3.3.7, 3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.5.3, 3.5.4, 3.5.5, 3.5.6, 3.5.7, 3.6.0, 3.6.1, 3.6.2, 3.6.3, 3.6.4, 3.6.5, 3.6.6, 3.6.7, 3.6.8, 3.7.0, 3.7.1, 3.7.2, 3.7.3

or by major versions:

1.1
1.2
1.3
1.4
1.5, 1.5.1, 1.5.2
1.6
2.0, 2.0.1
2.1, 2.1.1, 2.1.2, 2.1.3
2.2, 2.2.1, 2.2.2, 2.2.3
2.3, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5
2.4, 2.4.1, 2.4.2, 2.4.3, 2.4.4
2.5, 2.5.1, 2.5.2, 2.5.3, 2.5.4
2.6, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5, 2.6.6, 2.6.7, 2.6.8, 2.6.9
2.7, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.7.5, 2.7.6, 2.7.7, 2.7.8, 2.7.9, 2.7.10, 2.7.11, 2.7.12, 2.7.13, 2.7.14, 2.7.15, 2.7.16
3.0, 3.0.1
3.1, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5
3.2, 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.2.6
3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4, 3.3.5, 3.3.6, 3.3.7
3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 3.4.9, 3.4.10 
3.5.0, 3.5.1, 3.5.2, 3.5.3, 3.5.4, 3.5.5, 3.5.6, 3.5.7
3.6.0, 3.6.1, 3.6.2, 3.6.3, 3.6.4, 3.6.5, 3.6.6, 3.6.7, 3.6.8
3.7.0, 3.7.1, 3.7.2, 3.7.3

The challenge is a fixed output challenge, and very close to a , except that the output format is optional.

2The list is taken from the official Python website, here and here. There are some versions that aren't included, such as 0.9.0 .. 0.9.9 and 1.5.1p1. You must use the list above, even if you find versions that aren't included. I've decided to stick with the official lists, since otherwise someone would probably find a 2.1.0.1.2 version or something like that.

\$\endgroup\$
  • 2
    \$\begingroup\$ I guess we aren't allowed to output 1.1.0 (to make all versions 3 numbers) instead of 1.1? \$\endgroup\$ – Kevin Cruijssen Apr 16 at 9:27
  • 2
    \$\begingroup\$ You guess correctly @Kevin. I considered allowing it, but went with the official names instead. \$\endgroup\$ – Stewie Griffin Apr 16 at 9:37
17
\$\begingroup\$

JavaScript (ES6),  128 125  124 bytes

Saved 1 bytes thanks to @OlivierGrégoire

Outputs each version on a separate line. Ordered from highest to lowest major version, and from lowest to highest revision.

f=(r=v=28)=>v?r<parseInt('0111131000244655ah002678b8940'[v],36)?(1+v/10).toFixed(1)+(r|v>22?'.'+r:'')+`
`+f(r+1):f(+!v--):''

Try it online!

How?

The major and minor versions are held in the variable \$v \in [0..27]\$:

  • major = \$\lfloor v/10+1\rfloor\$
  • minor = \$v \bmod 10\$

The revision is held in the variable \$r\ge0\$. The maximum value of \$r\$ depends on \$v\$ and is stored in a lookup table encoded in Base-36. Any \$0\$ in this table means that this version was not released at all.

Besides, we use the test \$v>22\$ to know whether the revision should be included even when it's \$0\$ (starting with Python 3.3.0).

\$\endgroup\$
5
\$\begingroup\$

C# (Visual C# Interactive Compiler), 109 bytes

for(int j,k=1;;k++)for(j=@" [SOH][SOH][SOH][SOH][ETX][SOH][NUL][NUL][NUL][STX][EOT][EOT][ACK][ENQ][ENQ]
[DC1][NUL][NUL][STX][ACK][BEL][BS][VT][BS][TAB][EOT]"[k];j-->0;)Print($"{k*.1+1:N1}"+(j<1&k<17?"":"."+j));

Contains many unprintables, whose codes are shown in the brackets. This is a full program. The null bytes are replaced by \0s in the TIO link, since my device can't copy and paste them.

Saved one byte thanks to @OlivierGregoire.

Try it online! (Thanks to @OlivierGregoire for implanting the null bytes)

Explanation

Each character in the string represents how many minor versions in the major position. For example, the character at index 5(ETX) has an ASCII value of three, and corresponds to the major version 1.5.x which has three minor versions. The program takes the ascii value of the current character and loops that many times, printing the minor versions before moving on to the next major version.

For some versions, there are gaps to the next versions. To fix that, the string contains null bytes, so that the program loops zero times when it encounters those.

The unprintable string contains these character values:

1,1,1,1,3,1,0,0,0,2,4,4,6,5,5,10,17,0,0,2,6,7,8,11,8,9,4
\$\endgroup\$
  • \$\begingroup\$ Can be shortened with j="..."[k];j-->0;, especially since the order has no importance. Also, can you explain the difference in size between the TIO (115 bytes) and the entry (110 bytes)? \$\endgroup\$ – Olivier Grégoire Apr 17 at 8:34
  • \$\begingroup\$ @OlivierGrégoire Probably the five null bytes which tio represent as \0 \$\endgroup\$ – Sefa Apr 17 at 9:45
  • \$\begingroup\$ @Sefa yes, probably... But I'm asking for certainty. \$\endgroup\$ – Olivier Grégoire Apr 17 at 10:37
  • \$\begingroup\$ @OlivierGrégoire Exactly what Sefa said, I can't really copy-paste the null bytes. If the \0s were replaced by null bytes, it would be 110 bytes \$\endgroup\$ – Embodiment of Ignorance Apr 17 at 14:42
  • \$\begingroup\$ Then, here you are, with a nul-byte TIO \$\endgroup\$ – Olivier Grégoire Apr 17 at 14:56
4
\$\begingroup\$

Java (JDK), 134 bytes

v->{for(int a=0,b;;)for(b="0111131000244655:A002678;894".charAt(++a)-48;b-->0;)System.out.printf("%.1f%s ",a*.1+1,b<1&a<23?"":"."+b);}

Try it online!

The versions are printed from the highest to the lowest.

Credits

\$\endgroup\$
3
\$\begingroup\$

Retina, 105 bytes


11* 111131   244655TS  2678E894
L$`.
$&_$.`
T
10
E
11
S
17
.+_
*
Lv$`_+(.)(.)
$1.$2.$.%`
,16`(...)\.0
$1

Try it online! Loosely based on @Arnauld's solution. Explanation:


11* 111131   244655TS  2678E894

Insert the string consisting of 11 spaces followed by the given characters.

L$`.
$&_$.`

For each character, list it suffixed with a _ and its column number.

T
10
E
11
S
17

Convert the three letters to numeric values.

.+_
*

Convert the numeric values to unary.

Lv$`_+(.)(.)
$1.$2.$.%`

For each value up to the given value, use that as the suffix for the version number, extracting the major and minor from the column number.

,16`(...)\.0
$1

Delete the zero suffix for the first 16 versions that have one.

\$\endgroup\$
2
\$\begingroup\$

Pyth, 52 bytes

.emj\.+W|d>k18,h/k8%k8dbxLG"abbbbdbaceegffkrcghilije

Try it online here.

Output is a nested list, with elements grouped by major and minor version. There is an empty list at the start of the output, and another one after 1.6. Full output is as follows:

[[], ['1.1'], ['1.2'], ['1.3'], ['1.4'], ['1.5', '1.5.1', '1.5.2'], ['1.6'], [], ['2.0', '2.0.1'], ['2.1', '2.1.1', '2.1.2', '2.1.3'], ['2.2', '2.2.1', '2.2.2', '2.2.3'], ['2.3', '2.3.1', '2.3.2', '2.3.3', '2.3.4', '2.3.5'], ['2.4', '2.4.1', '2.4.2', '2.4.3', '2.4.4'], ['2.5', '2.5.1', '2.5.2', '2.5.3', '2.5.4'], ['2.6', '2.6.1', '2.6.2', '2.6.3', '2.6.4', '2.6.5', '2.6.6', '2.6.7', '2.6.8', '2.6.9'], ['2.7', '2.7.1', '2.7.2', '2.7.3', '2.7.4', '2.7.5', '2.7.6', '2.7.7', '2.7.8', '2.7.9', '2.7.10', '2.7.11', '2.7.12', '2.7.13', '2.7.14', '2.7.15', '2.7.16'], ['3.0', '3.0.1'], ['3.1', '3.1.1', '3.1.2', '3.1.3', '3.1.4', '3.1.5'], ['3.2', '3.2.1', '3.2.2', '3.2.3', '3.2.4', '3.2.5', '3.2.6'], ['3.3.0', '3.3.1', '3.3.2', '3.3.3', '3.3.4', '3.3.5', '3.3.6', '3.3.7'], ['3.4.0', '3.4.1', '3.4.2', '3.4.3', '3.4.4', '3.4.5', '3.4.6', '3.4.7', '3.4.8', '3.4.9', '3.4.10'], ['3.5.0', '3.5.1', '3.5.2', '3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7'], ['3.6.0', '3.6.1', '3.6.2', '3.6.3', '3.6.4', '3.6.5', '3.6.6', '3.6.7', '3.6.8'], ['3.7.0', '3.7.1', '3.7.2', '3.7.3']]

If this isn't acceptable, prepend .n to the code to have output as a flattened list, at a cost of 2 bytes.

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

Jelly, 51 bytes

+⁵D;ⱮḶ}j€”.
“øṄƇịɱ⁽Ɱj>⁶7,Ẉ¢’b18Ė0ị$Ƈç/€ḣ3$€1¦€17R¤¦

Try it online!

A niladic link that outputs a list of lists of .-separated integers, grouped by major version. On TIO, there’s some footer code to print these prettily.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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