Skip to main content
edited body
Source Link
Chau Giang
  • 1.3k
  • 1
  • 11
  • 16

Description

Count how many occurrences there are of the digit 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 2021 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l

Description

Count how many occurrences there are of the digit 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 20 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l

Description

Count how many occurrences there are of the digit 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 21 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l
Tweeted twitter.com/StackCodeGolf/status/1291524518654234627
deleted 1 character in body
Source Link
Olivier Grégoire
  • 14.4k
  • 3
  • 32
  • 56

Description

Count how many occurrences there are of the numberdigit 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 20 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l

Description

Count how many occurrences there are of the number 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 20 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l

Description

Count how many occurrences there are of the digit 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 20 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l
Became Hot Network Question
edited body
Source Link
Dion
  • 4k
  • 12
  • 42

Description

Count how many occurrences there are of the number 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 1010, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 20 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l

Description

Count how many occurrences there are of the number 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 20 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l

Description

Count how many occurrences there are of the number 1 between two given numbers \$[a, b]\$, inclusive.

For example, from 1 to 100 it should be 21:

1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31, 41, 51, 61, 71, 81, 91, 100

The number 1 is repeated 20 times.

Rules

  1. Each number in the input list is guaranteed is an integer in the range \$0 \leq a \leq b < 2^{32}\$.
  2. The shortest answer in bytes wins.

Test cases

[1, 100] -> 21
[11, 200] -> 138
[123, 678] -> 182

Example

Here is my code using bash

eval echo {$1..$2}|grep -o 1|wc -l
Loading
added 8 characters in body
Source Link
Chau Giang
  • 1.3k
  • 1
  • 11
  • 16
Loading
added 45 characters in body
Source Link
Chau Giang
  • 1.3k
  • 1
  • 11
  • 16
Loading
add codegolf
Source Link
Chau Giang
  • 1.3k
  • 1
  • 11
  • 16
Loading
Source Link
Chau Giang
  • 1.3k
  • 1
  • 11
  • 16
Loading