| Bytes | Lang | Time | Link |
|---|---|---|---|
| 052 | Python | 250312T224802Z | xnor |
| 007 | Nekomata | 250313T020729Z | alephalp |
| 1961 | ☾ | 250313T205203Z | Ganer |
| 028 | x8664 machine code | 250313T173149Z | m90 |
| 036 | Ruby | 250313T073741Z | G B |
| 102 | APLNARS | 250313T073434Z | Rosario |
| 008 | Jelly | 250312T152153Z | Jonathan |
| 028 | Charcoal | 250312T225751Z | Neil |
| 010 | 05AB1E | 250312T145454Z | Kevin Cr |
| 094 | Python | 250312T202126Z | Username |
| 065 | Retina 0.8.2 | 250312T200938Z | Neil |
| 079 | R | 250312T192412Z | pajonk |
| 100 | Maple | 250312T191918Z | dharr |
| 044 | Perl 5 | 250312T162151Z | Xcali |
| 054 | JavaScript V8 | 250312T131438Z | Arnauld |
Nekomata, 7 bytes
Ňᵗ{ƂJŁ≡
Takes no input and outputs every number in the sequence A328594. You can use the flag -l to limit the number of outputs. For example, -l 20 will output the first 20 terms.
Ňᵗ{ƂJŁ≡
Ň Find a natural number
ᵗ{ that does not satisfy the following:
Ƃ Binary representation
J Non-deterministic split into a list of lists
Ł Check if there are more than one list
≡ Check if all lists are equal
The original answer that printed A121016 (Ňᵖ{ƂJŁ≡) was incorrect, because when a number can satisfy the condition in multiple ways, the program will output the number multiple times.I fixed this by changing ᵖ to ᵗ, and printing A328594 instead.
☾, 19 chars (61 bytes)
⋁○²ᑀ🃌¶⁺⟞ₓᚤſⴴ
Note: ☾ uses a custom font, but you can run this code in the Web UI
x86-64 machine code, 28 bytes
31 C0 FF C0 89 C2 0F BD F0 8D 4E 01 0F B3 F2 11 D2 39 D0 E0 F7 E3 EB FF CF 79 E7 C3
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes a number n in EDI and returns the 1-indexed nth properly periodic number in EAX.
In assembly:
f: xor eax, eax # Set EAX to 0. EAX will hold the number being tried.
n: inc eax # Add 1 to EAX.
mov edx, eax # Set EDX to the same number as EAX.
bsr esi, eax # Set ESI to the highest position of a 1 bit in EAX.
lea ecx, [rsi + 1] # Set RCX to 1 more than that: the number of bits.
r: btr edx, esi # Set the bit at position ESI in EDX to 0.
# Set CF to the previous value of that bit.
adc edx, edx # Add EDX+CF to EDX, reinserting the bit at the end.
cmp eax, edx # Compare EAX and EDX.
loopne r # Decrease RCX by 1, and jump back if
# it is nonzero and the comparison was not equal.
jrcxz n # Jump if RCX=0 (no equal rotation).
dec edi # Subtract 1 from EDI, counting down from the index.
jns n # Jump if the result is nonnegative.
ret # Return.
APL(NARS), 102 chars
r←f w;i;c
i←3⋄r←⍬⋄c←0
→0×⍳c≥w⋄→3×⍳∼{l←≢a←{⍵⊤⍨2⍴⍨1+⌊2⍟⍵}⍵⋄∨/{a≡⍵⌽a}¨b/⍨0=l∣⍨b←⍳l-1}i⋄c+←1⋄r,←i
i+←1⋄→2
//10+12+72+8 =102
The function f would return the array of lenght its argument, of numbers that are 'periodic'.
This function {⍵⊤⍨2⍴⍨1+⌊2⍟⍵} traslate in binary the number of its argument. The 3th line would search for each number i
in the divirsors of ≢a the one q that is true a≡q⌽a,if that number exist return 1 else return 0.
f 19
3 7 10 15 31 36 42 45 54 63 127 136 153 170 187 204 221 238 255
Jelly, 8 bytes
BṙJ$QƑƊ#
A full program that reads a positive integer, \$n\$, from stdin and prints Jelly's list representation of the first \$n\$ nonnegative integers whose binary expansion is aperiodic (A328594).
How?
BṙJ$QƑƊ# - Main Link: no arguments
# - count up from K=0 to find the first {N = stdin} K for which:
Ɗ - last three links as a monad - f(K):
B - convert {K} to binary -> B
$ - last two links as a monad - f(B):
J - indices of B -> [1..length(B)]
ṙ - rotate {B} left by {those}
Ƒ - is {that list of lists} invariant under?
Q - deduplicate
A121016, 8 bytes
BṙJṖiƲ$#
Similar to the above. Makes the non-identity rotations and checks for existence with i (first 1-indexed index, or zero) TIO
Charcoal, 34 28 bytes
MN↓Wⅉ«→≔⍘ⅈ²θ¿№✂×²θ¹±¹¦¹θ↑»Iⅈ
Try it online! Link is to verbose version of code. Outputs the 1-indexed nth term of A121016. Explanation:
MN↓Wⅉ«
Use the y-coordinate of the canvas to track how many terms have been found.
→
Increment the candidate value, using the x-coordinate of the canvas.
≔⍘ⅈ²θ
Convert it to binary.
¿№✂×²θ¹±¹¦¹θ↑
If it's properly periodic then decrement the number of remaining terms to find. Edit: Now uses @xnor's periodicity test.
»Iⅈ
Output the found term.
05AB1E, 10 bytes
∞ʒ2в.œ¨€Ëà
Outputs a lazy infinite list of A121016.
Outputting the other sequence is apparently 10 bytes as well, by porting @JonathanAllan's Jelly answer:
∞<ʒbā._DÙQ: Try it online - Outputs a lazy infinite list of A328594.[Nbā._DÙQ–: Try it online - Outputs the infinite sequence of A328594 on separated lines.
Outputting the first second on separated newlines is also possible in 10 bytes by changing the Q to Ê in the third program: [Nbā._DÙÊ–: Try it online - Outputs the infinite sequence of A121016 on separated lines.
Explanation:
∞ # Push an infinite positive list: [1,2,3,...]
ʒ # Filter it by:
2в # Convert the current integer to a binary list†
.œ # Get all partitions of this list
¨ # Remove the last partition, containing the unmodified list with 1 part
€ # Map over each other partition:
Ë # Check that all parts are the same
à # Check that this is truthy for any part by taking the maximum
# (after which the filtered infinite list is output implicitly as result)
† Note: b for a binary-string doesn't work here, since the Ë will ignore leading 0s in its comparison (e.g. "1" equals "01" in 05AB1E). This could be countered by adding a leading 1 before the Ë check (1ì€Ë), but just using a binary-list 2в instead of binary-string b is a byte shorter.
∞ # Push an infinite positive list: [1,2,3,...]
< # Decrease each by 1 to make it non-negative: [0,1,2,...]
ʒ # Filter it by:
b # Convert the current integer to a binary-string
ā # Push a list in the range [1,length] (without popping the string)
._ # Map each to the string, rotated that many times
DÙQ # Check whether all rotations are unique:
D # Duplicate the list
Ù # Uniquify the copy
Q # Check that both lists are the same
# (after which the filtered infinite list is output implicitly as result)
[ # Start an infinite loop:
N # Push the 0-based loop-index
bā._DÙQ # Same as above
– # If the result is truthy: output the loop-index with trailing newline
Python, 94 bytes
a=0
while 1:
a+=1;b=bin(a)[2:];c=len(b)
if any([c//d*b[:d]==b for d in range(1,c)]):print(a)
Prints A121016 forever
Retina 0.8.2, 65 bytes
.+
$*
{r`\b(.*)@?(#*)$
$1#$.2$*@
}`1((.+)\2+)$
$1
#
@#
+`#@
@##
#
Try it online! Link includes test cases. Outputs the 1-indexed nth term of A121016. Explanation:
.+
$*
Convert n to unary.
r`\b(.*)@?(#*)$
$1#$.2$*@
If n is positive, increment the suffix, which is a binary number represented using @ for 0 and # for 1.
1((.+)\2+)$
$1
If the suffix is periodic then decrement n.
{`
}`
Repeat until n is zero.
#
@#
+`#@
@##
#
Convert (the suffix) from binary to decimal.
R, 79 bytes
while(F<-F+1)if(grepl("^(.*)\\1+$",Reduce(paste0,F%/%2^(0:log2(F))%%2)))show(F)
Prints A121016 indefinitely.
Maple, 100 bytes
for i do`if`(nops({seq(ListTools:-Rotate((s:=convert(i,base,2)),k),k=1..(d:=nops(s)))})=d,i,NULL)od;
Outputs A328594 indefinitely.
JavaScript (V8), 54 bytes
Prints A121016 indefinitely.
for(n=1;++n;)/^(.*)\1+$/.test(n.toString(2))&&print(n)