| Bytes | Lang | Time | Link |
|---|---|---|---|
| 083 | Setanta | 240811T071947Z | bb94 |
| 009 | Vyxal 3 | 240811T082002Z | bb94 |
| 065 | Raku Perl 6 rakudo | 240811T080020Z | bb94 |
| 018 | 05AB1E | 240521T090045Z | Kevin Cr |
| 041 | JavaScript Node.js | 240521T005502Z | l4m2 |
| 031 | Charcoal | 240520T235644Z | Neil |
| 007 | Jelly | 240520T191228Z | Jonathan |
Setanta, 93 92 86 83 bytes
gniomh(x){t:=0f:=1nuair-a x{t=f-t-1x-=1le i idir(-1,x%10){t+=f f*=2}x//=10}toradh t}
Explanation
gniomh(x){t:=0f:=1nuair-a x{t=f-t-1x-=1le i idir(-1,x%10){t+=f f*=2}x//=10}toradh t}
t:=0 >-- Cumulative result
f:=1 >-- Next bit to set
nuair-a x{ } >-- Iterate for each digit of the bijective representation: while x > 0...
t=f-t-1 >-- Invert the existing bits of the cumulative result
x-=1 >-- Subtract x by 1
le i idir(-1,x%10){ } >-- Do the following x % 10 + 1 times:
t+=f >-- Set next bit of result
f*=2 >-- Update next bit
x//=10 >-- Divide x by 10
toradh t >-- Return the result
💎
Created with the help of Luminespire.
Raku (Perl 6) (rakudo), 65 bytes
{:2(.&(my&g={$_??g(+^-$_ div 10)~($!+^=1)x+^-$_%10+1!!~($!=0)}))}
05AB1E, 21 18 bytes
[D_#<T‰`ˆ}TÞ¯R>×JC
Port of @Neil's Charcoal answer, so make sure to upvote that answer as well!
-3 bytes thanks to @Neil
For a language that's literally called 'Base' (when interpret as hexadecimal and converted to base-64), its lack of a bijective-base builtin is a bit disappointing for this challenge.. So things are done manually using the same approach as the Charcoal answer.
Try it online or verify all test cases.
Explanation:
[ # Start an infinite loop:
D # Duplicate the current integer
# (which will use the implicit input-integer in the first iteration)
_ # Pop the copy, and check whether it's 0
# # Pop and if it's 0: stop the infinite loop
< # Decrease the integer by 1
T‰ # Divmod by 10: [n//10,n%10]
` # Pop and push both values separated to the stack
ˆ # Pop the top n%10 and add it to the global array
}T # After the infinite loop: push 10
Þ # Convert it to an infinitely cycling digit-list: [1,0,1,0,1,0,...]
¯ # Push the global array
R # Reverse it
> # Increase each inner digit by 1
× # Repeat the [1,0,1,0,1,0,...] those amount of times
J # Join it together
C # Convert it from a binary-string to a base-10 integer
# (which is output implicitly as result)
Charcoal, 31 bytes
NθWθ«⊞υ∨﹪θχχ≔÷⊖θχθ»I⍘⭆⮌υ×§10κι²
Try it online! Link is to verbose version of code. Explanation:
NθWθ«⊞υ∨﹪θχχ≔÷⊖θχθ»
Input the number and convert it to little-endian bijective base 10.
I⍘⭆⮌υ×§10κι²
Create a string alternating between 1s and 0s and convert that from base 2 to decimal.
Jelly, 7 bytes
ḃ⁵Jx$ḂḄ
A monadic Link that accepts a non-negative integer and yields a non-negative integer.
Try it online! Or see the test-suite.
How?
ḃ⁵Jx$ḂḄ - Link: non-negative integer, N
⁵ - ten
ḃ - convert {N} to bijective base {ten}
$ - last two links as a monad - f(B=that):
J - indices {B} -> [1,2,...,#digits]
x - {B} times {that} -> [1,1,...,2,2,...,3,3,...,...]
Ḃ - least significant bit -> [1,1,...,0,0,...,1,1,...,...]
Ḅ - convert {that} from binary