Decimal Digit Truncating
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Input:
A decimal
Output:
The input truncated
How to truncate them?
The integer part of the input will remain the same. The decimal part of the input will be truncated based on the lowest digit in consecutive order. The two step-by-step examples below should clarify what I mean by that:
Example 1: Input: 17.46940822
Step 1: Leave the integer part unchanged: 17
Step 2: Look at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4694
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 6
→ remains .4694
Step 3 again: 9
→ remains .4694
Step 3 again: 4
→ remains .4694
So the output will be: 17.4694
.
Example 2: Input: 10.4521084
Step 1: Leave the integer part unchanged: 10
Step 2: Loop at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4521
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 5
→ remains .4521
Step 3 again: 2
→ truncation adjusted to: .45
So the output will be: 10.45
Challenge rules:
- You are allowed to take the input as decimal, string, list/array/stream of characters, etc. (Same applies to the output, although I doubt there are a lot of languages that have the proper truncation while remain working with decimal values.)
You are also allowed to use a comma,
instead of a dot.
(perhaps useful for regex-based solution/languages). - If the decimal part is not long enough for the truncation, you are optionally allowed to add trailing zeros. I.e.
123.4
can be both123.4
or123.4000
- If you have to truncate to
0
decimal digits we omit the decimal digits. The dot/comma may remain optionally if you use strings. I.e.847.3072
→847
(or847.
) - You can assume the input will always contain at least one decimal digit, so
123
won't be an input, but123.0
can be an input.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: Output:
17.46940822 17.4694
10.4521084 10.45
123.4 123.4000 (or 123.4)
-847.3072 -847 (or -847.)
123.0 123 (or 123.)
98.76543210 98.7654
0.3165 0.3
-0.1365 -0.1
82937.82937 82937.82
-0.1010101 -0.1
-1.0101010 -1 (or -1.)
28.684297 28.68
13.35 13.350 (or 13.35)
code-golf number floating-point
add a comment |Â
up vote
1
down vote
favorite
Input:
A decimal
Output:
The input truncated
How to truncate them?
The integer part of the input will remain the same. The decimal part of the input will be truncated based on the lowest digit in consecutive order. The two step-by-step examples below should clarify what I mean by that:
Example 1: Input: 17.46940822
Step 1: Leave the integer part unchanged: 17
Step 2: Look at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4694
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 6
→ remains .4694
Step 3 again: 9
→ remains .4694
Step 3 again: 4
→ remains .4694
So the output will be: 17.4694
.
Example 2: Input: 10.4521084
Step 1: Leave the integer part unchanged: 10
Step 2: Loop at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4521
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 5
→ remains .4521
Step 3 again: 2
→ truncation adjusted to: .45
So the output will be: 10.45
Challenge rules:
- You are allowed to take the input as decimal, string, list/array/stream of characters, etc. (Same applies to the output, although I doubt there are a lot of languages that have the proper truncation while remain working with decimal values.)
You are also allowed to use a comma,
instead of a dot.
(perhaps useful for regex-based solution/languages). - If the decimal part is not long enough for the truncation, you are optionally allowed to add trailing zeros. I.e.
123.4
can be both123.4
or123.4000
- If you have to truncate to
0
decimal digits we omit the decimal digits. The dot/comma may remain optionally if you use strings. I.e.847.3072
→847
(or847.
) - You can assume the input will always contain at least one decimal digit, so
123
won't be an input, but123.0
can be an input.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: Output:
17.46940822 17.4694
10.4521084 10.45
123.4 123.4000 (or 123.4)
-847.3072 -847 (or -847.)
123.0 123 (or 123.)
98.76543210 98.7654
0.3165 0.3
-0.1365 -0.1
82937.82937 82937.82
-0.1010101 -0.1
-1.0101010 -1 (or -1.)
28.684297 28.68
13.35 13.350 (or 13.35)
code-golf number floating-point
Need we output string?
– l4m2
2 hours ago
@l4m2 No, you are also allowed to output it as a decimal, or list of characters. Although I don't know a lot of languages that can do the proper truncation without converting to string format.
– Kevin Cruijssen
2 hours ago
So it's fine to remove ending zero if outputing float?
– l4m2
2 hours ago
@l4m2 Sure. I've updated the rules to also allow no additional trailing zeros.
– Kevin Cruijssen
2 hours ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Input:
A decimal
Output:
The input truncated
How to truncate them?
The integer part of the input will remain the same. The decimal part of the input will be truncated based on the lowest digit in consecutive order. The two step-by-step examples below should clarify what I mean by that:
Example 1: Input: 17.46940822
Step 1: Leave the integer part unchanged: 17
Step 2: Look at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4694
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 6
→ remains .4694
Step 3 again: 9
→ remains .4694
Step 3 again: 4
→ remains .4694
So the output will be: 17.4694
.
Example 2: Input: 10.4521084
Step 1: Leave the integer part unchanged: 10
Step 2: Loop at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4521
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 5
→ remains .4521
Step 3 again: 2
→ truncation adjusted to: .45
So the output will be: 10.45
Challenge rules:
- You are allowed to take the input as decimal, string, list/array/stream of characters, etc. (Same applies to the output, although I doubt there are a lot of languages that have the proper truncation while remain working with decimal values.)
You are also allowed to use a comma,
instead of a dot.
(perhaps useful for regex-based solution/languages). - If the decimal part is not long enough for the truncation, you are optionally allowed to add trailing zeros. I.e.
123.4
can be both123.4
or123.4000
- If you have to truncate to
0
decimal digits we omit the decimal digits. The dot/comma may remain optionally if you use strings. I.e.847.3072
→847
(or847.
) - You can assume the input will always contain at least one decimal digit, so
123
won't be an input, but123.0
can be an input.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: Output:
17.46940822 17.4694
10.4521084 10.45
123.4 123.4000 (or 123.4)
-847.3072 -847 (or -847.)
123.0 123 (or 123.)
98.76543210 98.7654
0.3165 0.3
-0.1365 -0.1
82937.82937 82937.82
-0.1010101 -0.1
-1.0101010 -1 (or -1.)
28.684297 28.68
13.35 13.350 (or 13.35)
code-golf number floating-point
Input:
A decimal
Output:
The input truncated
How to truncate them?
The integer part of the input will remain the same. The decimal part of the input will be truncated based on the lowest digit in consecutive order. The two step-by-step examples below should clarify what I mean by that:
Example 1: Input: 17.46940822
Step 1: Leave the integer part unchanged: 17
Step 2: Look at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4694
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 6
→ remains .4694
Step 3 again: 9
→ remains .4694
Step 3 again: 4
→ remains .4694
So the output will be: 17.4694
.
Example 2: Input: 10.4521084
Step 1: Leave the integer part unchanged: 10
Step 2: Loop at the first decimal digit, and truncate it to that many decimal digits: 4
→ .4521
Step 3: Look at the next decimal digit. If it's lower, adjust the truncation accordingly. If not, continue to the next decimal digit: 5
→ remains .4521
Step 3 again: 2
→ truncation adjusted to: .45
So the output will be: 10.45
Challenge rules:
- You are allowed to take the input as decimal, string, list/array/stream of characters, etc. (Same applies to the output, although I doubt there are a lot of languages that have the proper truncation while remain working with decimal values.)
You are also allowed to use a comma,
instead of a dot.
(perhaps useful for regex-based solution/languages). - If the decimal part is not long enough for the truncation, you are optionally allowed to add trailing zeros. I.e.
123.4
can be both123.4
or123.4000
- If you have to truncate to
0
decimal digits we omit the decimal digits. The dot/comma may remain optionally if you use strings. I.e.847.3072
→847
(or847.
) - You can assume the input will always contain at least one decimal digit, so
123
won't be an input, but123.0
can be an input.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: Output:
17.46940822 17.4694
10.4521084 10.45
123.4 123.4000 (or 123.4)
-847.3072 -847 (or -847.)
123.0 123 (or 123.)
98.76543210 98.7654
0.3165 0.3
-0.1365 -0.1
82937.82937 82937.82
-0.1010101 -0.1
-1.0101010 -1 (or -1.)
28.684297 28.68
13.35 13.350 (or 13.35)
code-golf number floating-point
code-golf number floating-point
edited 2 hours ago
asked 2 hours ago


Kevin Cruijssen
32.6k554176
32.6k554176
Need we output string?
– l4m2
2 hours ago
@l4m2 No, you are also allowed to output it as a decimal, or list of characters. Although I don't know a lot of languages that can do the proper truncation without converting to string format.
– Kevin Cruijssen
2 hours ago
So it's fine to remove ending zero if outputing float?
– l4m2
2 hours ago
@l4m2 Sure. I've updated the rules to also allow no additional trailing zeros.
– Kevin Cruijssen
2 hours ago
add a comment |Â
Need we output string?
– l4m2
2 hours ago
@l4m2 No, you are also allowed to output it as a decimal, or list of characters. Although I don't know a lot of languages that can do the proper truncation without converting to string format.
– Kevin Cruijssen
2 hours ago
So it's fine to remove ending zero if outputing float?
– l4m2
2 hours ago
@l4m2 Sure. I've updated the rules to also allow no additional trailing zeros.
– Kevin Cruijssen
2 hours ago
Need we output string?
– l4m2
2 hours ago
Need we output string?
– l4m2
2 hours ago
@l4m2 No, you are also allowed to output it as a decimal, or list of characters. Although I don't know a lot of languages that can do the proper truncation without converting to string format.
– Kevin Cruijssen
2 hours ago
@l4m2 No, you are also allowed to output it as a decimal, or list of characters. Although I don't know a lot of languages that can do the proper truncation without converting to string format.
– Kevin Cruijssen
2 hours ago
So it's fine to remove ending zero if outputing float?
– l4m2
2 hours ago
So it's fine to remove ending zero if outputing float?
– l4m2
2 hours ago
@l4m2 Sure. I've updated the rules to also allow no additional trailing zeros.
– Kevin Cruijssen
2 hours ago
@l4m2 Sure. I've updated the rules to also allow no additional trailing zeros.
– Kevin Cruijssen
2 hours ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
1
down vote
Python 2, 103 bytes
def f(n):
a=n.find('.');i,w=1,9
while i<=w and a+i<len(n):w=min(int(n[a+i]),w);i+=1
return n[:a+w+1]
Try it online!
a+w+1
can bea-~w
. Nice answer though, +1 from me.
– Kevin Cruijssen
1 hour ago
1
Oh, andreturn
can beprint
as well. And here you are golfing Python for years. Tsk tsk tsk. ;p (It's the simplest things we usually forgot to golf I guess.)
– Kevin Cruijssen
1 hour ago
Instead of a function, use n=input() and remove the spaces and print as mentioned by @KevinCruijssen to save a few bytes.
– Vedant Kandoi
1 hour ago
add a comment |Â
up vote
1
down vote
Charcoal, 28 bytes
≔⪪S.θW⊟EθΦκ‹IμLκ⊞θ…⊟θI§ιâ°⪫θ.
Try it online! Link is to verbose version of code. Explanation:
≔⪪S.θ
Split the input on .
.
W⊟EθΦκ‹IμLκ
Filter each part on those digits that are less than the string's length. Then take the last result. (This saves 1 byte over filtering on just the decimals.) Loop until that is empty.
⊞θ…⊟θI§ιâ°
Take the first filtered digit and truncate the decimals to that length.
⪫θ.
Join the parts back together and implicitly print.
Seems to give an incorrect result for the negative input-cases (although it is possible I don't know how to input negative values in Charcoal, I tried with a leading-
or_
, but both failed). Everything else works fine.
– Kevin Cruijssen
31 mins ago
add a comment |Â
up vote
1
down vote
05AB1E, 20 bytes
4 bytes extra due to a bug with £
not handling 0 correctly.
'.¡`DvÃÂgsNè-F¨]'.ý0Ü
Try it online!
or as a Test Suite
Where is the0Ü
used for? It seems to give the same results without removing trailing zeros. Did you try a test case I should add to the challenge description for which the0Ü
is required?
– Kevin Cruijssen
26 mins ago
add a comment |Â
up vote
0
down vote
C (gcc), 84 bytes
Takes input as a pointer to a string buffer, outputs by modification. Note that providing a pointer to a buffer that is too small (intPartLen + 1 + 9 > bufSize
) can cause SEGFAULT
.
If assuming the size of the buffer to be sufficient is not allowed, +7 to the score.
l,m,M;f(char*F)F=strchr(F,46);M=10;for(l=0;F[++l]&&l<M;m<M?M=m:0)m=F[l]-47;F[M]=0;
Degolf
l,m,M;f(char*F)
F=strchr(F,46); // Find the pointer to the period
M=10;for(l=0; // Initialize variables for the loop.
F[++l]&&l<M; // Check for null terminator, increment length, and check
// that we're not checking beyond limits of the recursion.
m<M?M=m:0) // Keep smaller of M and m
m=F[l]-47; // Read the character from F, deduct 47 to map 0->1, 9->10
F[M]=0; // Put a null terminator at the index M.
Try it online!
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Python 2, 103 bytes
def f(n):
a=n.find('.');i,w=1,9
while i<=w and a+i<len(n):w=min(int(n[a+i]),w);i+=1
return n[:a+w+1]
Try it online!
a+w+1
can bea-~w
. Nice answer though, +1 from me.
– Kevin Cruijssen
1 hour ago
1
Oh, andreturn
can beprint
as well. And here you are golfing Python for years. Tsk tsk tsk. ;p (It's the simplest things we usually forgot to golf I guess.)
– Kevin Cruijssen
1 hour ago
Instead of a function, use n=input() and remove the spaces and print as mentioned by @KevinCruijssen to save a few bytes.
– Vedant Kandoi
1 hour ago
add a comment |Â
up vote
1
down vote
Python 2, 103 bytes
def f(n):
a=n.find('.');i,w=1,9
while i<=w and a+i<len(n):w=min(int(n[a+i]),w);i+=1
return n[:a+w+1]
Try it online!
a+w+1
can bea-~w
. Nice answer though, +1 from me.
– Kevin Cruijssen
1 hour ago
1
Oh, andreturn
can beprint
as well. And here you are golfing Python for years. Tsk tsk tsk. ;p (It's the simplest things we usually forgot to golf I guess.)
– Kevin Cruijssen
1 hour ago
Instead of a function, use n=input() and remove the spaces and print as mentioned by @KevinCruijssen to save a few bytes.
– Vedant Kandoi
1 hour ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 2, 103 bytes
def f(n):
a=n.find('.');i,w=1,9
while i<=w and a+i<len(n):w=min(int(n[a+i]),w);i+=1
return n[:a+w+1]
Try it online!
Python 2, 103 bytes
def f(n):
a=n.find('.');i,w=1,9
while i<=w and a+i<len(n):w=min(int(n[a+i]),w);i+=1
return n[:a+w+1]
Try it online!
answered 2 hours ago


TFeld
12.7k2836
12.7k2836
a+w+1
can bea-~w
. Nice answer though, +1 from me.
– Kevin Cruijssen
1 hour ago
1
Oh, andreturn
can beprint
as well. And here you are golfing Python for years. Tsk tsk tsk. ;p (It's the simplest things we usually forgot to golf I guess.)
– Kevin Cruijssen
1 hour ago
Instead of a function, use n=input() and remove the spaces and print as mentioned by @KevinCruijssen to save a few bytes.
– Vedant Kandoi
1 hour ago
add a comment |Â
a+w+1
can bea-~w
. Nice answer though, +1 from me.
– Kevin Cruijssen
1 hour ago
1
Oh, andreturn
can beprint
as well. And here you are golfing Python for years. Tsk tsk tsk. ;p (It's the simplest things we usually forgot to golf I guess.)
– Kevin Cruijssen
1 hour ago
Instead of a function, use n=input() and remove the spaces and print as mentioned by @KevinCruijssen to save a few bytes.
– Vedant Kandoi
1 hour ago
a+w+1
can be a-~w
. Nice answer though, +1 from me.– Kevin Cruijssen
1 hour ago
a+w+1
can be a-~w
. Nice answer though, +1 from me.– Kevin Cruijssen
1 hour ago
1
1
Oh, and
return
can be print
as well. And here you are golfing Python for years. Tsk tsk tsk. ;p (It's the simplest things we usually forgot to golf I guess.)– Kevin Cruijssen
1 hour ago
Oh, and
return
can be print
as well. And here you are golfing Python for years. Tsk tsk tsk. ;p (It's the simplest things we usually forgot to golf I guess.)– Kevin Cruijssen
1 hour ago
Instead of a function, use n=input() and remove the spaces and print as mentioned by @KevinCruijssen to save a few bytes.
– Vedant Kandoi
1 hour ago
Instead of a function, use n=input() and remove the spaces and print as mentioned by @KevinCruijssen to save a few bytes.
– Vedant Kandoi
1 hour ago
add a comment |Â
up vote
1
down vote
Charcoal, 28 bytes
≔⪪S.θW⊟EθΦκ‹IμLκ⊞θ…⊟θI§ιâ°⪫θ.
Try it online! Link is to verbose version of code. Explanation:
≔⪪S.θ
Split the input on .
.
W⊟EθΦκ‹IμLκ
Filter each part on those digits that are less than the string's length. Then take the last result. (This saves 1 byte over filtering on just the decimals.) Loop until that is empty.
⊞θ…⊟θI§ιâ°
Take the first filtered digit and truncate the decimals to that length.
⪫θ.
Join the parts back together and implicitly print.
Seems to give an incorrect result for the negative input-cases (although it is possible I don't know how to input negative values in Charcoal, I tried with a leading-
or_
, but both failed). Everything else works fine.
– Kevin Cruijssen
31 mins ago
add a comment |Â
up vote
1
down vote
Charcoal, 28 bytes
≔⪪S.θW⊟EθΦκ‹IμLκ⊞θ…⊟θI§ιâ°⪫θ.
Try it online! Link is to verbose version of code. Explanation:
≔⪪S.θ
Split the input on .
.
W⊟EθΦκ‹IμLκ
Filter each part on those digits that are less than the string's length. Then take the last result. (This saves 1 byte over filtering on just the decimals.) Loop until that is empty.
⊞θ…⊟θI§ιâ°
Take the first filtered digit and truncate the decimals to that length.
⪫θ.
Join the parts back together and implicitly print.
Seems to give an incorrect result for the negative input-cases (although it is possible I don't know how to input negative values in Charcoal, I tried with a leading-
or_
, but both failed). Everything else works fine.
– Kevin Cruijssen
31 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Charcoal, 28 bytes
≔⪪S.θW⊟EθΦκ‹IμLκ⊞θ…⊟θI§ιâ°⪫θ.
Try it online! Link is to verbose version of code. Explanation:
≔⪪S.θ
Split the input on .
.
W⊟EθΦκ‹IμLκ
Filter each part on those digits that are less than the string's length. Then take the last result. (This saves 1 byte over filtering on just the decimals.) Loop until that is empty.
⊞θ…⊟θI§ιâ°
Take the first filtered digit and truncate the decimals to that length.
⪫θ.
Join the parts back together and implicitly print.
Charcoal, 28 bytes
≔⪪S.θW⊟EθΦκ‹IμLκ⊞θ…⊟θI§ιâ°⪫θ.
Try it online! Link is to verbose version of code. Explanation:
≔⪪S.θ
Split the input on .
.
W⊟EθΦκ‹IμLκ
Filter each part on those digits that are less than the string's length. Then take the last result. (This saves 1 byte over filtering on just the decimals.) Loop until that is empty.
⊞θ…⊟θI§ιâ°
Take the first filtered digit and truncate the decimals to that length.
⪫θ.
Join the parts back together and implicitly print.
answered 36 mins ago
Neil
77.1k744174
77.1k744174
Seems to give an incorrect result for the negative input-cases (although it is possible I don't know how to input negative values in Charcoal, I tried with a leading-
or_
, but both failed). Everything else works fine.
– Kevin Cruijssen
31 mins ago
add a comment |Â
Seems to give an incorrect result for the negative input-cases (although it is possible I don't know how to input negative values in Charcoal, I tried with a leading-
or_
, but both failed). Everything else works fine.
– Kevin Cruijssen
31 mins ago
Seems to give an incorrect result for the negative input-cases (although it is possible I don't know how to input negative values in Charcoal, I tried with a leading
-
or _
, but both failed). Everything else works fine.– Kevin Cruijssen
31 mins ago
Seems to give an incorrect result for the negative input-cases (although it is possible I don't know how to input negative values in Charcoal, I tried with a leading
-
or _
, but both failed). Everything else works fine.– Kevin Cruijssen
31 mins ago
add a comment |Â
up vote
1
down vote
05AB1E, 20 bytes
4 bytes extra due to a bug with £
not handling 0 correctly.
'.¡`DvÃÂgsNè-F¨]'.ý0Ü
Try it online!
or as a Test Suite
Where is the0Ü
used for? It seems to give the same results without removing trailing zeros. Did you try a test case I should add to the challenge description for which the0Ü
is required?
– Kevin Cruijssen
26 mins ago
add a comment |Â
up vote
1
down vote
05AB1E, 20 bytes
4 bytes extra due to a bug with £
not handling 0 correctly.
'.¡`DvÃÂgsNè-F¨]'.ý0Ü
Try it online!
or as a Test Suite
Where is the0Ü
used for? It seems to give the same results without removing trailing zeros. Did you try a test case I should add to the challenge description for which the0Ü
is required?
– Kevin Cruijssen
26 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
05AB1E, 20 bytes
4 bytes extra due to a bug with £
not handling 0 correctly.
'.¡`DvÃÂgsNè-F¨]'.ý0Ü
Try it online!
or as a Test Suite
05AB1E, 20 bytes
4 bytes extra due to a bug with £
not handling 0 correctly.
'.¡`DvÃÂgsNè-F¨]'.ý0Ü
Try it online!
or as a Test Suite
answered 29 mins ago


Emigna
44.1k431133
44.1k431133
Where is the0Ü
used for? It seems to give the same results without removing trailing zeros. Did you try a test case I should add to the challenge description for which the0Ü
is required?
– Kevin Cruijssen
26 mins ago
add a comment |Â
Where is the0Ü
used for? It seems to give the same results without removing trailing zeros. Did you try a test case I should add to the challenge description for which the0Ü
is required?
– Kevin Cruijssen
26 mins ago
Where is the
0Ü
used for? It seems to give the same results without removing trailing zeros. Did you try a test case I should add to the challenge description for which the 0Ü
is required?– Kevin Cruijssen
26 mins ago
Where is the
0Ü
used for? It seems to give the same results without removing trailing zeros. Did you try a test case I should add to the challenge description for which the 0Ü
is required?– Kevin Cruijssen
26 mins ago
add a comment |Â
up vote
0
down vote
C (gcc), 84 bytes
Takes input as a pointer to a string buffer, outputs by modification. Note that providing a pointer to a buffer that is too small (intPartLen + 1 + 9 > bufSize
) can cause SEGFAULT
.
If assuming the size of the buffer to be sufficient is not allowed, +7 to the score.
l,m,M;f(char*F)F=strchr(F,46);M=10;for(l=0;F[++l]&&l<M;m<M?M=m:0)m=F[l]-47;F[M]=0;
Degolf
l,m,M;f(char*F)
F=strchr(F,46); // Find the pointer to the period
M=10;for(l=0; // Initialize variables for the loop.
F[++l]&&l<M; // Check for null terminator, increment length, and check
// that we're not checking beyond limits of the recursion.
m<M?M=m:0) // Keep smaller of M and m
m=F[l]-47; // Read the character from F, deduct 47 to map 0->1, 9->10
F[M]=0; // Put a null terminator at the index M.
Try it online!
add a comment |Â
up vote
0
down vote
C (gcc), 84 bytes
Takes input as a pointer to a string buffer, outputs by modification. Note that providing a pointer to a buffer that is too small (intPartLen + 1 + 9 > bufSize
) can cause SEGFAULT
.
If assuming the size of the buffer to be sufficient is not allowed, +7 to the score.
l,m,M;f(char*F)F=strchr(F,46);M=10;for(l=0;F[++l]&&l<M;m<M?M=m:0)m=F[l]-47;F[M]=0;
Degolf
l,m,M;f(char*F)
F=strchr(F,46); // Find the pointer to the period
M=10;for(l=0; // Initialize variables for the loop.
F[++l]&&l<M; // Check for null terminator, increment length, and check
// that we're not checking beyond limits of the recursion.
m<M?M=m:0) // Keep smaller of M and m
m=F[l]-47; // Read the character from F, deduct 47 to map 0->1, 9->10
F[M]=0; // Put a null terminator at the index M.
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
C (gcc), 84 bytes
Takes input as a pointer to a string buffer, outputs by modification. Note that providing a pointer to a buffer that is too small (intPartLen + 1 + 9 > bufSize
) can cause SEGFAULT
.
If assuming the size of the buffer to be sufficient is not allowed, +7 to the score.
l,m,M;f(char*F)F=strchr(F,46);M=10;for(l=0;F[++l]&&l<M;m<M?M=m:0)m=F[l]-47;F[M]=0;
Degolf
l,m,M;f(char*F)
F=strchr(F,46); // Find the pointer to the period
M=10;for(l=0; // Initialize variables for the loop.
F[++l]&&l<M; // Check for null terminator, increment length, and check
// that we're not checking beyond limits of the recursion.
m<M?M=m:0) // Keep smaller of M and m
m=F[l]-47; // Read the character from F, deduct 47 to map 0->1, 9->10
F[M]=0; // Put a null terminator at the index M.
Try it online!
C (gcc), 84 bytes
Takes input as a pointer to a string buffer, outputs by modification. Note that providing a pointer to a buffer that is too small (intPartLen + 1 + 9 > bufSize
) can cause SEGFAULT
.
If assuming the size of the buffer to be sufficient is not allowed, +7 to the score.
l,m,M;f(char*F)F=strchr(F,46);M=10;for(l=0;F[++l]&&l<M;m<M?M=m:0)m=F[l]-47;F[M]=0;
Degolf
l,m,M;f(char*F)
F=strchr(F,46); // Find the pointer to the period
M=10;for(l=0; // Initialize variables for the loop.
F[++l]&&l<M; // Check for null terminator, increment length, and check
// that we're not checking beyond limits of the recursion.
m<M?M=m:0) // Keep smaller of M and m
m=F[l]-47; // Read the character from F, deduct 47 to map 0->1, 9->10
F[M]=0; // Put a null terminator at the index M.
Try it online!
answered 1 min ago
Rogem
61910
61910
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174946%2fdecimal-digit-truncating%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Need we output string?
– l4m2
2 hours ago
@l4m2 No, you are also allowed to output it as a decimal, or list of characters. Although I don't know a lot of languages that can do the proper truncation without converting to string format.
– Kevin Cruijssen
2 hours ago
So it's fine to remove ending zero if outputing float?
– l4m2
2 hours ago
@l4m2 Sure. I've updated the rules to also allow no additional trailing zeros.
– Kevin Cruijssen
2 hours ago