Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:27:07+00:00 2026-06-01T19:27:07+00:00

I have these two functions: def comparison(a, b): return [-1, 0, 1].index(cmp(b, a)) def

  • 0

I have these two functions:

def comparison(a, b):
    return [-1, 0, 1].index(cmp(b, a))

def base_3(seq):
    return [comparison(a, b) for a, b in itertools.combinations(seq, 2)]

The function comparison returns a comparison number based on this:

  1. 0 if a > b
  2. 1 if a = b
  3. 2 if a < b

The function base_3 returns the comparison among all combined elements.

For instance:

x = [0, 1, 2]
y = [1, 2, 0]
z = [0, 1, 0]

>>> base_3(x)
[2, 2, 2]

>>> base_3(y)
[2, 0, 0]

>>> base_3(z)
[2, 1, 0]

I need a function that return a sequence from a given base_3, when possible:

>>> base_3_to_seq([2, 2, 2])
[0, 1, 2]

>>> base_3_to_seq([2, 1, 0])
[0, 1, 0]

>>> base_3_to_seq([0, 2, 1])
"Impossible"

How can I write this function base_3_to_seq?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:27:09+00:00Added an answer on June 1, 2026 at 7:27 pm

    This is a brute force way:

    def base_3_to_seq(base3):
       for seq in itertools.product(range(3), repeat=3):
           if base_3(seq) == base3:
               return seq
       return "Impossible"
    

    Depending upon which way you’re calling it most, you could speed the code up for long runs by memoizing either base_3 or base_3_to_seq.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions like the following: def fitnesscompare(x, y): if x.fitness>y.fitness: return 1
How can I combine these two functions into one recursive function to have this
I have these two functions (with Point2D & LineVector (has 2 Point2D member variables)
I have a class which is being operated on by two functions. One function
Are these two function declarations effectively different? If not, why do they have different
I have two def functions that I call in a nested fashion and want
So I have a numeric value and on those two functions can be applied.
If I have two byte[] arrays, is there a built-in function to compare them
I have these two modules : package G1; sub new { my $class =
I have these two classes public class Person { } public class Company {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.