Swift 3 Challenge 4: Being Cool

Datetime:2016-08-23 04:15:16          Topic: Swift           Share

Today’s code challenge is about being cool.

Problem Description:

A number is cool if it’s a multiple of 11 or if it is one more than a multiple of 11.

Return true if the given non-negative number is cool.

Test Cases:

Try this before you look at my solution.

Seriously – try it yourself.

Last chance.

Okay – here is my solution.

Here is the Ternary Operator again with a modulus operator used twice making it another one-liner.

Either condition would make the number a multiple of 11 or one more than a multiple of 11.

You can view my solution at the IBM Swift Sandbox.





About List