Skip to main content
added 23 characters in body
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

Python 2, 5957 bytes

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

Try it online!Try it online!

2 bytes thanks to Dennis

Uses an exec loop to counts up n in steps of 9 as 1008, 1017, ..., 89919981, 90009990, 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'in`n` . This condition is joined with the other one with a chained inequality, using that Python 2 treats strings as greater than numbers.

Python 2, 59 bytes

n=999
exec"n+=9\nif'0'in`n`>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'in`n` . This condition is joined with the other one with a chained inequality, using that Python 2 treats strings as greater than numbers.

Python 2, 57 bytes

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

Try it online!

2 bytes thanks to Dennis

Uses an exec loop to counts up n in steps of 9 as 1008, 1017, ..., 9981, 9990, 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'in`n` . This condition is joined with the other one with a chained inequality, using that Python 2 treats strings as greater than numbers.

Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

Python 2, 59 bytes

n=999
exec"n+=9\nif'0'in`n`>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'in`n` . This condition is joined with the other one with a chained inequality, using that Python 2 treats strings as greater than numbers.