Skip to main content
added 21 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293
;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVærO;0µ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær 

Try it online!Try it online! Or see the test-suitetest-suite.

;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVærO;0µ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær - Link: list of characters, S ;0O  - ordinal (vectorises across S) ;0 - concatenate a zero O - ordinal- (vectorises)to (zerocater ->BOTH zerofor no '0', '1', '8', or '9' AND for no '.') µ - start a new monadic link (call that X) _8 - subtract eight (vectorises across X) ¦ - sparse application... 1 - ...to: indices: one H - ...do: halve (i.e. halve first ordinal) %8 - modulo by eight (vectorises) Ị - insignificant (abs(v)<=1?) (vectorises) T - truthy indices Ḣ - head Ɗ - last three links as a monad (i.e. f(X)): <48 - less than 48? (i.e. was it a '.' in S or the added 0?) T - truthy indices Ḣ - head _ - subtract ¥ - last two links as a dyad < 0 - less than zero? (1 if so 0 otherwise) _ - subtract ɓ - start a new dyadic chain (i.e. f(S,X)) V - evaluate S as Jelly code (i.e. get S as a float) ær - round to the nearest multiple of 10^(-X) 
;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær 

Try it online! Or see the test-suite.

;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær - Link: list of characters, S ;0 - concatenate a zero O - ordinal (vectorises) (zero -> zero) µ - start a new monadic link (call that X) _8 - subtract eight (vectorises across X) ¦ - sparse application... 1 - ...to: indices: one H - ...do: halve (i.e. halve first ordinal) %8 - modulo by eight (vectorises) Ị - insignificant (abs(v)<=1?) (vectorises) T - truthy indices Ḣ - head Ɗ - last three links as a monad (i.e. f(X)): <48 - less than 48? T - truthy indices Ḣ - head _ - subtract ¥ - last two links as a dyad < 0 - less than zero? (1 if so 0 otherwise) _ - subtract ɓ - start a new dyadic chain (i.e. f(S,X)) V - evaluate S as Jelly code (i.e. get S as a float) ær - round to the nearest multiple of 10^(-X) 
O;0µ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær 

Try it online! Or see the test-suite.

O;0µ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær - Link: list of characters, S O  - ordinal (vectorises across S) ;0 - concatenate a zero - (to cater BOTH for no '0', '1', '8', or '9' AND for no '.') µ - start a new monadic link (call that X) _8 - subtract eight (vectorises across X) ¦ - sparse application... 1 - ...to: indices: one H - ...do: halve (i.e. halve first ordinal) %8 - modulo by eight (vectorises) Ị - insignificant (abs(v)<=1?) (vectorises) T - truthy indices Ḣ - head Ɗ - last three links as a monad (i.e. f(X)): <48 - less than 48? (i.e. was it a '.' in S or the added 0?) T - truthy indices Ḣ - head _ - subtract ¥ - last two links as a dyad < 0 - less than zero? (1 if so 0 otherwise) _ - subtract ɓ - start a new dyadic chain (i.e. f(S,X)) V - evaluate S as Jelly code (i.e. get S as a float) ær - round to the nearest multiple of 10^(-X) 
added 21 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Try it online! Or see the test-suite.

How

First note that the input string is made exclusively from the characters 0123456789. which have ordinals [48,49,50,51,52,53,54,55,56,57,46], which have remainders when divided by eight of [0,1,2,3,4,5,6,7,0,1,6]. The only characters which are between -1 and 1 inclusive are 0, 1, 8, and 9.

Furthermore if we subtract eight from the ordinals ([40,41,42,43,44,45,46,47,48,49,38]) the same (fairly obviously) holds. If we halve these ([20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,19]) the only characters which have remainders when divided by eight which are between -1 and 1 inclusive are 8 and 9.

;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær - Link: list of characters, S ;0 - concatenate a zero O - ordinal (vectorises) (zero -> zero) µ - start a new monadic link (call that X) _8 - subtract eight (vectorises across X) ¦ - sparse application... 1 - ...to: indices: one H - ...do: halve (i.e. halve first ordinal) %8 - modulo by eight (vectorises) Ị - insignificant (abs(v)<=1?) (vectorises) T - truthy indices Ḣ - head Ɗ - last three links as a monad (i.e. f(X)): <48 - less than 48? T - truthy indices Ḣ - head _ - subtract ¥ - last two links as a dyad < 0 - less than zero? (1 if so 0 otherwise) _ - subtract ɓ - start a new dyadic chain (i.e. f(S,X)) V - evaluate S as Jelly code (i.e. get S as a float) ær - round to the nearest multiple of 10^(-X) 

Try it online! Or see the test-suite.

How

First note that the input string is made exclusively from the characters 0123456789. which have ordinals [48,49,50,51,52,53,54,55,56,57,46], which have remainders when divided by eight of [0,1,2,3,4,5,6,7,0,1,6]. The only characters which are between -1 and 1 inclusive are 0, 1, 8, and 9.

Furthermore if we subtract eight from the ordinals ([40,41,42,43,44,45,46,47,48,49,38]) the same (fairly obviously) holds. If we halve these ([20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,19]) the only characters which have remainders when divided by eight which are between -1 and 1 inclusive are 8 and 9.

;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær - Link: list of characters, S ;0 - concatenate a zero O - ordinal (vectorises) (zero -> zero) µ - start a new monadic link (call that X) _8 - subtract eight (vectorises across X) ¦ - sparse application... 1 - ...to: indices: one H - ...do: halve (i.e. halve first ordinal) %8 - modulo by eight (vectorises) Ị - insignificant (abs(v)<=1?) (vectorises) T - truthy indices Ḣ - head Ɗ - last three links as a monad (i.e. f(X)): <48 - less than 48? T - truthy indices Ḣ - head _ - subtract ¥ - last two links as a dyad < 0 - less than zero? (1 if so 0 otherwise) _ - subtract ɓ - start a new dyadic chain (i.e. f(S,X)) V - evaluate S as Jelly code (i.e. get S as a float) ær - round to the nearest multiple of 10^(-X) 
added 21 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 30 30  29 bytes

-1 thanks to Erik the Outgolfer (use of dyadic quick ¥ from his answer)

;0Oµ_8H1¦%8ỊTḢ_<48TḢƊµ_>0$ɓVær;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær 

A monadic link accepting a list of characters which yields a float.

Try it online!Try it online!

Jelly, 30 bytes

;0Oµ_8H1¦%8ỊTḢ_<48TḢƊµ_>0$ɓVær 

A monadic link accepting a list of characters which yields a float.

Try it online!

Jelly,  30  29 bytes

-1 thanks to Erik the Outgolfer (use of dyadic quick ¥ from his answer)

;0Oµ_8H1¦%8ỊTḢ_<48TḢƊ_>¥0ɓVær 

A monadic link accepting a list of characters which yields a float.

Try it online!

Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293
Loading