Jump to content

Writing a procedure in Scheme

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
john galt

john galt

    Newbie

  • Members
  • Pip
  • 1 posts
I need to Write a procedure (ways-to-factor n m) that computes the number of different ways in which n can be represented as a product of integers, each of them is at least m. A factor may appear more than once in the representation, and the order of the factor doesn’t matter, and n and m are positive integers.

For example:


> (ways-to-factor 4 3)
0
> (ways-to-factor 8 2)
2
> (ways-to-factor 8 8)
0
> (ways-to-factor 1 1)
1



I'm very new at this, so I don't know how to this/

Thanks for any kind of help...

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Well, to start with, can you get the above answers by hand? Can you write down how you're doing them?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Soupdude

Soupdude

    Newbie

  • Members
  • Pip
  • 4 posts
eh...,sry if i don't understand xP, so my guess here is, you want to say something like

how many different ways can i arrive at the number N, by multiplying unknown numbers where either one of the two unknown numbers has to be m, (or both) ?

edit:
my bad, i was assuming that there would only be 2 unknown numbers to multiply, but 1 of those numbers have to be M ?, in that case, your example of:

(ways-to-factor 8 2)

would be:

1) 4 x m 2) m x m x m (if m = 2)

my guess for solving this would be to see how many times one can divide N by M, and count them up, although haven't gone too deeply into this, as im not even sure if thats wat u want :S

Edited by Soupdude, 09 November 2009 - 02:56 PM.
further suggesting


#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Factorings of 8 are:
2x2x2
2x4
1x8 -> invalid, uses 1<2

Now try 36 3 :)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog