Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: sammyMaX on May 14, 2013, 05:59:36 pm

Title: sammyMaX's Nspire PalPrime
Post by: sammyMaX on May 14, 2013, 05:59:36 pm
darn my code is waayyy longer than Jim Bauwens's and Xeda's...

My submission was in Nspire basic, and it had two helper functions along with the main palprime function. The main function generates palindromes and gives them to the prime tester. The prime tester uses the Miller-Rabin algorithm, which requires modular exponentiation, so there is also a modular exponentiation function. My code for each:
exprem (Modular Exponentiation) (http://pastebin.com/2bFxiSBY)
primetest (Miller-Rabin Test) (http://pastebin.com/vv4FbsLa)
palprime (Palindrome Generator and Main Function) (http://pastebin.com/XQvW7L9t)
It takes around 2 seconds to calculate the 100th palprime, 6 seconds for the 250th palprime, 16 seconds for the 500th palprime, and 39 seconds for the 1000th palprime. The times were taken from an emulated Nspire CX running OS 3.1.0, at 100% emulation (normal speed).
Title: Re: sammyMaX's Nspire PalPrime
Post by: Adriweb on May 15, 2013, 06:14:26 am
It takes around 2 seconds to calculate the 100th palprime, 6 seconds for the 250th palprime, 16 seconds for the 500th palprime, and 39 seconds for the 1000th palprime. The times were taken from an emulated Nspire CX running OS 3.1.0, at 100% emulation (normal speed).

Having finished to time the Nspire entries, I can say your emulated Nspire wasn't at 100% (or, well, the emulation speed display was clearly inaccurate).
On a real CX 3.1, n=1000 took 2mins 33secs 5tenth.
But you really don't have to worry, each program was tested on the same calc (hardware and software) following a strict protocol ensuring performance fairness for everyone :)
Title: Re: sammyMaX's Nspire PalPrime
Post by: sammyMaX on May 15, 2013, 07:04:22 am
Maybe I should get a real Nspire CX to test my programs...oh wait that's why I entered this contest :)
Title: Re: sammyMaX's Nspire PalPrime
Post by: Joshuasm32 on May 15, 2013, 07:07:01 am
Would an emulator work?  I know that there is some software to make ROM's...   <_<
Title: Re: sammyMaX's Nspire PalPrime
Post by: sammyMaX on May 15, 2013, 07:17:49 am
I was using an emulator but apparently its speed is inaccurate.
Title: Re: sammyMaX's Nspire PalPrime
Post by: lkj on May 15, 2013, 02:01:00 pm
Yeah, the speed isn't very accurate. Accessing the RAM for example is much faster than on a real calc.

It's still much, much faster than my entry  :o
Title: Re: sammyMaX's Nspire PalPrime
Post by: Lionel Debroux on May 15, 2013, 02:05:58 pm
Indeed, the speed of most emulators is not accurate at all. Benchmarking on real hardware was the only way to achieve fairness :)