Author |
Message |
|
thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569
|
Posted: 16 Dec 2006 10:51:57 pm Post subject: |
|
|
Now for a related, but slightly more complicated teaser. *sigh*
Write a program with the same purpose as that in the first post; that is, given A and B, the program should return √(A²+B²), with the restrictions that you cannot use any of [s]abs(),[/s] R►Pr(), ^, or even √() for that matter. The program would of course be longer... but the shorter the code, the better.
Anyone like to take a stab? ;)
(* EDITED due to recent developments. See my next post. *)
thornahawk
Last edited by Guest on 17 Dec 2006 09:42:30 am; edited 1 time in total |
|
Back to top |
|
|
todlangweilig
Advanced Member
Joined: 14 Feb 2006 Posts: 470
|
Posted: 16 Dec 2006 11:15:55 pm Post subject: |
|
|
This seems too easy, hope Im not missing something (like a shorter way of doing this) :confused:
(A²+B²)^.5
or
A²+B²
Ans^.5 |
|
Back to top |
|
|
chipmaster
Active Member
Joined: 21 Sep 2005 Posts: 601
|
Posted: 16 Dec 2006 11:43:31 pm Post subject: |
|
|
Cheater.
Points for creativity? Here's an implementation of Heron's method:
Code: :Prompt A,B
:A^2+B^2->A
:Rand->C
:While 10^-9<abs(C-D
:C->D
:.5(C+A/C->C
:End
:C
Shoot, I used abs(. Well, it's not really for the same purpose that you were using it for.
Last edited by Guest on 17 Dec 2006 12:04:08 am; edited 1 time in total |
|
Back to top |
|
|
todlangweilig
Advanced Member
Joined: 14 Feb 2006 Posts: 470
|
Posted: 16 Dec 2006 11:45:43 pm Post subject: |
|
|
Quote: Shoot, I used abs(. Who's the cheater now |
|
Back to top |
|
|
chipmaster
Active Member
Joined: 21 Sep 2005 Posts: 601
|
Posted: 16 Dec 2006 11:47:10 pm Post subject: |
|
|
You could get rid of that in my code as long as A^2 + B^2 > 1. |
|
Back to top |
|
|
Fallen Ghost
Elite
Joined: 15 Jun 2006 Posts: 955
|
Posted: 16 Dec 2006 11:48:17 pm Post subject: |
|
|
Number^2+Number2^2 always is positive. |
|
Back to top |
|
|
chipmaster
Active Member
Joined: 21 Sep 2005 Posts: 601
|
Posted: 16 Dec 2006 11:53:28 pm Post subject: |
|
|
0<.5<1 |
|
Back to top |
|
|
todlangweilig
Advanced Member
Joined: 14 Feb 2006 Posts: 470
|
Posted: 17 Dec 2006 12:02:02 am Post subject: |
|
|
Code: :Prompt A,B
:A^2+B^2->A
:Rand->C
:While 10^-9<abs(C-D
:C->D
:.5(C+A/C->C
:End
:C
Chipmaster, did you initialize D? Or does it not matter in this case?
Last edited by Guest on 17 Dec 2006 12:02:33 am; edited 1 time in total |
|
Back to top |
|
|
chipmaster
Active Member
Joined: 21 Sep 2005 Posts: 601
|
Posted: 17 Dec 2006 12:05:12 am Post subject: |
|
|
We can be fairly certain that a random value of C will not precisely equal D the first pass through. That would be a 1 in 10^9 chance. I think I'll take the risk and save the bytes. |
|
Back to top |
|
|
thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569
|
Posted: 17 Dec 2006 09:38:26 am Post subject: |
|
|
OK, I have overlooked stuff in writing that challenge.
The use of abs() is hard to avoid. So the restriction I gave is moot.
*HOWEVER* I modify the challenge that you cannot use complex numbers (which should've been what was intended so I don't see abs(a+bi) ) or powers and roots, for that matter. Cheater. XD
...and to make it even stiffer, the code should work for *LARGE* values, e.g., inputting 3e99 and 4e99 should give 5e99 . ;)
thornahawk
Last edited by Guest on 17 Dec 2006 10:04:59 am; edited 1 time in total |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 17 Dec 2006 09:49:24 am Post subject: |
|
|
[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]Prompt A,B
B/sin(tan‾¹(B/A
This might also be considered cheating because of the alternate forms of circular functions.
Also, the limit for [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]sin() on the 83+ is 10^12.
Last edited by Guest on 17 Dec 2006 11:03:58 am; edited 1 time in total |
|
Back to top |
|
|
thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569
|
Posted: 17 Dec 2006 10:04:18 am Post subject: |
|
|
Clever, Goose. I won't consider it cheating, but the trig functions are so limited in range...
Other takers?
thornahawk
P.S. OK, a hint. What I had in mind was related, but not quite the same, as Newton's method like what chipmaster employed. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 17 Dec 2006 12:24:57 pm Post subject: |
|
|
Removing all the obviously cheat answers that I posted here, [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]stdDev({-A,A,Btan(Pi/3. This does have a limited range, but it's exactly as limited as R>Pr's range - it works for [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]E63 or thereabouts.
Of course you could fix it by scaling all numbers down. Which still doesn't change the presence of a square root deep down in stdDev()'s formula.
Last edited by Guest on 19 Jan 2008 12:07:12 pm; edited 1 time in total |
|
Back to top |
|
|
simplethinker snjwffl
Active Member
Joined: 25 Jul 2006 Posts: 700
|
Posted: 18 Dec 2006 03:59:54 pm Post subject: |
|
|
Here's one thats probably cheating too, but it's range is 10^-99 to 10^99:
:Prompt A,B
:int(log(A /->/ C
:not©+.1(C>0)+10(C<0 /->/ W
:1 /->/ X:For(R,1,abs(C:WX /->/ X:End
:AAns /->/ D
:int(log(B /->/ E
:not(E)+.1(E>0)+10(E<0 /->/ W
:1 /->/ Y:For(R,1,abs(E:WY /->/ Y:End
:BAns /->/ F
:If 4<abs(C-E
:Then:Disp max({A,B:Stop:End
:Y /^-1/ solve(log(/theta/)-2/^-1/log((DY/X)/^2/+F/^2/),/theta/,0 |
|
Back to top |
|
|
thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569
|
Posted: 19 Dec 2006 02:09:48 am Post subject: |
|
|
Alright, I'm posting my solution to my challenge:
[SPOILER]
Prompt A,B
abs(B→V
max(Ans, abs(A→U
min(V, abs(A→V
While V
V/U
Ans²/(4+Ans²→C
U+2AnsU→U
CV→V
End
U
[SPOILER]
The algorithm was originally discussed here.
thornahawk |
|
Back to top |
|
|
trigkid213
Member
Joined: 30 Mar 2006 Posts: 208
|
Posted: 19 Dec 2006 11:40:00 pm Post subject: |
|
|
that's cool. |
|
Back to top |
|
|
|