Show Posts
|
|
Pages: [1] 2 3 ... 115
|
|
1
|
Calculator Community / TI-BASIC Language / Re: My z80 basic palprime algorithm
|
on: 14 May, 2013, 21:04:25
|
So I tested yours and I got 21 seconds for the 42nd prime palindrome.
Strange, I just tried it again and I get 16s on my TI-84 Plus. (not sure what OS version actually). I've attached my program to this post, could you time that (in case something is different in tokens)? Compared to mine, yours is 53 bytes less, too. You have a bunch of places that can be optimised for speed, though, so I tried a few things and here is what I have: First, here are the main optimisations I made: 1 2 3 4 5 6 7 8 9 10 11 12
| :If prod(Ans-{1,3,7,9 Goes to: :If 1<gcd(10,Ans ;I actually used 'not equal', but this works, too
:If fPart(F/3 Goes to: :If remainder(F,3
:While Ans{^2}≤F and fPart(F/Ans) and fPart(F/(Ans+2 Goes to: :While Ans{^2}≤F and min(remainder(F,{Ans,Ans+2
|
There are a few more, too, but here is what I ended up with: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| :DelVar EAns-5→N :While 1 :E+1→E :1+int(log(E→B :If 1<gcd(10,int(E10^(1-Ans :End :10E→F :E→D :While iPart(D :.1iPart(D→D :10(F+fPart(Ans→F :End :For(H,0,9 :If remainder(F,3 :Then :√(F→D :7 :While Ans≤D and min(remainder(F,{Ans,Ans+4 :Ans+6 :End :N-(Ans>D→N :If not(Ans :Return :End :End :F+10^(B→F :End :End
|
Now it takes about 17 seconds to compute the 42nd prime palindrome and it is 24 bytes smaller  Hah, nice optimisations! It's always fun when you still can make such a big difference by little code changes  I have been trying to tweak it to get it even faster and I know that there must be a few optimisations that I am not seeing. It is 77 bytes smaller than mine and almost as fast, so that is really awesome. ... After adjusting the prime checker thing even more, I made it much faster, and it is now faster than mine, at the cost of some bytes (still 59 bytes smaller than mine). For comparison, the version above takes 17 seconds to find palprime 42 and 86 seconds for palprime 100. This version takes 13 and 52 seconds, respectively. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| :DelVar EAns-5→N :While 1 :E+1→E :1+int(log(E→B :If 1<gcd(10,int(E10^(1-Ans :End :10E→F :E→D :While iPart(D :.1iPart(D→D :10(F+fPart(Ans→F :End :For(H,0,9 :If min(remainder(F,{3,7,11 :Then :√(F→D :13 :While Ans≤D and min(remainder(F,Ans+{0,4,6,10,16,18,24,28 :Ans+30 :End :N-(Ans>D→N :If not(Ans :Return :End :End :F+10^(B→F :End :End
|
Hopefully everything is typed properly. EDIT: Made it even faster. Now 12 and 49 seconds respectively, using the same prime checking routine as my program. Hah, cool! I actually changed my Nspire version to use 30 but reverted the change because it became slower for larger numbers (although faster for smaller numbers). But didn't try it in my z80 version. Anyway thanks Xeda for looking into my code!
|
|
|
|
|
2
|
Calculator Community / TI-BASIC Language / My z80 basic palprime algorithm
|
on: 13 May, 2013, 21:46:54
|
While I only participated in the TI-Nspire section for the palprime contest, I made a z80 basic version too (which I did not enter). It's my first basic program for z80 based calculators. It finds the 42nd palprime in 16 seconds (TI-84 Plus) Here is the code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| :Ans→N --- find the AnsTh palprime :5→A :0→E :While 1 :E+1→E :1+int(log(Ans→B :int(E10^(1-Ans :If prod(Ans-{1,3,7,9 :End :E10^(B+1→F :E :For(G,B,1,{-}1 :.1Ans→D :F+fPart(Ans)10^(G→F :int(D :End :10^(B→P :For(H,0,9 :If fPart(F/3:Then :5 :While Ans{^2}≤F and fPart(F/Ans) and fPart(F/(Ans+2 :Ans+6 :End :If Ans{^2}>F :Then :A+1→A :If A=N:Stop :End :End :F+P→F :End :End
|
The result will be stored in F. Beware I'm using some end tokens to quickly jump again to the start of the loop, so there is start/end of block 'mismatching' ;P. While I'm not really going to continue this I'd like to know if I still can optimise it more (the code, not the algorithm)^^ Edit: I forgot, it can not find the first 5 palprimes, not implemented because I was first focusing on the algorithm
|
|
|
|
|
3
|
General Discussion / Computer Projects and Ideas / Re: Random Script Snippets
|
on: 10 May, 2013, 19:26:08
|
Here is something I did in my spare time in C#. It's not really a snippit, but fun anyway^^ Main.cs - Main program code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| using System;
namespace Fractal { class MainClass {
public static void TriLine(double distance, Turtle myTurtle) { Console.ForegroundColor = ConsoleColor.Magenta; if (distance < 1) { myTurtle.Forward(distance); } else { TriLine (distance/3, myTurtle); myTurtle.Left (60); TriLine (distance/3, myTurtle); myTurtle.Right (120); TriLine (distance/3, myTurtle); myTurtle.Left (60); TriLine (distance/3, myTurtle); } }
public static void Main (string[] args) { Console.WriteLine ("Press any key to start"); Console.ReadLine ();
Display myDisplay = new Display (); Turtle myTurtle = new Turtle (myDisplay);
//myTurtle.HomeXPos = 10; myTurtle.HomeYPos = 10;
for (int i = 0; i < 3; i++) { TriLine(300, myTurtle); myTurtle.Right(120); }
myDisplay.UpdateDisplay ();
} } }
|
Turtle.cs - Turtle 'engine' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| using System;
namespace Fractal { public class Turtle { public double XPos {get; set;} public double YPos {get; set;} public double Angle {get; set;}
public bool Pen {get; set;}
public double HomeXPos {get; set;} public double HomeYPos {get; set;}
private Display myDisplay;
public Turtle(Display myDisplay) { XPos = 0; YPos = 0; Angle = 0;
Pen = true;
this.myDisplay = myDisplay;
HomeXPos = myDisplay.Width / 2; HomeYPos = myDisplay.Height / 2; }
public static double DegToRad(double deg) { return deg * Math.PI / 180; }
public void Forward(double distance) { double oldX = XPos; double oldY = YPos; double angle = DegToRad(this.Angle); YPos = oldY + distance * Math.Cos(angle); XPos = oldX + distance * Math.Sin(angle); if (Pen) { myDisplay.DrawLine ( (int) Math.Round(HomeYPos + oldY), (int) Math.Round(HomeXPos + oldX), (int) Math.Round(HomeYPos + YPos), (int) Math.Round(HomeXPos + XPos) );
//m } }
public void Left(double angleDelta) { Angle -= angleDelta; }
public void Right(double angleDelta) { Angle += angleDelta; }
public override string ToString () { return string.Format ("[Turtle: XPos={0}, YPos={1}, Angle={2}]", XPos, YPos, Angle); } } }
|
Display.cs - Allows you to draw to your console 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| using System;
namespace Fractal { public class Display { public const string PIXEL_ON = "\u2588\u2588"; public const string PIXEL_OFF = " "; public const int PIXEL_CHARS = 2;
public int Height { get; set; } public int Width { get; set; }
public bool[,] DisplayBuffer;
public Display() { SetDisplay (); }
public void SetDisplay () { Width = Console.BufferWidth / PIXEL_CHARS; Height = Console.BufferHeight - 2;
DisplayBuffer = new bool[Height, Width];
for (int i = 0; i < DisplayBuffer.Length; i++) { DisplayBuffer [(int) i/Width, i%Width] = false; }
}
public void SetPixel (int y, int x, bool state) { if (x > 0 && y > 0 && x < Width && y < Height) DisplayBuffer [y, x] = state; }
public void DrawLine(int x1, int y1, int x2, int y2) { int w = x2 - x1; int h = y2 - y1; int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0 ; if (w<0) dx1 = -1 ; else if (w>0) dx1 = 1 ; if (h<0) dy1 = -1 ; else if (h>0) dy1 = 1 ; if (w<0) dx2 = -1 ; else if (w>0) dx2 = 1 ; int longest = Math.Abs(w) ; int shortest = Math.Abs(h) ; if (!(longest>shortest)) { longest = Math.Abs(h) ; shortest = Math.Abs(w) ; if (h<0) dy2 = -1 ; else if (h>0) dy2 = 1 ; dx2 = 0 ; } int numerator = longest >> 1; for (int i=0; i<=longest; i++) { SetPixel(x1 , y1, true) ; numerator += shortest ; if (!(numerator<longest)) { numerator -= longest ; x1 += dx1 ; y1 += dy1 ; } else { x1 += dx2 ; y1 += dy2 ; } } }
public void UpdateDisplay() { Console.SetCursorPosition (0, 0);
for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { string pixel = DisplayBuffer[y, x] ? PIXEL_ON : PIXEL_OFF; Console.Write (pixel); } Console.WriteLine (); } }
} }
|
Now, here is what it looks like:  Of course, I set my terminal to have very very many rows and columns so I can simulate pixels. (however you can change the code to work on a 'lower' resolution)
|
|
|
|
|
5
|
Calculator Community / Other Calculator Discussion and News / Re: TI NSpire CX CAS VS HP Prime CAS
|
on: 04 May, 2013, 13:16:54
|
Where does the Nspire CX CAS have better CAS than the 89? I'd honestly like to know this.
It's also important to note that the CAS software on the Nspire evolved from the CAS on 68k systems. Regarding the HP Prime vs the TI-Nspire CAS, the Nspire has a lot more backing of teachers and there is an incredible amount of activities you can download.
|
|
|
|
|
6
|
General Discussion / Miscellaneous Discussion / Re: Would you be interested in an European calculator community meeting?
|
on: 23 April, 2013, 20:42:10
|
Make sure the place has enough sleeping places for those who want to hang out late night and/or can't afford a hotel.
You make a good point here, I actually haven't thought about this. Will need to think about the possible solutions about this  As far the location, at the moment Belgium/France seems the best bet (for most members). But of course the expense of traveling is big problem. I understand that this is a big problem for most people. But without traveling, there isn't really going to be a big meeting. Maybe we could have meetings for different countries at the same time, have a big video conference together (project/display). That would be interesting too.
|
|
|
|
|
8
|
Omnimaga / News / Re: Mini vMac for the TI-Nspire
|
on: 15 April, 2013, 15:21:14
|
How can I open and edit AppleScripts on this emulator?
From wikipedia: AppleScript was released in October 1993 as part of System 7.1.1 I suppose if you have system 7.1.1 running, yes. (the one included is 7.0.1).
|
|
|
|
|
9
|
Omnimaga / News / Re: Mini vMac for the TI-Nspire
|
on: 14 April, 2013, 22:27:21
|
Just do MS-DOS, I bet that that could run on a potato.
But not on an apple  If you guys are interested in porting DOS or an emulator such as DOSbox, you should start a new thread about it. This topic isn't really the place for it 
|
|
|
|
|
10
|
Omnimaga / News / Re: Mini vMac for the TI-Nspire
|
on: 14 April, 2013, 18:22:25
|
|
Augs, When the OS has started, press TAB one time. Then pressing 5 will act as a mouse click. The other can also be used to control the mouse.
Floris: It's a lot of work to do that, so I'll see.
|
|
|
|
|
11
|
Calculator Community / Other Calculator Discussion and News / Re: Your calculator collection
|
on: 14 April, 2013, 12:32:09
|
What happened to the one in the bottom right (83+?) It looks like someone stabbed the screen  Nice collection though  It actually doesn't have a display anymore. It's a headless calc now ^^ I've got it from a friend, no idea what happened to it. The screen was all cracked, I just removed it. erm, is the 89+ all on the bottom only the case without the actual calc?  It's a TI-92 Plus without mainboard. I got the mainbord still though, and it's still functional. I broke the screen of it during the 2006 TI-Freakware contest.
|
|
|
|
|
12
|
Omnimaga / News / Re: Mini vMac for the TI-Nspire
|
on: 14 April, 2013, 12:06:08
|
Well, at the moment my port can open only one disk image. That image has to have a system folder in it, in order to boot. But it doesn't, and that is why it fails. Install Mini vMac on your computer, and drag the system.dsk onto the emulator (so it will boot), and then drag the 1988.dsk image on it. You will see two floppies on your desktop, and now you could for example copy the system folder to the 1988.dsk. Then shutdown your emulator. Now you should be able to get that disk working on your handheld. Regarding the problem that you can't delete the file, try rebooting your Nspire. It might be that the disk is still seen as in use. Few problems I have encountered: Figuring out how to use drop down menus is a hassle.
You need to keep clicking while dragging through the menu's. I recommend you to press 'tab' to toggle numpad control for the mouse. Then you can use the touchpad to move the mouse, and 5 to click. There is no "controls" section of the help.
Well, it does mention that you can use TAB to toggle numpad control, and ctrl to access the menu. The controls of Mac System 7 are out of the scope of the readme, it doesn't belong to the emulator. Rebooting/shutting down and turning back on causes the system to be unable to locate/read/initialize it's disk image. So rebooting is a nono.
When rebooting, System 7 ejects the disk. So when boot again, the disk will be gone. So this is perfectly normal behavior. I'll see if I can add a menu to mount disk images. That will always be handy. There are no save states, and instead of control, I suggest using a button like docs to pull up the emulator controls.
Well, I need to see if DOC allows you to press other keys simultaneously. If it does, then I'll definitely do the switch. Darn this is cool. I wonder if it's legal to distribute, though? Or has it become abandonware over the years?
I could always remove the disk and rom image if it could present problems (although I don't think so, for example os 7.0.1 is freely available). It would just be harder though for new users. By the way, does this include all 7.x systems and would it be able to run softwares from a Flash Drive like Linucx? Because Starcraft can run on Mac System 7.6 so I wonder if it could actually run it?  I suppose the fact that old versions requires the CD might be seriously problematic, though, unless there's a way to make a Flash drive act like a CD drive and have a game read from it. Normal all 7.x (and previous versions) should boot. However, there are PowerPC versions and 68k versions. This emulator is for 68k (68000 specifically), so you need to see if the software supports that. As for USB disk support, that's quite hard .. but it is possible with very very much work ;P
|
|
|
|
|
13
|
Omnimaga / News / Re: Mini vMac for the TI-Nspire
|
on: 13 April, 2013, 19:59:46
|
|
@Dapianokid, Stefan and I are brothers ^.^
I still need to work a bit on improving the speed, as that dropped slightly (although it's still very usable) when adding touchpad mouse control support.
|
|
|
|
|
15
|
Omnimaga / News / Re: Mini vMac for the TI-Nspire
|
on: 13 April, 2013, 19:06:38
|
Update everyone, there is a new version that has touchpad support! Now you can move the mouse easily around. Edit: (there is a ROM file in it.. isn't that illegal??)
As far as I understand, this isn't illegal were it's hosted now. Is there a way to make a bigger disk file? I'm having too much fun with this
http://minivmac.sourceforge.net/extras/blanks.htmlInstall Mini vMac on your computer, and migrate your disk to a bigger one (you can download empty disk images in the above link).
|
|
|
|
|
|