Author |
Message |
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 16 May 2008 06:53:56 am Post subject: |
|
|
You're in a loop that does one of two things: either it constantly displays 1, or it constantly displays 0. Pressing [2nd] will switch between these two events. Pressing [CLEAR] will terminate the loop. Do this in 30 bytes.*
*That is, if the program's name is TEASER (a six-letter name), then the respective byte count on the memory management screen would be 30 + 6 = 36 bytes if the program's code matches the answer in number of bytes.
Last edited by Guest on 30 Jul 2010 05:04:29 am; edited 1 time in total |
|
Back to top |
|
|
vuurrobin
Advanced Member
Joined: 09 Aug 2006 Posts: 428
|
Posted: 16 May 2008 07:50:19 am Post subject: |
|
|
I have it currently at 35 bytes (without name) and I can take 3 bytes of if I asume A is 0 prior to running the program, and another 2 bytes if I use 2 getkeys instead of 1, but with that, pressing a key will sometimes not be notised.
Quote: delvar Arepeat ans=45
disp A
getkey
abs(A-(ans=21->A
end |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 16 May 2008 09:41:57 am Post subject: |
|
|
I think I got it.
Quote: Repeat Ans=45
A xor Ans=21→A
Disp A
getKey
End
As long as it doesn't really matter which of the two states you start in.
Last edited by Guest on 16 May 2008 09:48:33 am; edited 1 time in total |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 16 May 2008 09:53:24 am Post subject: |
|
|
That's it exactly. I can see this being a relevant optimization inside some programs – the concept is not all that uncommon.
Last edited by Guest on 16 May 2008 10:08:38 am; edited 1 time in total |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 16 May 2008 09:58:39 am Post subject: |
|
|
Did you come up with this as a response to the "why is xor useful at all" discussion on TI|BD? |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 16 May 2008 10:13:48 am Post subject: |
|
|
I wasn't really looking for a way in which it'd be useful, but xor did come to mind as I was writing something, probably due to that conversation. Based off of that something, here is a two-item custom menu:
0:ClrHome // zero added to prevent ERR:DATA TYPE
Output(4,1,"Normal -- Expert
Repeat Ans=105
A xor 1=abs(Ans-25→A
Output(4,8,sub("<->",Ans+1,2
getKey
End
ClrHome
If A=0
Disp "Normal
If A=1
Disp "Expert
What's great about this is that the setting is "remembered" between uses of the program.
Last edited by Guest on 30 Jul 2010 05:04:54 am; edited 1 time in total |
|
Back to top |
|
|
Igrek
Member
Joined: 23 Aug 2007 Posts: 151
|
Posted: 16 May 2008 11:31:19 am Post subject: |
|
|
I have an other version, also 30+6 bytes:
Quote: :0
:While getKey-45
:Disp Ans
:abs(Ans-(getKey=21
:End |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 16 May 2008 12:38:24 pm Post subject: |
|
|
Igrek wrote: I have an other version, also 30+6 bytes:
Quote: :0
:While getKey-45
:Disp Ans
:abs(Ans-(getKey=21
:End
[post="123739"]<{POST_SNAPBACK}>[/post]
That doesn't really work well: it's almost impossible to exit out of with CLEAR, since once getKey is read it resets to 0 until the next keypress. |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 16 May 2008 12:40:36 pm Post subject: |
|
|
Right, but that version's slower, and [2nd] will occasionally not work; as occasionally as it does work, [CLEAR] loses its opportunity to work, because getKey takes on the value of the most recent keypress and then discards it, causing other instances of getKey to zero out until another keypress is made.
[EDIT] – Beaten by DarkerLine.
Last edited by Guest on 30 Jul 2010 05:06:12 am; edited 1 time in total |
|
Back to top |
|
|
alexrudd pm me if you read this
Bandwidth Hog
Joined: 06 Oct 2004 Posts: 2335
|
Posted: 17 May 2008 12:11:56 am Post subject: |
|
|
In one of my classes this year, I actually used an extremely similar idea (using xor to flip one variable based on the status of another) It allowed a robot (circuit board with an infrared sensor, a microcontroller, and 2 motors) to avoid walls. Using xor was absolutely the smallest and fastest way of doing what needed to be done.
Of course, then I spent quite some time struggling to make it work on hardware because the microprocessor was getting a little interference from the motors which was causing the xor instruction to work one more time than necessary in a 1000Mhz loop, because my instructor insisted I put a duty cycle on the motors, and .... |
|
Back to top |
|
|
WikiGuru ADOS (Attention deficit... Oh! Shiny!)
Elite
Joined: 15 Sep 2005 Posts: 923
|
Posted: 07 Aug 2008 08:33:15 pm Post subject: |
|
|
hehe, you can cut out 5 bytes if [ON] is the quit key
:While 1
:A xor getKey=21->A
:Disp A
:End
Last edited by Guest on 30 Jul 2010 05:03:30 am; edited 1 time in total |
|
Back to top |
|
|
|