| Bytes | Lang | Time | Link |
|---|---|---|---|
| 016 | APL Dyalog Extended | 250820T064657Z | Adá |
| 035 | Dyalog APL | 250819T023038Z | Aaron |
| 013 | Japt | 250819T092410Z | Shaggy |
| 049 | APLNARS | 250819T070909Z | Rosario |
| 020 | Pip p | 211215T210459Z | DLosc |
| 5857 | x8616 machine code | 211216T165317Z | 640KB |
| 078 | Ruby | 211217T110333Z | G B |
| 084 | Perl 5 | 211216T202802Z | Kjetil S |
| 027 | APL Dyalog Extended | 211216T080757Z | ovs |
| 090 | JavaScript SpiderMonkey | 211216T084308Z | tsh |
| 013 | 05AB1E | 211216T073300Z | Kevin Cr |
| 062 | Retina | 211215T214327Z | Neil |
| 074 | Python3 | 211215T212551Z | Ajax1234 |
| 026 | Charcoal | 211215T211326Z | Neil |
| 012 | Vyxal | 211215T204007Z | emanresu |
| 087 | Python | 211215T205713Z | pxeger |
| 088 | JavaScript ES6 | 211215T203644Z | rydwolf |
| 023 | Jelly | 211215T204303Z | hyperneu |
APL (Dyalog Extended), 16 bytes
Anonymous tacit prefix function. Takes bit vector and returns bit matrix
1↓¯2↓∘⍉∘⊤⌽…⍥⊥⍪,≤
≤ Boolean mask of elements where 0≤, i.e. all 1s
⍪, prepend a column of the argument (makes a two column matrix, right column all 1s)
……⍥⊥ inclusive range of binary-evaluations until the first of those (the second at end), from…
⌽ the reversed argument
…∘⊤ represent in binary, one number per column, then:
…∘⍉ transpose (to one number per row), then:
¯2↓ drop the last two rows
1↓ drop the first row
Dyalog APL, 41 35 chars
{(2⍴⍨≢⍵)∘⊤¨(⊢(¯1↓⌊↓⍳⍤⌈)⍥(2∘⊥)⌽)⍎¨⍵}
⍎¨⍵ # Execute each character to get bit string
( ) # Apply this train
⊢ # the input
⌽ # and the reversed input
( )⍥ # applied to this train over
(2∘⊥) # the base two decoding
⍳⍤⌈ # Indices for the max of the two numbers
⌊↓ # dropping the nunmber of the minimum between the two
¯1↓ # and dropping one more off the right
¨ # For each result
( )∘⊤ # Encode with
2⍴⍨≢⍵ # a 2 for however long the input was
💎
Created with the help of Luminespire.
Japt, 13 bytes
ÍoUÔÍȤù0UÊÃÅ
ÍoUÔÍȤù0UÊÃÅ :Implicit input of binary string U
Í :Convert to decimal
UÔÍ :Reverse U & convert to decimal
o :Range [Min,Max)
È :Map
¤ : Convert to binary
ù0 : Left pad with 0 to
UÊ : Length of U
à :End map
Å :Slice of first element
APL(NARS), 49 chars
{k←≢⍵⋄0≥≢a←m∼⍨↑../m←2⊥¨⍎¨¨(⊂⍵),⊂⌽⍵:⍬⋄{(k⍴2)⊤⍵}¨a}
Input one string of binary numbers, output one list of list of binary numbers or zilde if there is no solution.
I Read the line: Assign to k the list length of chars of input. Build one array of 2 elements, the list of input and its reverse,apply execute to each to each element of that list (that convert single char in number decimal, or better binary because are '0' or '1') to each 2 elements of list result apply the conversion from base 2 to decimal, for obtain the extreme of interval, save that 2 numbers in m, build the range from m, and eliminate of that set the extremes...if the set has some element convert in binary of length k all element of the set.
test:
f←{k←≢⍵⋄0≥≢a←m∼⍨↑../m←2⊥¨⍎¨¨(⊂⍵),⊂⌽⍵:⍬⋄{(k⍴2)⊤⍵}¨a}
f'0'
┌0─┐
│ 0│
└~─┘
f'1'
┌0─┐
│ 0│
└~─┘
f'01'
┌0─┐
│ 0│
└~─┘
f'001'
┌2────────────────┐
│┌3─────┐ ┌3─────┐│
││ 0 1 0│ │ 0 1 1││
│└~─────┘ └~─────┘2
└∊────────────────┘
f'100'
┌2────────────────┐
│┌3─────┐ ┌3─────┐│
││ 0 1 1│ │ 0 1 0││
│└~─────┘ └~─────┘2
└∊────────────────┘
f'0010'
┌1─────────┐
│┌4───────┐│
││ 0 0 1 1││
│└~───────┘2
└∊─────────┘
Pip -p, 27 20 bytes
S*STB$,SNFB[Raa]+E#a
Explanation
S*STB$,SNFB[Raa]+E#a
[ ] List containing
Ra Reverse of argument
a and argument
FB Convert each from binary
+ For padding purposes, add to each:
E Two to the power of
#a length of argument
SN Sort in ascending order
$, Create a range from the first (inclusive) to
the second (exclusive)
TB Convert each to binary
S Remove first element (we want the range to be
exclusive on both ends)
S* Remove first element of each (an extra leading 1
from our padding strategy)
The program could be 14 bytes without the 0-padding requirement:
STB$,SNFB[Raa]
x86-16 machine code, 58 57 bytes
00000000: 8be9 e82a 008b da8b cdfd 4ee8 2100 3bda ...*......N.!.;.
00000010: 7602 87d3 433b da73 1f8b cd8b c303 f957 v...C;.s.......W
00000020: 4fd1 e850 b000 1430 aa58 e2f5 5feb e533 O..P...0.X.._..3
00000030: d2ac d0e8 13d2 e2f9 c3 .........
Listing:
8B E9 MOV BP, CX ; save input "Binary Pad" length to BP
E8 002A CALL BINDEC ; BX = forward input value
8B DA MOV BX, DX ; forward number in BX
8B CD MOV CX, BP ; restore input pad length
FD STD ; reverse string load/store direction
4E DEC SI ; fix offset - SI is one char off
E8 0021 CALL BINDEC ; DX = reversed input value
3B DA CMP BX, DX ; is reversed number smaller?
76 02 JBE MID_LOOP ; if not, start looping through middle numbers
87 D3 XCHG DX, BX ; otherwise swap numbers
MID_LOOP:
43 INC BX ; increment middle number
3B DA CMP BX, DX ; is less than end number?
73 1F JAE DONE ; if not, return
8B CD MOV CX, BP ; restore input pad length
8B C3 MOV AX, BX ; AX = next number
DECBIN: ; convert value in AX to string at [DI]
03 F9 ADD DI, CX ; move pointer to end of padded output buffer
57 PUSH DI ; save position for next number
4F DEC DI ; fix offset - DI is one char off
LOOP_BIT:
D1 E8 SHR AX, 1 ; CF = LSb of number
50 PUSH AX ; save number
B0 00 MOV AL, 0 ; zero AL
14 30 ADC AL, '0' ; convert CF to ASCII
AA STOSB ; write char to [DI]
58 POP AX ; restore number
E2 F5 LOOP LOOP_BIT ; loop next bit
5F POP DI ; restore next number output offset
EB E5 JMP MID_LOOP ; keep looping
BINDEC: ; convert ASCII binary string at [SI] to DX
33 D2 XOR DX, DX ; zero output value
LOOP_DEC:
AC LODSB ; load next char into AL
D0 E8 SHR AL, 1 ; CF = LSb of ASCII char
13 D2 ADC DX, DX ; shift LSb left onto result
E2 F9 LOOP LOOP_DEC ; loop until end of string
DONE:
C3 RET ; return to caller
Callable function, input binary string in [SI] length in CX, output to [DI].
No helpful built-ins in machine code... just brute force string to decimal and back stuff!
Test program output:
Ruby, 78 bytes
->s{a,b=[s.to_i(2),s.reverse.to_i(2)].sort;(a+1...b).map{|x|"%0#{s.size}b"%x}}
Perl 5, 84 bytes
sub{($_,$e,@r)=sort@_,"".reverse@_;push@r,$_ while s/01*$/$&=~y|01|10|r/e&&$_<$e;@r}
APL (Dyalog Extended), 33 29 27 bytes
(∊¨-⍤≢⍕¨⍤↑¨¯1↓1↓⊢⊤¨⍤…⍥⊥⌽)⍎¨
Explanation (slightly outdated):
⍎¨ Evaluate each character of the input to get a vector of 0's and 1's.
…⍥⊥ Inclusive range, after converting the arguments from base 2: of the the vector ⍵ and its reverse ⌽⍵.
¯1↓1↓ Make the range exclusive by dropping one value from the start and one from the end.
⊤¨ Convert all values in the exclusive range to base 2.
(-≢⍵)↑¨ Pad the binary values to the length of the input with 0's in the front.
∊¨⍕¨¨ In each binary number, convert each digit to a string, then join into a string.
JavaScript (SpiderMonkey), 90 bytes
x=>{for([x,y]=[1+x,1+[...x].reverse().join``].sort();++x<y;+t&&print(t.slice(3)))t='0b'+x}
05AB1E, 13 bytes
R‚CŸ¨¦bygjð0:
Try it online or verify all test cases.
Explanation:
R # Reverse the (implicit) input
‚ # Pair it with the (implicit) input
C # Convert both from a binary-string to an integer
Ÿ # Convert this pair to a ranged list
¨¦ # Remove the first and last items to make it an exclusive list
b # Convert each integer to a binary-string
Ig # Push the input-length
j # Pad leading spaces to each binary-string to make it that length
ð0: # Replace every space with a 0
# (after which the result is output implicitly)
Retina, 62 bytes
$
¶$^$`
O`.+
/(.+)¶\1$/^{-1`¶
¶$%`¶
)-2%T`d`10`01*$
,,-1A`
A`$
Try it online! Link includes test cases. Explanation:
$
¶$^$`
Append the reverse of the input.
O`.+
Sort in ascending order.
/(.+)¶\1$/^{
)`
Repeat until the last two lines are identical.
-1`¶
¶$%`¶
Duplicate the last but one line.
-2%T`d`10`01*$
Increment the newly duplicated line.
,,-1A`
Delete the original input.
A`$
Delete the line that duplicated the last line.
Python3, 74 bytes:
lambda x:[f"{i:b}".zfill(len(x))for i in range(int(x,2)+1,int(x[::-1],2))]
Charcoal, 26 bytes
⊞υθ⊞υ⮌θ←E…⊕⍘⌊υ²⍘⌈υ²⮌⍘ι²UB0
Try it online! Link is to verbose version of code. Outputs the values in descending order. Explanation:
⊞υθ⊞υ⮌θ
Push the input and its reverse to the predefined empty list.
←E…⊕⍘⌊υ²⍘⌈υ²⮌⍘ι²
Convert the minimum and maximum of the input and its reverse from base 2, loop over the intermediate values, convert them back to base 2, then print them in reverse order and right-justified.
UB0
Fill unprinted areas with zeros.
Vyxal, 12 bytes
ṘB$BrḢƛb?L∆Z
Try it Online! Outputs as a list of lists of bits.
ṘB # x reversed as an integer
$B # x as an integer
rḢ # Exclusive range
ƛ # Map...
b # convert to binary
∆Z # Zfill to...
?L # Input length
Python, 87 bytes
lambda s:[f"{x:b}".zfill(len(s))for x in range(*sorted([int(s,2),int(s[::-1],2)]))][1:]
Can probably be shorter, but I'm not interested in golfing it.
JavaScript (ES6), 88 bytes
x=>(f=y=>y<z[1]?[y,...f(y+1)]:[])(-~(z=["0b"+x,"0b"+[...x].reverse().join``]).sort()[0])
Jelly, 23 bytes
,UV€€Ḅr/BḊṖṭ@¹Uz0ZUṖṾ€€
Follows the input format very strictly (input as string, output as list of strings including padding zeroes).
Jelly, 8 bytes
,UḄr/ḊṖB
Using actually reasonable I/O formatting, if we accept a list of digits and output as digit lists without doing leading zeroes, this is a lot more suitable for Jelly.
