function unique_in_order(iterable){ return iterable.split("").filter((x,i) => x!==iterable.split("")[i+1]); }
def unique_in_order(iterable):iterable = list(iterable)while 1==1:for x in range(len(iterable)):if iterable[x]==iterable[x-1]:del iterable[x]breakif x==len(iterable)-1:return iterable- function unique_in_order(iterable){
- return iterable.split("").filter((x,i) => x!==iterable.split("")[i+1]);
- }
Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B']) Test.assertEquals(unique_in_order('44444455321111'), ['4','5','3','2','1']) Test.assertEquals(unique_in_order('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B']) Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B']) Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDAABBB'), ['A','B','C','D','A','B']) Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B']) Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCsssCCCCCCCCCCCCCDAABBB'), ['A','B','C','s', 'C','D','A','B'])
test.assert_equals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])test.assert_equals(unique_in_order('44444455321111'), ['4','5','3','2','1'])test.assert_equals(unique_in_order('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])test.assert_equals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])test.assert_equals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDAABBB'), ['A','B','C','D','A','B'])test.assert_equals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])test.assert_equals(unique_in_order('AAAABBBCCCCCCCCCCCsssCCCCCCCCCCCCCDAABBB'), ['A','B','C','s', 'C','D','A','B'])- Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])
- Test.assertEquals(unique_in_order('44444455321111'), ['4','5','3','2','1'])
- Test.assertEquals(unique_in_order('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])
- Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])
- Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDAABBB'), ['A','B','C','D','A','B'])
- Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCCCCCCCCCCCCCCDAABBB'), ['A','B','C','D','A','B'])
- Test.assertEquals(unique_in_order('AAAABBBCCCCCCCCCCCsssCCCCCCCCCCCCCDAABBB'), ['A','B','C','s', 'C','D','A','B'])
traversed using streams instead of for loops
import java.util.*; public class Kumite { public static String highAndLow(String numbers) { Object maxValue = Arrays.stream(numbers.split(" ")) .filter(n -> Arrays.stream(numbers.split(" ")) .noneMatch(n2 -> Integer.parseInt(n2)>Integer.parseInt(n))).toArray()[0]; Object minValue = Arrays.stream(numbers.split(" ")) .filter(n -> Arrays.stream(numbers.split(" ")) .noneMatch(n2 -> Integer.parseInt(n2)<Integer.parseInt(n))).toArray()[0]; return maxValue +" "+minValue; } }
- import java.util.*;
- public class Kumite {
- public static String highAndLow(String numbers) {
String[] integerStrings = numbers.split(" ");int maxValue = Integer.parseInt(integerStrings[0]);int minValue = Integer.parseInt(integerStrings[0]);for (int i = 1; i < integerStrings.length; i++){int number = Integer.parseInt(integerStrings[i]);if(number > maxValue){maxValue = number;}if(number < minValue){minValue = number;}}return Integer.toString(maxValue) + " " + Integer.toString(minValue);- Object maxValue = Arrays.stream(numbers.split(" "))
- .filter(n -> Arrays.stream(numbers.split(" "))
- .noneMatch(n2 -> Integer.parseInt(n2)>Integer.parseInt(n))).toArray()[0];
- Object minValue = Arrays.stream(numbers.split(" "))
- .filter(n -> Arrays.stream(numbers.split(" "))
- .noneMatch(n2 -> Integer.parseInt(n2)<Integer.parseInt(n))).toArray()[0];
- return maxValue +" "+minValue;
- }
- }