View unanswered posts | View active topics It is currently Sun Apr 21, 2019 8:20 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Prime Factorization of Positive Integers
Author Message
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 207
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Prime Factorization of Positive Integers
This is my code for factorizing a number input to the function and some code put around it. The function simply returns the smallest factor greater than one of its input (which is prime for any input other than 1 or 0), and the code repeatedly calls this function to determine the entire factorization of the number. My only problem is I don't know what I should use the function for other than math. Feel free to use it and tell me how you did so we can learn together.

 Code:short factor(long factand){   if(factand <= 1)   {      return factand;   }   else   {      short divisor;      bool isfactor = false;      for(divisor = 2;!isfactor;divisor++)      {         isfactor = (factand%divisor==0);      }      return divisor-1;   }}//------------------------------------------------------------------------------------------------------------------------//task main(){   string factorization;   string nextfactor;   short numtofactor = 30;// Change this number if you like. It's the number this code factorizes.   while(factor(numtofactor)>1)   {      factorization = factorization + "*";      StringFormat(nextfactor,"%d",factor(numtofactor));      factorization = factorization + nextfactor;      numtofactor /= factor(numtofactor);   }   StringDelete(factorization,0,1);   nxtDisplayCenteredTextLine(3,"%s",factorization);   while(nNxtButtonPressed == -1){}}

I don't even know if factand is a word!

-Coder A

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot

Mon Feb 11, 2013 5:41 pm
Rookie

Joined: Sun Nov 11, 2012 6:21 pm
Posts: 5
Re: Prime Factorization of Positive Integers
Recursive solutions are cool, but not the most efficient (if you deal with large numbers, you might run out of resources). Have you taken a look at Eratosthenes' sieve? It's pretty handy

Sat Jun 01, 2013 11:30 pm
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 207
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Re: Prime Factorization of Positive Integers
Actually, I am using an iterative approach. And Eratosthenes' sieve is neat, but not good for determining if just a single number is false, because you must determine all the primes lesser than the input number as well, which leads to memory issues, much in the same way a recursive algorithm would. But thanks for the comment!

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot

Thu Aug 22, 2013 6:15 pm
Professor

Joined: Sat May 18, 2013 1:24 pm
Posts: 271
Location: Olympia, WA
Re: Prime Factorization of Positive Integers
For starters, there's this: http://projecteuler.net/problems

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

Fri Aug 23, 2013 12:48 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning