Jump to content

{1,2..., n*(n-1)/2 } -> {all the pairs in the {1,2...,n}}

- - - - -

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

#1
Bat0u89

Bat0u89

    Newbie

  • Members
  • PipPip
  • 25 posts
I need a function that would take a number from the first set and convert it to the corresponding pair in the second.
e.g. n=4 then the first set would be {1,...6} and the second: {{1,2},{1,3},{1,4},{2,3},{2,4},{3,4}}

Is there even an algorithm for that?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You'll have to define a canonical ordering for the second set (since sets don't have a concept of order).
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog