Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#TI-BASIC, (削除) 106 (削除ここまで)(削除) 94 (削除ここまで)(削除) 87 (削除ここまで)(削除) 86 (削除ここまで) 87 bytes

TI-BASIC, (削除) 106 (削除ここまで)(削除) 94 (削除ここまで)(削除) 87 (削除ここまで)(削除) 86 (削除ここまで) 87 bytes

#TI-BASIC, (削除) 106 (削除ここまで)(削除) 94 (削除ここまで)(削除) 87 (削除ここまで)(削除) 86 (削除ここまで) 87 bytes

TI-BASIC, (削除) 106 (削除ここまで)(削除) 94 (削除ここまで)(削除) 87 (削除ここまで)(削除) 86 (削除ここまで) 87 bytes

added 359 characters in body
Source Link
lirtosiast
  • 21.6k
  • 5
  • 53
  • 127

This program uses a special propertyTI-BASIC doesn't have an increment operator, right? Well, it sort of thedoes. The equation variable u, normally used with sequences, has an obscure feature: when u is called with an argument, the variable n is set to one greater than that argument. The conditional increment depends on this. (I've been waiting to use it for a long time.)

For list indexing to work properly, n must be its default value of 0, and nMin should be its default 1, so either clear your calculator's RAM or set those values manually before running this.

Ans and Ans≠2+seq(u(n-(Ans(X)≠2)+dim(∟B)),X,1,dim(Ans
Ans and ;set 0s to 0
Ans≠ ;set to 0 all sums that equal...
2+seq2+
 seq(...,X,1,dim(Ans ;execute for each element of the list
u( u( ;return this element in list of bits (looping) 
 n n  ;current location in the list
 -(Ans(X)≠2)+ ;subtract 1 if the element isn't 2
 dim(∟B) 2dim(∟B) ;Add twice the dimension of the list
 ;(because n<nMin on the first iteration, it's out of the domain;domain
 this ;this prevents thean error)
 ) ;set n to one greater than that value
 ;i.e. increment if element≠2
 ;Will equal Ans(X) iff Ans(X)=2 and the bit read false
Result of above line
n \ u | 0 | 1
0 0 0

This program uses a special property of the equation variable u: when u is called with an argument, the variable n is set to one greater than that argument. The conditional increment depends on this. For list indexing to work properly, n must be its default value of 0, and nMin should be its default 1, so either clear your calculator's RAM or set those values manually before running this.

Ans and Ans≠2+seq(u(n-(Ans(X)≠2)+dim(∟B)),X,1,dim(Ans
Ans and ;set 0s to 0
Ans≠ ;set to 0 all sums that equal...
2+seq(...,X,1,dim(Ans ;execute for each element of the list
u( ;return this element in list of bits (looping) 
 n ;current location in the list
 -(Ans(X)≠2)+ ;subtract 1 if the element isn't 2
 dim(∟B) ;Add twice the dimension of the list
 ;(because n<nMin on the first iteration, it's out of the domain; this prevents the error
 ) ;set n to one greater than that value

TI-BASIC doesn't have an increment operator, right? Well, it sort of does. The equation variable u, normally used with sequences, has an obscure feature: when u is called with an argument, the variable n is set to one greater than that argument. The conditional increment depends on this. (I've been waiting to use it for a long time.)

For list indexing to work properly, n must be its default value of 0, and nMin should be its default 1, so either clear your calculator's RAM or set those values manually before running this.

Ans and Ans≠2+seq(u(n-(Ans(X)≠2)+dim(∟B)),X,1,dim(Ans
Ans and ;set 0s to 0
Ans≠ ;set to 0 all sums that equal...
2+
 seq(...,X,1,dim(Ans ;execute for each element of the list
 u( ;return this element in list of bits (looping) 
 n  ;current location in the list
 -(Ans(X)≠2)+ ;subtract 1 if the element isn't 2
 2dim(∟B) ;Add twice the dimension of the list
 ;(because n<nMin on the first iteration, it's out of the domain
 ;this prevents an error)
 ) ;set n to one greater than that value
 ;i.e. increment if element≠2
 ;Will equal Ans(X) iff Ans(X)=2 and the bit read false
Result of above line
n \ u | 0 | 1
0 0 0
added 1044 characters in body
Source Link
lirtosiast
  • 21.6k
  • 5
  • 53
  • 127

#TI-BASIC, (削除) 106 (削除ここまで) (削除) 94 (削除ここまで)(削除) 87 (削除ここまで)(削除) 86 (削除ここまで) 87 bytes

Prompt N,B
"∟B(1+remainder(n,dim(∟B→u
{1
For(I,1,N
Disp Ans
augment({0},Ans)+augment(Ans,{0
Ans and not(Ans=2+seqAns≠2+seq(u(n-(Ans(X)<2)+dim+2dim(∟B)),X,1,dim(Ans
End

This program uses a special property of the equation variable u: when u is called with an argument, the variable n is set to one greater than that argument. The conditional increment depends on this. For list indexing to work properly, n must be its default value of 0, and nMin should be its default 1, so either clear your calculator's RAM or set those values manually before running this.

augment({0},Ans)+augment(Ans,{0 calculates a list of sums of two adjacent elements, so it will return a list of 0s, 1s, and 2s. Then the magic is on this line:

Ans and Ans≠2+seq(u(n-(Ans(X)≠2)+dim(∟B)),X,1,dim(Ans
Ans and ;set 0s to 0
Ans≠ ;set to 0 all sums that equal...
2+seq(...,X,1,dim(Ans ;execute for each element of the list
u( ;return this element in list of bits (looping) 
 n ;current location in the list
 -(Ans(X)≠2)+ ;subtract 1 if the element isn't 2
 dim(∟B) ;Add twice the dimension of the list
 ;(because n<nMin on the first iteration, it's out of the domain; this prevents the error
 ) ;set n to one greater than that value

The result of this line will be that list elements are 0 if they were 0 or if they were 2 and the bit read was 0.

#TI-BASIC, (削除) 106 (削除ここまで) (削除) 94 (削除ここまで) 87 bytes

Prompt N,B
"∟B(1+remainder(n,dim(∟B→u
{1
For(I,1,N
Disp Ans
augment({0},Ans)+augment(Ans,{0
Ans and not(Ans=2+seq(u(n-(Ans(X)<2)+dim(∟B)),X,1,dim(Ans
End

This program uses a special property of the equation variable u: when u is called with an argument, the variable n is set to one greater than that argument. For list indexing to work properly, n must be its default value of 0, and nMin should be its default 1, so either clear your calculator's RAM or set those values manually before running this.

#TI-BASIC, (削除) 106 (削除ここまで) (削除) 94 (削除ここまで)(削除) 87 (削除ここまで)(削除) 86 (削除ここまで) 87 bytes

Prompt N,B
"∟B(1+remainder(n,dim(∟B→u
{1
For(I,1,N
Disp Ans
augment({0},Ans)+augment(Ans,{0
Ans and Ans≠2+seq(u(n-(Ans(X)<2)+2dim(∟B)),X,1,dim(Ans
End

This program uses a special property of the equation variable u: when u is called with an argument, the variable n is set to one greater than that argument. The conditional increment depends on this. For list indexing to work properly, n must be its default value of 0, and nMin should be its default 1, so either clear your calculator's RAM or set those values manually before running this.

augment({0},Ans)+augment(Ans,{0 calculates a list of sums of two adjacent elements, so it will return a list of 0s, 1s, and 2s. Then the magic is on this line:

Ans and Ans≠2+seq(u(n-(Ans(X)≠2)+dim(∟B)),X,1,dim(Ans
Ans and ;set 0s to 0
Ans≠ ;set to 0 all sums that equal...
2+seq(...,X,1,dim(Ans ;execute for each element of the list
u( ;return this element in list of bits (looping) 
 n ;current location in the list
 -(Ans(X)≠2)+ ;subtract 1 if the element isn't 2
 dim(∟B) ;Add twice the dimension of the list
 ;(because n<nMin on the first iteration, it's out of the domain; this prevents the error
 ) ;set n to one greater than that value

The result of this line will be that list elements are 0 if they were 0 or if they were 2 and the bit read was 0.

added 8 characters in body
Source Link
lirtosiast
  • 21.6k
  • 5
  • 53
  • 127
Loading
added 172 characters in body
Source Link
lirtosiast
  • 21.6k
  • 5
  • 53
  • 127
Loading
deleted 71 characters in body
Source Link
lirtosiast
  • 21.6k
  • 5
  • 53
  • 127
Loading
Source Link
lirtosiast
  • 21.6k
  • 5
  • 53
  • 127
Loading

AltStyle によって変換されたページ (->オリジナル) /