+11

[challenge] Sort a string with special rules

Given a string with numbers and characters. Sort that string so that characters are sorted in ascending order and numbers in descending order. characters and numbers as groups keep their places. Example a1bc32 -> a3bc21 Have Fun

2/13/2018 5:23:14 AM

Oma Falk

23 Answers

New Answer

+14

https://code.sololearn.com/cFLP6L5kmheL/?ref=app

+7

example solution python https://code.sololearn.com/c1E10EEa90hz

+6

My try is here, thanks @VcC for table idea https://code.sololearn.com/cI07NUjpY4RU/?ref=app

+5

@Tim... I was born in the sixties(-;

+5

https://code.sololearn.com/cpNY5BmPDwnq/?ref=app

+5

My try here https://code.sololearn.com/c1fr6G5qNiqg/?ref=app

+4

how about symbols? Should they come before or after letters?

+4

@jonathan treat symbols like characters. We have two groups: numbers/nonNumbers

+4

Tried now in Kotlin https://code.sololearn.com/cFwKd8WkcKGr

+3

heres it...just hurried so its not a one liner https://code.sololearn.com/cC8LRFqUhy46/?ref=app

+3

@Oma In your question you say "characters and numbers as groups keep their places." yet in the example you show Example a1bc32 -> a3bc21 is 32 not a number group?

+3

https://code.sololearn.com/cP79Z4YfwdfH/?ref=app

+2

this is your homework?

+2

@VcC How will this keep numbers on a number place?

+1

So I just have to follow their ascii values?

+1

the code now uses only one array... bit smaller##edited

+1

@vcc it is a bit tricky.,,

+1

@oma use a table giving the priority of ezch char then key=lambda c:table.index(c)

+1

Simple commented code. Would love comments =) https://code.sololearn.com/c3a58v5cke0b/?ref=app

+1

My version: https://code.sololearn.com/cvrlWfScxpo2/?ref=app