-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd0ace5
commit 1d622d2
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Two non-negatives integers are called siblings if they can be obtained from each other | ||
# by rearranging the digits of their decimal representations. For example, 123 and 213 are siblings | ||
# 535 and 355 are also siblings. | ||
|
||
# A set consisting of a non-negative integer N and all of its siblings is called the | ||
# of N. For example, the family of 553 comprises three numbers: 355, 535 and 553. | ||
|
||
# Write a function: | ||
# def solution(n) | ||
|
||
# that, given a non-negative integer N, returns the largest number in the family of N. | ||
# For example, given N = 213 the function should return 321. Given N = 553 the function should return 553. | ||
# Assume that: | ||
# N is an integer within the range [0..10,000]. | ||
# In your solution, focus on correctness, . The performance of your solution will not be the focus of the assessment. | ||
|
||
# Wellington Avelino | ||
|
||
def solution(n) | ||
siblings = n.to_s.chars.each_slice(1).to_a | ||
siblings.sort {|x,y| -(x <=> y)}.join.to_i | ||
end |