Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
So I need to think of a good example of a program that can be carried through from planning, deciding on functions, to writing, unit-testing, testing, and debugging. TI-BASIC, of course, and it can use loops, jumps, conditionals, menus, and subprograms. I asked on IRC, and there were some good ideas, such as a Menu-based RPG and a random number-guessing game. I already discuss a number-guessing game somewhere, so I took the number-guessing game idea and thought of a dice-rolling game (game?) of some sort. I'm not 100% on that, though, so any other ideas? Ideally, this program wouldn't be more than 30 or 40 lines.
How about tackling some of the problems in Project Euler?

http://projecteuler.net/problems
rfdave wrote:
How about tackling some of the problems in Project Euler?

http://projecteuler.net/problems
Wow, that's actually a really awesome idea. Very Happy I appreciate you sharing that! And in the next chapter, I carry a game through, so this would be a good place for a math program. Problem 9 particularly catches my eye:

http://projecteuler.net/problem=9

I think if I expanded it to ask the user for a number to look for the sum for, rather than just using 1000, and perhaps some kind of progress display, that that might be a neat example program.
pong. I didn't realize how many people have trouble with it, until there was recently an assignment on that in one of the other comp sci classes.
graphmastur wrote:
pong. I didn't realize how many people have trouble with it, until there was recently an assignment on that in one of the other comp sci classes.
I actually thought of that, but sadly, they (you?) don't learn getKey until the next chapter. I could make it be a bouncing ball, but no paddle. :S However, please keep on me to make Pong be an example in some later chapter!
I would look for more-concrete examples that aren't flush with avenues for people taking creative liberties with the designs. Pong can go in several directions, and a beginner might mistake a demonstration of one of them as the "right" way to go about it.
Weregoose wrote:
I would look for more-concrete examples that aren't flush with avenues for people taking creative liberties with the designs. Pong can go in several directions, and a beginner might mistake a demonstration of one of them as the "right" way to go about it.
Weregoose, with that in mind, could you suggest a (sane) sort of math or entertaining program that would fit the bill and be sufficiently concrete? What do you think about my Project Euler idea based on rfdave's excellent suggestion?
KermMartian wrote:
Weregoose wrote:
I would look for more-concrete examples that aren't flush with avenues for people taking creative liberties with the designs. Pong can go in several directions, and a beginner might mistake a demonstration of one of them as the "right" way to go about it.
Weregoose, with that in mind, could you suggest a (sane) sort of math or entertaining program that would fit the bill and be sufficiently concrete? What do you think about my Project Euler idea based on rfdave's excellent suggestion?
From a list of integers less than 100, house a stem-and-leaf plot in a matrix.

The Pythagorean Triple assignment should be a fun one (and it was; I just tried it). Ingenuity there makes the difference between the number of For( loops employed.
Hmm, now I'm intrigued how I might get better than O(n^2/2) = O(n^2) performance on that. Very Happy This should indeed be a fun example to present, I think.
I would like this better than another game example because, at the end of the day, a calculator is intended to do mathematical computations, not play games...
rfdave wrote:
I would like this better than another game example because, at the end of the day, a calculator is intended to do mathematical computations, not play games...
What it's intended for and what people are able to stretch their imaginations to create are two different things, but for this particular chapter, I agree that a math program would be a good example.
*bump* (Premature bump, I know; sue me Wink ). For what it's worth, here's the version that I came up with. I'm sure Weregoose might see some insane version that uses seq() to complete this in O(log(n)) or something, but here goes:

BASIC Code wrote:
:ClrHome
:Disp "FINDS A PYTHAGOR","EAN TRIPLET","A B C (A+B=C)","WHERE A+B+C=N","AND A<B<C
:Input "TARGET N=",N
:For(A,1,N-1
:For(B,A+1,N-1
:If A+B+√(A+B)=N
:Then
:ClrHome
:Disp "FOUND:","A=","B=","C=","N=
:Output(2,3,A
:Output(3,3,B
:Output(4,3,√(A+B
:Output(5,3,N
:Pause
:Return
:End
:End
:End
:ClrHome
:Disp "NO RESULTS
Generated by SourceCoder, 2005-2012 Cemetech
One thing I notice, are some optimizations like removing end parens and quotation marks; wouldn't it be wise to inform the reader of the optimizations at a later time, to lead away from more potential bad-optimization tricks and general confusion? Plus, if the reader moves on to use a Computer language, they won't be all "WTF mate" when those tricks don't work.

Unless of course you wisely integrated a section on optimization earlier and I obviously don't know about it. Razz
As you'll find out if you (please?) sign up for the MEAP that's launching in less than a week, I gradually introduced leaving off things like ending parentheses and quotes after first teaching them to write commands with all the closing "punctuation" intact. Smile But it's a good point, thanks for thinking of that.
Find integers u and v such that u+v+√(u+v) = k.

u+v+√(u+v) = k
√(u+v) = k-u-v
u+v = (k-u-v)
u+v = k-2ku+u-2kv+2uv+v
0 = k-2ku-2kv+2uv
2ku-2uv = k-2kv
u(2k-2v) = k-2kv
u = (k-2kv)/(2k-2v)
u = (k/2-kv)/(k-v)
u = k(k/2-v)/(k-v)
u = k((k-k/2)/(v-k)+1) // (p-r)/(q-r) = (q-p)/(r-q)+1
u = k(k-k/2)/(v-k)+k
u = k(k/2)/(v-k)+k
u = k/(2(v-k))+k

Our task now is to find a v for which u stays an integer.

With k = 1000, the smallest such pair is (200,375).

√(200+375) = 425, and 200+375+425 = 1000.

Another little fact is that if k isn't divisible by 3, you can increment v by 3 in the hunt for u. If k isn't divisible by 4, you can increment v by 4.

Code:
:Input N
:1+max({2,3}not(fPart(N/{3,4
:For(X,Ans,N-1,Ans
:N+N/(2(X-N
:If fPart(Ans
:End
:If X<N-1
:{X,Ans,R►Pr(X,Ans

ETA: A009096
As a side note, I should point out that I generalized the problem to "Given some arbitrary N, find A, B, C such that 0<A<B<C (and obviously C<N) where A+B+C=N". Of course all the tricks you mentioned are awesome and valid, but do you think perhaps that might fly over their heads? Perhaps after I work them through the process of building to my solution I'll show how you can massively reduce the search space like that.
KermMartian wrote:
*bump* (Premature bump, I know; sue me Wink ). For what it's worth, here's the version that I came up with. I'm sure Weregoose might see some insane version that uses seq() to complete this in O(log(n)) or something, but here goes:

BASIC Code wrote:
:ClrHome
:Disp "FINDS A PYTHAGOR","EAN TRIPLET","A B C (A+B=C)","WHERE A+B+C=N","AND A<B<C
:Input "TARGET N=",N
:For(A,1,N-1
:For(B,A+1,N-1
:If A+B+√(A+B)=N
:Then
:ClrHome
:Disp "FOUND:","A=","B=","C=","N=
:Output(2,3,A
:Output(3,3,B
:Output(4,3,√(A+B
:Output(5,3,N
:Pause
:Return
:End
:End
:End
:ClrHome
:Disp "NO RESULTS
Generated by SourceCoder, 2005-2012 Cemetech



I may be missing the point, (or blind) but you could also add some code to find ALL of the sides. Would be easy. again, I MAY be blind and missing where you do this.

Code:
:Output(2,3,A
:Output(3,3,B
:Output(4,3,√(A+B
:Output(5,3,N

All sides are found.
Sounds like you're in the right audience for me to bounce the material in this chapter off of you, then. Smile The idea is to find where A+B+C=N, and remember that A^2+B^2=C^2, or C=sqrt(A^2+B^2). Therefore, this line:

If A+B+√(A+B)=N

is equivalent to A+B+C.

Edit: Weregoose, I decided to show the one-loop solution as an extra add-on, a "never decide your program is complete" sort of thing. I even managed to work through the derivation and get the same equation as you!
Why not go further and display all possible solutions?

Code:
:Input N
:For(X,1,N-N/√(2
:.5N/(N-X
:If not(fPart(Ans
:Disp {X,N-Ans,Ans-X
:End


Edit: To make that go a little faster:

Code:
:Input N
:.5N→M
:For(X,N-1,N/√(2),-1)
:If not(fPart(M/X
:Disp abs(N-{X,M/X,X+M/X
:End
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement