Vote UpVote

Fun Code of the Week #6: Primality Checking

Nick Hodges –   I decided to give KhanAcademy a spin, and watched this set of videos:  Level 1: Primality Test And that let to me writing this code: function IsPrime(const x: integer): Boolean; var i: integer; begin i := 2; repeat if X mod i = 0 then begin Result := False; Exit; end; Inc(i); until i > Sqrt(x); Result := True; end; I know that this can be optimized (which I'll do if I end up watching the next video :-) ), but I don't often write really geeky code like this, so I thought I'd post it so you all can write lots of comments like you ...
Favorite? Off-Topic? nick@nickhodges.com @ 2012-10-28 00:02


Visits: 707
Votes: 2
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Alister Christie
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News


Please login or register to use this functionality.
(click on this box to dismiss)