| Bytes | Lang | Time | Link |
|---|---|---|---|
| 045 | C gcc | 241212T235751Z | matteo_c |
| 021 | Perl 5 p | 241210T150204Z | Xcali |
| 053 | Java | 241210T154208Z | Kevin Cr |
| 016 | 05AB1E | 241210T095646Z | Kevin Cr |
| 021 | Charcoal | 241210T115752Z | Neil |
| 014 | Retina 0.8.2 | 241210T095453Z | Neil |
| 042 | JavaScript Node.js | 241210T080536Z | tsh |
Java, 57 53 bytes
s->s.replaceAll("^0\\B","-").replaceAll("^\\.","\\$")
-4 bytes thanks to @Neil.
Explanation:
s-> // Method with String as both parameter and return-type
s.replaceAll("^0 // Replace a leading "0",
\\B", // which has a (zero-width) digit after it
"-") // with "-"
.replaceAll("^\\.", // Then(/or) replace a leading "."
"\\$") // with "$"
05AB1E, 21 16 bytes
¦нdić„-$ì¤0tskèì
Try it online or verify all test cases.
Explanation:
¦ # Remove the first character of the (implicit) input
н # Pop and take the new first character (aka the second),
# or an empty string if the input was 1 character long
di # Pop, and if this second character is a digit:
ć # Extract head; push first character and remainder-string
„-$ì # Prepend "-$" before this first character
¤ # Push the last character of this triplet (without popping),
# aka that same first character
0t # Push 0.0 (square root of 0)
s # Swap so the first character is at the top again
k # Get the 0-based index of this character in "0.0",
# or -1 if it's neither "0" nor "."
è # Use that index to index into "-$ÿ",
# where -1 indexes into this last character (`ÿ`)
ì # Prepend that to the remainder-string
# (after which it is output implicitly as result)
# (implicit else: output the implicit input as is)
Charcoal, 21 bytes
Pθ¿‹.⊟KD²→§⁺-$KK⌕0.KK
Try it online! Link is to verbose version of code. Explanation:
Pθ
Output the input string without moving the cursor.
¿‹.⊟KD²→
If the second character exists and is a digit, then...
§⁺-$KK⌕0.KK
... transliterate the character under the cursor from 0 to - or . to $ or anything else to itself.
Retina 0.8.2, 14 bytes
1T1`0.`-$`^.\d
Try it online! Link includes test cases. Explanation: Port of @tsh's JavaScript answer.
1T1`
Transliterate only the first character of the first match. (There will only be one match, but I still need to specify it so that I can only transliterate the first character.)
0.`-$`
Transliterate 0 to - and . to $.
^.\d
Match only the first two characters and only if the second is a digit. (Transliterate will ignore the first character if it's not a 0 or ..)