+ 2

Pattern challenge : Enter 5 numbers if the largest is bigger than the sum of the two smallest number then print a triangle else

-else print an inverted triangle. the number in triangle is largest one if you've a duplicated numbers u use them unless all are the same.in this case print a flat line šŸ˜ƒ. Input: 12345 Output: 5 55 555 5555 55555 Input:37691 Output: 9 99 999 9999 99999 999999 9999999 99999999 999999999 Input:34563 Output: 666666 66666 6666 666 66 6 Input:67548 Output: 88888888 8888888 888888 88888 8888 888 88 8 You can use your numbers .

5th Oct 2017, 7:13 AM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar
11 Answers
5th Oct 2017, 9:44 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 8
Could you please clarify the case for duplicate numbers? Beisdes that, the number in triangle would always be the largest number except the orientation. Am I right?
5th Oct 2017, 7:19 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
@ChaoticDawg I see, maybe it's just me confused with the requirements. I've done in the folowing way: s1 + s2 = largest ( Flat line ) s1 + s2 < largest ( Normal triangle ) s1 + s2 > largest ( Inverrted triangle ) Let's wait for the confirmation from the OP.
6th Oct 2017, 2:48 AM
Zephyr Koo
Zephyr Koo - avatar
+ 7
Just my opinion, how about printing a flat line if both numbers are equal?
5th Oct 2017, 7:40 AM
Zephyr Koo
Zephyr Koo - avatar
+ 7
Here's my C# implementation! āœŒ LINQ One-Liner怰 Enumerable.Range(1, digit - 1) .Select(n => ( isInverted ? n * (2 * digit - n + 1) / 2 : n * (n + 1) / 2) + 2 * (n - 1)) .ToList() .ForEach(i => str = str.Insert(i, "\n")); I doubt this is not the recommended way to solve the challenge as I've abused LINQ with side-effect this time. This solution relies on formula for inserting new line into the string to form the triangle since the number occurences are the same for all 3 cases. Enjoy~ ā¤ https://code.sololearn.com/c9R26iY77gdF/?ref=app
6th Oct 2017, 8:11 AM
Zephyr Koo
Zephyr Koo - avatar
+ 5
I'm almost done now. Can I confirm the output for 34563? Isn't it a straight line since 3 + 3 = 6?
6th Oct 2017, 2:33 AM
Zephyr Koo
Zephyr Koo - avatar
+ 3
nums = list(input("Input 5 digit number: ")).sort() print() high, low1, low2 = int(nums[-1]), int(nums[0]), int(nums[1]) if high == low1: [print(high, end='') for _ in range(high)] elif (low1 + low2) >= high: for i in range(high): [print(high, end='') for _ in range(high-i)] print() else: for i in range(high): [print(high, end='') for _ in range(i)] print()
5th Oct 2017, 8:58 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
@Zephyr I read it as if all the values are equal then print them on a line. So if the smallest number is the same as the largest. For 34563 the example shows it to be an inverted triangle. So if the 2 smallest numbers are equal to or greater than, then print it as an inverted triangle.
6th Oct 2017, 2:37 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
@zephyr s1+s2 < largest (normal triangle) s1+s2 >= largest (inverted triangle) n1=n2=n3=n4=n5 (flat line )
6th Oct 2017, 7:17 AM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar
0
edited
5th Oct 2017, 7:32 AM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar
0
šŸ‘šŸ‘Œ
5th Oct 2017, 7:58 AM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar