Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Even/Odd permutation
#5
def is_even(p):
  i = 0
  count = 0
  while(i < len(p)):
    k = i + 1
    while(k < len(p)):
      if(p[i] > p[k]):
        count+=1
      k+=1
    i+=1
  if(count == 0):
    return True
  if(count % 2 == 0):
    return True
  else:
    return False
Here is some solution. Could it be done better? Yes.
:)

This is my first code in python ever, so I was kind of 'scared'.
Reply


Messages In This Thread
Even/Odd permutation - by braankoo - Jul-17-2018, 06:00 PM
RE: Even/Odd permutation - by Larz60+ - Jul-17-2018, 06:04 PM
RE: Even/Odd permutation - by braankoo - Jul-17-2018, 06:08 PM
RE: Even/Odd permutation - by buran - Jul-17-2018, 06:16 PM
RE: Even/Odd permutation - by braankoo - Jul-18-2018, 12:11 AM
RE: Even/Odd permutation - by Larz60+ - Jul-18-2018, 01:10 AM
RE: Even/Odd permutation - by buran - Jul-18-2018, 06:44 AM
RE: Even/Odd permutation - by kingjacob1515 - Jan-09-2021, 07:38 PM
RE: Even/Odd permutation - by braankoo - Jul-18-2018, 12:27 PM
RE: Even/Odd permutation - by Larz60+ - Jan-10-2021, 01:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to print each possible permutation in a dictionary that has arrays as values? noahverner1995 2 1,866 Dec-27-2021, 03:43 AM
Last Post: noahverner1995
  memory error using permutation list of 11 elements kikidog 1 3,997 Sep-10-2019, 08:22 PM
Last Post: ichabod801
  how to get all the possible permutation and combination of a sentence in python sodmzs 1 4,259 Jun-13-2019, 07:02 AM
Last Post: perfringo
  Calling list() on permutation trevorkavanaugh 2 2,480 Mar-01-2019, 06:00 AM
Last Post: trevorkavanaugh
  Permutation help. jarrod0987 1 2,256 Jun-28-2018, 04:44 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020