# List all possible titles for the Anno games

Laikoni 10/15/2018. 30 answers, 3.940 views

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.

J.Doe 10/16/2018.

# R, 59 51 bytes

Outputs the valid numbers as the names of a list of 201's. Why 201? Because ASCII 0 is 48, and 4*48+9 is... yeah. Saved 6 bytes by aliasing ^ to Map and another 2 by using 1:9e3 as range.

"^"=Map;x=sum^utf8ToInt^grep(0,1:9e3,,,T);x[x==201]

Try it online!

# Explanation

# Create list of sums of ASCII char values of numbers,
# with the original numbers as the names of the list
x <- Map(sum,
# Create a list from the strings where each element is the string split
# into ASCII char values
Map(utf8ToInt,
# Find all numbers between 1 and 9e3 that contain a zero
# Return the matched values as a vector of strings (6th T arg)
grep(pattern=0,x=1:9000,value=TRUE)
)
)
# Pick out elements with value 201 (i.e. 4-digits that sum to 9)
# This implicitly only picks out elements with 4 digits, since 3-digit
# sums to 9 won't have this ASCII sum, letting us use the 1:9e3 range
x[x==201] 

nwellnhof 10/16/2018.

# Perl 6, 35 33 bytes

-2 bytes thanks to Jo King

{grep {.ords.sum==201&&/0/},^1e4}

Try it online!

TFeld 10/16/2018.

# Python 2, 6766 64 bytes

print[y for y in range(9001)if('0'iny)*sum(map(ord,y))==201]

Try it online!

Saved:

• -1 byte, thanks to Luis felipe De jesus Munoz
• -2 bytes, thanks to Kevin Cruijssen

# PowerShell, 50 49 bytes

999..1e4-match0|?{([char[]]"$_"-join'+'|iex)-eq9} Try it online! Constructs a range from 999 to 10000, then uses inline -match as a filter to pull out those entries that regex match against 0. This leaves us with 1000, 1001, 1002, etc. We then pipe that into a Where-Object clause where we take the current number as a string "$_", cast it as a char-array, -join those characters together with + and Invoke-Expression (similar to eval) to come up with their digit sum. We check whether that is -equal to 9, and if so it's passed on the pipeline. At program completion, those numbers are picked up from the pipeline and implicitly output.

Alion 10/15/2018.

# JavaScript (Node.js), 89 bytes

[...Array(9e3)].map(_=>i++,i=1e3).filter(a=>(s=[...a+""]).sort()[0]<1&eval(s.join+)==9)

Try it online!

• -4 bytes thanks to @ETHproductions

# JavaScript (Node.js), 129127126124115114111110105979392 90 bytes

[...Array(9e3)].map(f=(_,i)=>eval(s=[...(i+=1e3)+""].sort().join+)-9|s[0]?0:i).filter(f)

Try it online!

### Explanation

[...Array(9e3)].map(f=(_,i)=>eval(s=[...(i+=1e3)+""].sort().join+)-9|s[0]?0:i).filter(f)
[...Array(9e3)].map(f=(_,i)=>                                                  )           // Create a 9000-length array and loop over it; store the loop body
[...(i+=1e3)+""]                                       // Add 1000 to the index and split it into an array of characters (17 -> ["1", "0", "1", "7"])
.sort()                                // Sort the array of characters in ascending order by their code points ("0" will always be first) (["1", "0", "1", "7"] -> ["0", "1", "1", "7"])
s=                       .join+                        // Join them together with "+" as the separator (["0", "1", "1", "7"] -> "0+0+2+9"); store the result
eval(                                 )-9                     // Evaluate and test if it's different than 9
s[0]                // Take the first character of the string and implicitly test if it's different than "0"
|    ?0              // If either of those tests succeeded, then the number doesn't meet challenge criteria - return a falsey value
:i            // Otherwise, return the index
.filter(f) // Filter out falsey values by reusing the loop body

First time doing code golf in JavaScript. I don't think I need to say it, but if I'm doing something wrong, please notify me in the comments below.

• -3 bytes thanks to @Luis felipe De jesus Munoz

• -6 bytes thanks to @Kevin Cruijssen

xnor 10/16/2018.

# Python 2, 59 bytes

n=999
exec"n+=9\nif'0'inn>int(n,11)%10>8:print n\n"*889

Try it online!

Uses an exec loop to counts up n in steps of 9 as 1008, 1017, ..., 8991, 9000, printing those that meet the condition.

Only multiples of 9 can have digit sum 9, but multiples of 9 in this range can also have digits sum of 18 and 27. We rule these out with the condition int(n,11)%10>8. Interpreting n in base 11, its digit sum is equal to the number modulo 10, just like in base 10 a number equals its digit sum modulo 9. The digits sum of (9, 18, 27) correspond to (9, 8, 7) modulo 10, so taking those>8 works to filter out nines.

The number containing a zero is check with string membership. '0'inn. This condition is joined with the other one with a chained inequality, using that Python 2 treats strings as greater than numbers.

Arnauld 10/15/2018.

# JavaScript (ES6), 78 73 bytes

Saved 2 bytes thanks to @KevinCruijssen

Returns a space-separated string.

f=(n=9e3)=>n>999?f(n-9)+(eval([...n+''].join+)&/0/.test(n)?n+' ':''):''

Try it online!

### How?

We iterate over the range $$\[1008..9000]\$$ with an increment of $$\9\$$, ignoring numbers that don't have a $$\0\$$.

All these numbers are multiples of $$\9\$$, so the sum of their digits is guaranteed to be a multiple of $$\9\$$ as well.

Because valid numbers have at least one $$\0\$$, they have no more than two $$\9\$$'s, which means that the sum of the remaining digits is at most $$\18\$$. Therefore, it's enough to test if the sum of the digits is odd.

Hence the test:

(eval([...n + ''].join+) & /0/.test(n)

Dennis 10/16/2018.

# Jelly, 11 bytes

9ȷṢ€æ.ẹ9ṫ19

Try it online!

### How it works

9ȷṢ€æ.ẹ9ṫ19  Main link. No arguments.

9ȷ           Set the left argument and the return value to 9000.
Ṣ€         Sort the digits of each integer in [1, ..., 9000].
æ.       Perform the dot product of each digit list and the left argument,
which gets promoted from 9000 to [9000].
Overflowing digits get summed without multiplying, so we essentially
map the digit list [a, b, c, d] to (9000a + b + c + d).
ẹ9     Find all 1-based indices of 9.
Note that 9000a + b + c + d == 9 iff a == 0 and b + c + d == 9.
ṫ19  Tail 19; discard the first 18 indices.

Giuseppe 10/15/2018.

# R, 82 bytes

write((x=t(expand.grid(1:9,0:9,0:9,0:9)))[,colSums(x)==9&!apply(x,2,all)],1,4,,"")

Try it online!

Generates a matrix x of all possible 4-digit numbers, excluding leading zeros, going down columns. Then filters for column (digital) sums of 9 and containing zero, i.e., not all are nonzero. write prints down the columns, so we write to stdout with a width of 4 and a separator of "".

Outgolfed by J.Doe

# Japt, 20 18 bytes.

-2 bytes thanks to @Shaggy and @ETHproductions

A³òL² f_=ì)x ¥9«Z×

A³òL² f_=ì)x ¥9«Z×  Full program
A³òL²               Range [1000, 10000]
f_            Filter by :
=ì)         Convert to array
x ¥9     Sum equal to 9?
«    And
Z×  Product not 0

Try it online!

Thor 10/15/2018.

# sed and grep (and seq), 7264 63 bytes

seq 9e3|sed s/\\B/+/g|bc|grep -wn 9|sed s/:9//|grep 0|grep ....

DLosc 10/15/2018.

# Pip, 18 bytes

{0Na&$+a=9}FIm,t*m Use an ouput-format flag such as -p to get readable output. Try it online! {0Na&$+a=9}FIm,t*m
m,t*m  Range from 1000 to 10*1000
{         }FI       Filter on this function:
0Na                 There is at least one 0 in the argument
&                and
$+a The sum of the argument =9 equals 9 Misha Lavrov 10/16/2018. # Wolfram Language (Mathematica), 56 55 bytes Select[9!!~Range~9999,Tr@#==Times@@#+9&@*IntegerDigits] Try it online! We test the range from 9!! = 945 to 9999, since there are no results between 945 and 999. Maybe there's a shorter way to write a number between 9000 and 10007, as well. Tr@#==Times@@#+9& applied to {a,b,c,d} tests if a+b+c+d == a*b*c*d+9, which ends up being equivalent to The Anno Condition. G B 10/16/2018. # Ruby, 46 42 41 bytes ?9.upto(?9*4){|x|x.sum==201&&x[?0]&&p(x)} Try it online! ### How it works: • Iterate on strings ranging from '9' to '9999' • Check that sum of ASCII values is 201 • Check if string contains a zero (without regex, a regex would be 1 byte longer) (Thanks Laikoni for -2 bytes) Kevin Cruijssen 10/16/2018. # 05AB1E, 15 13 bytes ₄4°Ÿʒ0å}ʒSO9Q -2 bytes thanks to @Emigna. Try it online. Explanation: ₄4°Ÿ # List in the range [1000,10000] ʒ } # Filter this list by: 0å # The number contains a 0 ʒ # Filter the filtered list further by: SO9Q # The sum of its digits is exactly 9 13-bytes alternative: ₄4°ŸʒW_sSO9Q* Try it online. Explanation: ₄4°Ÿ # List in the range [1000,10000] ʒ # Filter this list by: W_ # Take the minimum digit (without popping), and check if it's a 0 * # And sSO9Q # Where the sum of its digits is exactly 9 And yet another 13-bytes alternative: 4°Lʒ0å}ʒÇOт·- Credit for this alternative goes to @Mr.Xcoder. Try it online. Explanation: 4°L # List in the range [1,10000] ʒ } # Filter this list by: 0å # The number contains a 0 ʒ # Filter the filtered list further by: Ç # Convert the digits to unicode values O # Take the sum т·- # Subtract 200 (Only 1 is truthy in 05AB1E, and the sum of digits # as unicode values equaling 9 is 201) Kevin Cruijssen 10/16/2018. # Java 8, 128117 115 bytes v->{int i=109,r[]=new int[i],n=i;for(;i>0;n++)if((n+"").chars().sum()==201&(n+"").contains("0"))r[--i]=n;return r;} -11 bytes thanks to @nwellnhof. Try it online. Explanation: v->{ // Method with empty unused parameter & int-array return int i=109, // Index-integer, starting at 109 r[]=new int[i], // Result-array of size 109 n=i; // Number integer, starting at 109 for(;i>0; // Loop as long as i is not 0 yet: n++) // After every iteration, increase n by 1 if((n+"").chars().sum()==201 // If the sum of the unicode values of n is 201, // this means there are four digits, with digit-sum = 9 &(n+"").contains("0")) // and n contains a 0: r[--i // Decrease i by 1 first ]=n; // And put n in the array at index i return r;} // Return the array as result Luis Mendo 10/16/2018. # Octave, 49 bytes 6 bytes saved using a more convenient output format as suggested by J.Doe. Thanks to @Laikoni for a correction. y=dec2base(x=1e3:9999,10)'-48;x(sum(y)==9>all(y)) Try it online! aslum 10/16/2018. ## PHP, 69 bytes 87 bytes for($i=999;$i<9001;$i++){echo((array_sum(str_split($i))==9&strpos($i,"0")!=0)?$i:" ");} Note this puts a space for every "failed" number, leading to some kind of funky spacing. This can be changed to comma separation, but will add another 4 characters: ?$i.",":""

Got bigger because I wasn't checking for 0. Derp.

digEmAll 10/16/2018.

# R, 85 bytes

(just competing for the best abuse of R square brackets ... :P )

[=for;i[a<-0:9,j[a,k[a,w[a,if(sum(s<-c(i,j,k,w))==9&any(!s)&i)write(s,1,s='')]]]]

Try it online!

Elcan 10/16/2018.

# Dart, 103 bytes

f()=>List.generate(9001,(i)=>i).where((i)=>'$i'.contains('0')&&'$i'.codeUnits.fold(0,(p,e)=>p+e)==201);

Pretty self-explanatory. generates a list of 9001 (0-9000) cells with the cell's index as value, filters the ones containing a 0 then the one having an ASCII sum of 201 (The result if all the ASCII characters sum to 9). These conditions implictly include that the year is 4 digits long because using 2 ASCII numbers (and the 0), you cannot reach 201.

mb21 10/16/2018.

[i|i<-show<$>[1..5^6],201==sum(fromEnum<$>i),elem '0'i]

Thanks to @Laikoni, see the comments.

import Data.Char (digitToInt)
[i | i <- show <$> [1000..9999], 9 == sum (digitToInt <$> i), '0' elem i]

Quintec 10/15/2018.

# APL(Dyalog), 33 bytes

1e3+⍸{{(9=+/⍵)∧0∊⍵}⍎¨⍕⍵}¨1e3+⍳9e3

Working on golfing it, but I have a headache.

Try it online!

sergiol 10/15/2018.

# Tcl, 77 bytes

time {if [incr i]>1e3&[regexp 0 $i]&9==[join [split$i ""] +] {puts $i}} 9999 Try it online! Shaggy 10/15/2018. # Japt, 16 bytes Returns an array of digit arrays. L²õì l4 k_×ª9aZx Test it ## Explanation L :100 ² :Squared õ :Range [1,L²] ì :Convert each to a digit array l4 :Filter elements of length 4 k_ :Remove each Z that returns truthy (not 0) × : When reduced by multiplication ª : OR Zx : When reduced by addition 9a : And subtracted from 9 RosLuP 10/15/2018. # APL(NARS), 45 chars, 90 bytes f←{⍵×⍳(0∊x)∧9=+/x←⍎¨⍕⍵}⋄f¨1e3..5e3⋄f¨5e3..9e3 test afther some formatting: 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  possible alternative r←f;i;x r←⍬⋄i←1e3⋄→B A: r←r,i B: i+←1⋄→A×⍳(0∊x)∧9=+/x←⍎¨⍕i⋄→B×⍳i≤9e3 Jonathan Allan 10/15/2018. # Jelly, 13 bytes ȷ4µṢÄm3Ḍ)ẹ9ṫ4 Try it online! ### How? ȷ4µṢÄm3Ḍ)ẹ9ṫ4 - Link: no arguments ȷ4 - literal 10^4 = 10000 µ ) - for each in range (1,2,3,...,10000): e.g. 3042 or 5211 Ṣ - sort (given an integer makes digits) [0,2,3,4] [1,1,2,5] Ä - cumulative addition [0,2,5,9] [1,2,4,9] m3 - modulo 3 slice (1st,4th,7th...) [0,9] [1,9] Ḍ - convert from decimal digits 9 19 ẹ9 - 1-based indices equal to nine [9,99,999,1008,1017,...,8100,9000] ṫ4 - tail from the 4th index [1008,1017,...,8100,9000] recursive 10/16/2018. # 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

Galen Ivanov 10/16/2018.

# 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!

streetster 10/16/2018.

# 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...

tsh 10/16/2018.

# 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. :)