Author |
Message |
|
Ed H
Member
Joined: 30 Nov 2007 Posts: 138
|
Posted: 14 Oct 2008 09:32:28 pm Post subject: |
|
|
Write a program that takes a list in Ans and returns a list to Ans that contains one of every element from the original list. The program could turn {1,1,7,3,7,2,1} into {1,7,3,2} or {1,2,3,7} - order does not need to be preserved. Basically, the program removes the duplicates from Ans.
I've got it in 48 bytes.
Last edited by Guest on 14 Oct 2008 10:03:41 pm; edited 1 time in total |
|
Back to top |
|
|
darkstone knight
Advanced Member
Joined: 07 Sep 2008 Posts: 438
|
Posted: 15 Oct 2008 04:38:42 am Post subject: |
|
|
Spoiler wrote: sortAD(L1
L1*not(not(seq(L1(dim(L1)-x),x,1,dim(L1 (whitout the mujltiplication sing)
sortAD(ans (possible??)
25 bytes... but there are stil zeroes at the end
Last edited by Guest on 15 Oct 2008 06:51:35 am; edited 1 time in total |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 15 Oct 2008 06:50:10 am Post subject: |
|
|
No, that's not possible. Why submit it, asking if it will work, and not just test it yourself to make sure? It doesn't even take into account that the input needs to be in Ans. Also, I put your code into a [quote] box to hide it better, as white-on-gray is still clearly visible on my screen.
Oh yeah, and I have my program in 48 bytes.
Last edited by Guest on 22 Jul 2010 12:31:29 pm; edited 1 time in total |
|
Back to top |
|
|
simplethinker snjwffl
Active Member
Joined: 25 Jul 2006 Posts: 700
|
Posted: 15 Oct 2008 10:46:28 am Post subject: |
|
|
Quote: :Ans→A:{Ans(1
:For(A,1,dim(∟A
[s]:If not(max(Ans=∟A(A[/s] :If min(Ans≠∟A(A
:augment(Ans,{∟A(A
:End:Ans
49 bytes...
[edit]I figured out how to cut that last byte out
Last edited by Guest on 15 Oct 2008 01:47:20 pm; edited 1 time in total |
|
Back to top |
|
|
bfr
Member
Joined: 13 Feb 2006 Posts: 108
|
Posted: 15 Oct 2008 04:32:08 pm Post subject: |
|
|
Break all the standards of TI-BASIC coding!
Quote:
:If min(Ans≠max(Ans
:Then
:augment(L2,L1
:L1*(L1≠max(L1
:prgmA
:Else
:L2
(assuming the program is called prgmA)
If only the augment(L2,L1 part worked...still an interesting concept though
It's 43 bytes, anyway, I think
EDIT:
simplethinker: I don't think that "Ans" at the end is needed in your code
Last edited by Guest on 15 Oct 2008 04:59:23 pm; edited 1 time in total |
|
Back to top |
|
|
simplethinker snjwffl
Active Member
Joined: 25 Jul 2006 Posts: 700
|
Posted: 15 Oct 2008 07:50:37 pm Post subject: |
|
|
bfr wrote: simplethinker: I don't think that "Ans" at the end is needed in your code
[post="127887"]<{POST_SNAPBACK}>[/post]
It is. The only time you don't need to add it to the end of the program is when the calculation yielding Ans is the last line of the program, but there's an End there because of the loop.
Last edited by Guest on 22 Jul 2010 12:31:58 pm; edited 1 time in total |
|
Back to top |
|
|
Ed H
Member
Joined: 30 Nov 2007 Posts: 138
|
Posted: 16 Oct 2008 12:53:44 am Post subject: |
|
|
simplethinker wrote: bfr wrote: simplethinker: I don't think that "Ans" at the end is needed in your code
[post="127887"]<{POST_SNAPBACK}>[/post]
It is. The only time you don't need to add it to the end of the program is when the calculation yielding Ans is the last line of the program, but there's an End there because of the loop.
[post="127906"]<{POST_SNAPBACK}>[/post]
You're right -- but the challenge criteria do not require you to display the answer; only return it to Ans.
I actually had 46 bytes. I forgot to subtract off 2 bytes for the title in the opening post.
Quote: :Ans→A
:{Ans(1
:For(X,2,dim(∟A
:If min(Ans≠∟A(X
:augment(Ans,{∟A(X
:End was my solution.
Last edited by Guest on 22 Jul 2010 12:32:33 pm; 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 Oct 2008 08:47:50 am Post subject: |
|
|
Bonus question: how do you add 2 bytes to that code to make it at least twice as fast? |
|
Back to top |
|
|
ticalcnoah
Member
Joined: 28 Oct 2007 Posts: 153
|
Posted: 16 Oct 2008 09:33:00 am Post subject: |
|
|
Close up the for loop. |
|
Back to top |
|
|
JoostinOnline
Active Member
Joined: 22 Aug 2007 Posts: 559
|
Posted: 16 Oct 2008 09:36:38 am Post subject: |
|
|
ticalcnoah wrote: Close up the for loop.
[post="127924"]<{POST_SNAPBACK}>[/post]
It is closed... |
|
Back to top |
|
|
Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565
|
Posted: 16 Oct 2008 11:59:32 am Post subject: |
|
|
JoostinOnline wrote: ticalcnoah wrote: Close up the for loop.
[post="127924"]<{POST_SNAPBACK}>[/post]
It is closed...
[post="127925"]<{POST_SNAPBACK}>[/post]
Did you saw the same code as us? (the last of Ed H)
I am not certain but is a good guess. I am not certain because I don't remember the details if the For unclosed affects If/Then/End and :If:command or just one of them. |
|
Back to top |
|
|
TheStorm
Calc Guru
Joined: 17 Apr 2007 Posts: 1233
|
Posted: 16 Oct 2008 10:39:40 pm Post subject: |
|
|
The For loop is closed and If with out the Then Does not require a End. |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 16 Oct 2008 11:31:46 pm Post subject: |
|
|
By "close" he means to add the right parenthesis to the end of the For( loop, and he's right.
Go to For( at TI|BD and search the article for "one rather strange optimization" to learn why.
Last edited by Guest on 22 Jul 2010 12:32:51 pm; edited 1 time in total |
|
Back to top |
|
|
JoostinOnline
Active Member
Joined: 22 Aug 2007 Posts: 559
|
Posted: 17 Oct 2008 01:58:26 pm Post subject: |
|
|
Weregoose wrote: By "close" he means to add the right parenthesis to the end of the For( loop, and he's right.
Go to For( at TI|BD and search the article for "one rather strange optimization" to learn why.
[post="127956"]<{POST_SNAPBACK}>[/post]
Haha, I had completely forgotten about that.
Last edited by Guest on 22 Jul 2010 12:33:10 pm; edited 1 time in total |
|
Back to top |
|
|
Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565
|
Posted: 17 Oct 2008 02:25:19 pm Post subject: |
|
|
JoostinOnline wrote: Weregoose wrote: By "close" he means to add the right parenthesis to the end of the For( loop, and he's right.
Go to For( at TI|BD and search the article for "one rather strange optimization" to learn why.
[post="127956"]<{POST_SNAPBACK}>[/post]
Haha, I had completely forgotten about that.
[post="127978"]<{POST_SNAPBACK}>[/post]
It looked so obvious to me that was the parentheses that I forgot that you would think in the End.
Also, without the End I don't think the code would function. (only if the end of the program mysteriously "closes" the For( like an End ??? No, I don't think )
Hopefully Weregoose watches all.
And yes, by seeing the TI|BD page the If without Then and End and when is false will slow down.
Last edited by Guest on 22 Jul 2010 12:33:27 pm; edited 1 time in total |
|
Back to top |
|
|
Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565
|
Posted: 17 Oct 2008 04:13:36 pm Post subject: |
|
|
bfr wrote: Break all the standards of TI-BASIC coding!
Quote:
If only the augment(L2,L1 part worked...still an interesting concept though
I think it is called recursion. And it is used to by using 1 BASIC program to use routines to make sprites or such.
But for math or other uses I never found that original use, at least in TI-BASIC. |
|
Back to top |
|
|
TheStorm
Calc Guru
Joined: 17 Apr 2007 Posts: 1233
|
Posted: 17 Oct 2008 05:14:48 pm Post subject: |
|
|
JoostinOnline wrote: Weregoose wrote: By "close" he means to add the right parenthesis to the end of the For( loop, and he's right.
Go to For( at TI|BD and search the article for "one rather strange optimization" to learn why.
[post="127956"]<{POST_SNAPBACK}>[/post]
Haha, I had completely forgotten about that.
[post="127978"]<{POST_SNAPBACK}>[/post]
Yeah I had too, another weird thing about that optimization is the leaving the parenthesis off only causes a slow down if the If comes right after the For( statement. If you were to add either a step argument to the for loop or a blank line after the For( command it is just as fast as if you had the closing parenthesis. So actually you can double the speed by adding a blank line before the If statement which is one byte rather than the two needed to close the for loop.
Last edited by Guest on 22 Jul 2010 12:33:47 pm; edited 1 time in total |
|
Back to top |
|
|
JoostinOnline
Active Member
Joined: 22 Aug 2007 Posts: 559
|
Posted: 18 Oct 2008 05:26:50 pm Post subject: |
|
|
Galandros wrote: JoostinOnline wrote: Weregoose wrote: By "close" he means to add the right parenthesis to the end of the For( loop, and he's right.
Go to For( at TI|BD and search the article for "one rather strange optimization" to learn why.
[post="127956"]<{POST_SNAPBACK}>[/post]
Haha, I had completely forgotten about that.
[post="127978"]<{POST_SNAPBACK}>[/post]
It looked so obvious to me that was the parentheses that I forgot that you would think in the End.
Also, without the End I don't think the code would function. (only if the end of the program mysteriously "closes" the For( like an End ??? No, I don't think )
Hopefully Weregoose watches all.
And yes, by seeing the TI|BD page the If without Then and End and when is false will slow down.
[post="127979"]<{POST_SNAPBACK}>[/post]
I am really sorry, but what??? I don't really understand what you are trying to say. Nobody said we should remove End from the code.
Last edited by Guest on 22 Jul 2010 12:31:02 pm; edited 1 time in total |
|
Back to top |
|
|
Baruch
Newbie
Joined: 24 Dec 2008 Posts: 5
|
Posted: 25 Dec 2008 03:39:34 am Post subject: |
|
|
Hello !
I've done this in 42 bytes :
Quote: Ans->L1
{0
For(A,1,dim(L1
If min(Ans=!L1(A
augment(Ans,{L1(A
End
cumSum(DList(Ans
Last edited by Guest on 25 Dec 2008 03:40:08 am; edited 1 time in total |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 25 Dec 2008 05:39:18 pm Post subject: |
|
|
Hi! The way we're counting bytes—the number of letters in the program name is subtracted from the RAM occupied by the program—your code comes in at 55 bytes. (I think you could save another byte by storing to a user-defined list.)
Welcome to United-TI! :biggrin: |
|
Back to top |
|
|
|