Post History
Article
code-golf
#7: Post edited
Display a Progress Bar
- Display a Progress Bar [FINALIZED]
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, you may round in whichever direction your language supports.
- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
- ## Now finalized: [Display a Progress Bar](https://codegolf.codidact.com/posts/292935)
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, you may round in whichever direction your language supports.
- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
#6: Post edited
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$. When rounding from half (for example, rounding $16.5$), you may do whatever the default is for your programming language.- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, you may round in whichever direction your language supports.
- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
#5: Post edited
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$. When rounding from half, you must round up, so a value of $16.5$ rounds up to $17$.- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$. When rounding from half (for example, rounding $16.5$), you may do whatever the default is for your programming language.
- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
#4: Post edited
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$.- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$. When rounding from half, you must round up, so a value of $16.5$ rounds up to $17$.
- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
#3: Post edited
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$.
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$.
- ### Scoring
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
#2: Post edited
The goal of this challenge is simple: given a ratio of whole numbers, output a 100-character long progress bar representing the ratio.- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$.
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
- The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio.
- ## Rules
- ### Input
- - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$.
- - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language.
- - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$.
- - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed.
- ### Output
- - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets.
- - The progress bar must fill from left to right.
- - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`.
- - The progress bar must be enclosed in square brackets `[]`.
- - Whitespace is fine at the end of the output, but not anywhere else.
- - When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$.
- This is a code-golf challenge, so the shortest code in bytes wins!
- ## Examples
- ### Example 1
- ```
- Input: 1/2
- Output: [|||||||||||||||||||||||||-------------------------]
- ```
- ### Example 2
- ```
- Input: 2/3
- Output: [|||||||||||||||||||||||||||||||||-----------------]
- ```
- ### Example 3
- ```
- Input: 234/300
- Output: [|||||||||||||||||||||||||||||||||||||||-----------]
- ```
- ### Example 4
- ```
- Input: 5/50
- Output: [|||||---------------------------------------------]
- ```
#1: Initial revision
Display a Progress Bar
The goal of this challenge is simple: given a ratio of whole numbers, output a 100-character long progress bar representing the ratio. ## Rules ### Input - Your program must take two numbers as input. These numbers will be the numerator and denominator of the ratio, in that order. Your program cannot take the calculated result of the ratio as input. So, an input of $1/4$ is fine, but not $0.25$. - The numbers may be entered separately, or together with a `/` as a separator, whichever works best with your chosen language. - The numerator can be any integer greater than or equal to $0$, and the denominator can be any integer greater than $0$. - The ratio cannot be greater than 1, or less than zero. So $0 \le r \le 1$ where $r$ is the ratio. Thus, ratios like $12/3$ are not allowed. ### Output - Your program must output a progress bar that is 50 characters in length, not counting the enclosing brackets. - The progress bar must fill from left to right. - The "filled" part of the progress bar must be made of pipes `|`, and the "empty" part of the progress bar must be made of dashes `-`. - The progress bar must be enclosed in square brackets `[]`. - Whitespace is fine at the end of the output, but not anywhere else. - When calculating the number of "filled" characters to output, round up or down as required by any decimal digits. So a value of $39.3$ characters must be rounded down to $39$, and a value of $23.7$ characters must be rounded up to $24$. This is a code-golf challenge, so the shortest code in bytes wins! ## Examples ### Example 1 ``` Input: 1/2 Output: [|||||||||||||||||||||||||-------------------------] ``` ### Example 2 ``` Input: 2/3 Output: [|||||||||||||||||||||||||||||||||-----------------] ``` ### Example 3 ``` Input: 234/300 Output: [|||||||||||||||||||||||||||||||||||||||-----------] ``` ### Example 4 ``` Input: 5/50 Output: [|||||---------------------------------------------] ```