Swift 3 Challenge 4: Being Cool

cool-wallpaper-1

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:

Challenge-4-Test-Cases

Try this before you look at my solution.

Seriously – try it yourself.

Last chance.

Okay – here is my solution.

Challenge-4-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.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s