# List all possible titles for the Anno games

In the Anno video game series there are 6 games with a 7th one announced for early 2019. Their titles always feature a year in a specific pattern:

Anno 1602, Anno 1503, Anno 1701, Anno 1404, Anno 2070, Anno 2205, Anno 1800

• The digital sum is always 9.
• The years are four digits long.
• They contain at least one zero.

Within these constrains there exist 109 possible titles:

[1008,1017,1026,1035,1044,1053,1062,1071,1080,1107,1170,1206,1260,1305,1350,1404,1440,1503,1530,1602,1620,1701,1710,1800,2007,2016,2025,2034,2043,2052,2061,2070,2106,2160,2205,2250,2304,2340,2403,2430,2502,2520,2601,2610,2700,3006,3015,3024,3033,3042,3051,3060,3105,3150,3204,3240,3303,3330,3402,3420,3501,3510,3600,4005,4014,4023,4032,4041,4050,4104,4140,4203,4230,4302,4320,4401,4410,4500,5004,5013,5022,5031,5040,5103,5130,5202,5220,5301,5310,5400,6003,6012,6021,6030,6102,6120,6201,6210,6300,7002,7011,7020,7101,7110,7200,8001,8010,8100,9000]


Your objective is to list them all in any reasonable form in the fewest number of bytes.

• How flexible is the output format? Is this acceptable? – Luis Mendo Oct 15 '18 at 14:50
• @LuisMendo Yes, that's fine with me. – Laikoni Oct 15 '18 at 14:54
• Are lists of digits allowed? – Erik the Outgolfer Oct 15 '18 at 18:18
• @aslum I assume you mean a lot of spaces, not just one, right? Comment markdown doesn't allow for a good representation of that. And I would assume that's allowed, given that Luis's format above is allowed. ;-) – Erik the Outgolfer Oct 15 '18 at 20:20
• @EriktheOutgolfer I'd say no to lists of digits because they really do not look like years anymore. – Laikoni Oct 15 '18 at 21:50

# Stax, 13 bytes

ü┌o☻≈;╫▄mI░↨Z


Run and debug it

Unpacked, ungolfed, and commented, it looks like this.

VM      Constant one million
this program produces its output pretty quickly, but takes much longer to end
f       filter the numbers [1..n] using the rest of the program as a predicate
$convert to ascii decimal string e.g. "1234" |+ sum of ascii codes 201= is equal to 201 [result a] _E:* product of the decimal digits [result b] > [result a] is greater than [result b]  Run this one • @Laikoni: I read the challenge wrong, and missed that requirement. I've updated my submission, at the cost of 4 bytes. – recursive Oct 16 '18 at 0:20 # J, 38 bytes -1 byte and bug fixed thanks to Quintec echo(#~(4#10)(0&e.*9=+/)@#:])1e3+i.9e3  Try it online! Thanks to Laikoni for findng an even bigger bug! • 1000 can be 1e3 for a byte saved, right? – Quintec Oct 15 '18 at 17:12 • (Also, should it be 9e3 instead of 9e4?) – Quintec Oct 15 '18 at 17:17 • @Quintec Yes, sure. I tried it, but forgot it (golfing on the phone) – Galen Ivanov Oct 15 '18 at 17:18 • @Laikoni As in my Red answer, I forgot this, sorry! Fixed. – Galen Ivanov Oct 16 '18 at 6:29 # K (oK), 37 bytes x@&{9=+/x*0in x}'(4#10)\'x:1000+!9000  Try it online! On mobile, will add explanation later. Couldn't get 0 in' to work without the lambda which wastes bytes... • 36 - x@&9=+/+y*|/~+y:(4#10)\'x:1000+!9000 – streetster Oct 16 '18 at 22:45 # JavaScript (SpiderMonkey), 57 bytes for(y=0;y<9e3;)/(?=([0-4].?){3}).*0/.test(y+=9)&&print(y)  Try it online! # JavaScript (SpiderMonkey), 58 bytes for(y=999;++y<1e4;9-p-q-r-s|q*r*s||print(y))[p,q,r,s]=''+y  Try it online! You may change print to alert to test it in your browser. :) • Maybe the first time I realize that submitting a whole program is even shorter than a function in JavaScript... – tsh Oct 16 '18 at 8:19 # K (ngn/k), 33 bytes t@&"0"=*'t@'<'t:$&201=+/'i:$!9001  Try it online! Will edit with explanation later. # Julia 1.0, 52 bytes f()=[x for x=1:9^5 if'0' in"$x"&&sum(Int,"$x")==201]  Try it online! # C (clang), 95 91 bytes f(i){char*c;for(i=1e4;--i;*c+c[1]+c[2]+c[3]-201||index(c,48)&&puts(c))asprintf(&c,"%d",i);}  Try it online! -4 bytes thanks to @ceilingcat # Common Lisp, 140 bytes (defun x()(loop for x from 1008 to 9000 for y =(map'list #'digit-char-p(prin1-to-string x))when(and(member 0 y)(=(apply #'+ y)9))collect x))  Try it online! • This does not ensure that each year contains at least one zero. – Laikoni Oct 18 '18 at 21:27 • Edited, i must have overlooked that – JRowan Oct 21 '18 at 22:36 • It looks like you can drop the space in map 'list. Also there are two trailing newlines that do not appear to be necessary. – Laikoni Oct 22 '18 at 5:40 # Haskell, 66 79 74 bytes drop 55[x>>=show|x<-sequence.replicate 4$[0..9],sum x==9,elem 0x]


Damn you with your type juggling, you can treat numbers as strings :(

Basically just an exact description of whats asked here. Just no spaces.

Try it online! (Modifications for it to run were necessary, tio doesn't support pure functions in Haskell.)

• Nice approach, but unfortunately lists of digits are not valid output. However, there a few ways you can save some bytes to make up for the additional ones you need for the final conversion to a string. First of all, a list comprehension is shorter than filter and you can drop the second space in elem 0 x. – Laikoni Oct 22 '18 at 22:01
• A few more: Instead of using map the conversion to string can be put into the list comprehension. concat.map is common enough that there exists a build-in called concatMap, however the overloading of the bind operator =<< on lists has the same effect and is even shorter. – Laikoni Oct 23 '18 at 14:13
• The default bind operator is (>>=), what you showed is the reverse bind operator. – schuelermine Oct 24 '18 at 9:59

# MathGolf, 16 13 bytes

♫♪↨Ç{▒ε*\Σ8=┌


Try it online!

### Explanation:

  ↨              Range from
♫♪               1000 to 10000
Ç{            Filter out by
▒ε*         The product of all digits is not 0
Σ8=┌     The digit sum of the loop index (0 based) is not equal to 8

• Does MathGolf have an ord command to transform characters/digits to unicode values? If yes, you might be able to use the same ord sum == 201 trick other answers use, which covers both the length == 4 and digit sum == 9 at the same time. – Kevin Cruijssen Oct 16 '18 at 8:02
• @KevinCruijssen Unfortunately, it doesn't, but I've requested it – Jo King Oct 16 '18 at 11:48
• @JoKing I'm a bit late to the party, but both of these things have been implemented, and have been submitted for pulling to TIO. check out the README for instructions. I've had a very stressful month, but I'm trying to get everything implemented. – maxb Nov 27 '18 at 10:18

# Retina 0.8.2, 52 bytes


9001$* .$.=>$.; >|\G\d$*
M!\d{4}(?==1{9};)
G0


Try it online! Explanation:


9001$*  Insert 9001 1s. .$.=>$.;  Replace each 1 with the number of 1s to its left, followed by =>, followed by the same number again, followed by ;. >|\G\d$*


Convert > and subsequent digits to unary, thus calculating the digit sum.

M!\d{4}(?==1{9};)


List all the 4-digit numbers with a digit sum of 9.

G0


Keep those that contain a zero.

# Red, 109 bytes

repeat n 8000[s: 0 p: 1 foreach t form d: 1000 + n[s: s + r: do t - 48 p: p * r]if all[s = 9 p = 0][print d]]


Try it online!

• @Laikoni Sorry, apparently I've missed that part. Fixed. – Galen Ivanov Oct 16 '18 at 6:20

# Pyth, 22 19 bytes

f&}\0Tq201sCMTM^T4


Output is an array of strings. Try it online here.

f&}\0Tq201sCMTM^T4
M^T4   Array of strings of numbers 0-999
f                     Keep the elements of the above, as T, where:
CMT          Get the code points of each character in T
s             Take the sum
q201              Does the above == 201?
}\0T                  Does T contain "0" ?
&                      Logical AND the two previous results


The 201 trick is the same as used in other answers.

Previous answer, without using 201 trick, 22 bytes: iRTf}0Tfq9sTjRTr^T3^T4

# Jelly, 13 bytes

ȷ4ȷrDS9Ƒ>ẠƲƇḌ


Try it online!

-2 (yucky, yucky trivial) bytes thanks to Dennis.

# PHP, 114 bytes

<?php
for($i=1e3;$i<=9e3;$i++) if(array_sum($a=[$i/1e3%10,$i/100%10,$i/10%10,$i%10])==9&in_array(0,$a)) echo$i.' ';


Try it online!

# Prolog 117 bytes

b(X):-between(0,9,X). w(X):-write(X). y():-b(A),b(B),b(C),b(D),X is A+B+C+D,X=9,(A=0;B=0;C=0;D=0),w(A),w(B),w(C),w(D).

• Would you consider adding a link to a service like Try it online! - (link is to your code, but I'm not sure if the footer is right since I don't prolog much.)? – Οurous Oct 18 '18 at 5:25
• 98 – ASCII-only Nov 14 '18 at 5:07
• 91 – ASCII-only Nov 14 '18 at 5:18

# J, 35 bytes

echo@>55}.I.(4#10)(*/<9=+/)@#:i.1e4


Try it online!

# C# (.NET Core), 106 bytes

for(int i=999;++i<9999;)if(i.ToString().Sum(c=>c-'0')==9&&i.ToString().Contains("0"))Console.WriteLine(i);


Try it online!

Ungolfed:

for(int i = 999; ++i < 9999;)               // from 1000 to 9999 (fulfills four digit parameter)
if(i.ToString().Sum(c => c - '0') == 9  // if the sum of the digits is nine
&& i.ToString().Contains("0"))  //   and if the year contains at least one zero
Console.WriteLine(i);               // write the year to the console


# Scala, 58 bytes

jrook's solution is currently 2 byte shorter

val v=(9 to 9000).filter(x=>(x+"").min<49&(x+"").sum==201)

val v=(9 to 9000).map(_+"").filter(x=>x.min<49&x.sum==201)


Try it online!

# Attache, 37 bytes

{{Sum@Ords@_=201and"0"in _}@S\1:9000}


Try it online!

Based on the perl answer.

# Perl 5-MList::Util=sum, 40 32 bytes

map/0/*9-(sum/./g)||say,1E3..9E3


Try it online!

# Kotlin, 59 bytes

Lambda that returns a List<Int> containing every valid year.

{(1008..9000).filter{"$it".sumBy{it-'0'}==9&&'0' in "$it"}}
`

Try it online!