Skip to content

Instantly share code, notes, and snippets.

@IwoHerka
Last active October 23, 2020 18:19
Show Gist options
  • Save IwoHerka/5e94a97f7bdc7145f582b9be9ecf83cc to your computer and use it in GitHub Desktop.
Save IwoHerka/5e94a97f7bdc7145f582b9be9ecf83cc to your computer and use it in GitHub Desktop.
Python Exercises - Lab 1
# 1. "SUPERSIZE ME.... or rather, this integer!"
# Write a function that rearranges an integer into its largest possible value.
super_size(123456) == 654321
super_size(105) == 510
super_size(12) == 21
# If the argument passed through is single digit or is already the maximum
# possible integer, your function should simply return it.
#
# Hint: You can use function 'reverse', 'sort' and 'join' method on
# string object.
#
# Source: https://www.codewars.com/kata/5709bdd2f088096786000008
# 2. "Sum of positive"
# You get an array of numbers, return the sum of all of the positives ones.
# Example
[1,-4,7,12] == 1 + 7 + 12
# Note: if there is nothing to sum, the sum is default to 0.
# Source: https://www.codewars.com/kata/5715eaedb436cf5606000381
# 3. "Unique in order"
# Implement the function unique_in_order which takes as argument a sequence
# and returns a list of items without any elements with the same value next
# to each other and preserving the original order of elements.
# For example:
unique_in_order('AAAABBBCCDAABBB') == ['A', 'B', 'C', 'D', 'A', 'B']
unique_in_order('ABBCcAD') == ['A', 'B', 'C', 'c', 'A', 'D']
unique_in_order([1,2,2,3,3]) == [1,2,3]
# How can you modify this solution to remove duplicated letters at
# later positions?
#
# Source: https://www.codewars.com/kata/54e6533c92449cc251001667
# 4. Rock-paper-scissors!
# Let's play! You have to return which player won!
# In case of a draw return "Draw!".
# Examples:
rps('scissors','paper') == "Player 1 won!"
rps('scissors','rock') == "Player 2 won!"
rps('paper','paper') == "Draw!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment