Skip to main content
Commonmark migration
Source Link

MATLAB: 70 bytes##bytes

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

UPD: well, that's embarrassing that I confused

with at least 3 significant digits

with

with 3 significant digits

Anyway, I'll leave my answer in this form because the 15 bytes Matlab solution is already given by @costrom

MATLAB: 70 bytes##

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

UPD: well, that's embarrassing that I confused

with at least 3 significant digits

with

with 3 significant digits

Anyway, I'll leave my answer in this form because the 15 bytes Matlab solution is already given by @costrom

MATLAB: 70 bytes

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

UPD: well, that's embarrassing that I confused

with at least 3 significant digits

with

with 3 significant digits

Anyway, I'll leave my answer in this form because the 15 bytes Matlab solution is already given by @costrom

added explanation
Source Link
brainkz
  • 359
  • 1
  • 5

MATLAB: 70 bytes##

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

UPD: well, that's embarrassing that I confused

with at least 3 significant digits

with

with 3 significant digits

Anyway, I'll leave my answer in this form because the 15 bytes Matlab solution is already given by @costrom

MATLAB: 70 bytes##

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

MATLAB: 70 bytes##

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

UPD: well, that's embarrassing that I confused

with at least 3 significant digits

with

with 3 significant digits

Anyway, I'll leave my answer in this form because the 15 bytes Matlab solution is already given by @costrom

added explanation
Source Link
brainkz
  • 359
  • 1
  • 5

MATLAB: 70 bytes##

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

MATLAB: 70 bytes##

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

MATLAB: 70 bytes##

@(x)num2str(arrayfun(@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x))

Test:

ans(1:10)
5.86            13.7            29.5            67.2             164             422            1120            3010            8130           22100

Explanation: There were several issues with number formatting.

Firstly, the question requires 3 sig-figs. Matlab has no built-in function for rounding by sig-figs (only by decimal places), so the following workaround was required:

floor(log10(pi*x+exp(x)))) computes the largest significant digit.

@(x)(round(pi*x+exp(x),2-floor(log10(pi*x+exp(x))))),x)) takes input x and rounds to 3 significant digits.

Another requirement was to handle multiple inputs. The above code can work only with single number. To mitigate this, we use arrayfun to evaluate the function for each vector element.

The last problem, Matlab displays the result of arrayfun with its own rounding that leads to outputs like 1.0e+04 * 0.0006 which violates the 3 sig-fig requirement. So, num2str was used to turn array into char format.

Matlab is good for numerical analysis, but, frankly, it sucks when it comes to fine number formatting

Source Link
brainkz
  • 359
  • 1
  • 5
Loading