Swift 3 Challenge 4: Being Cool


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.



2 thoughts on “Swift 3 Challenge 4: Being Cool

  1. Why do you use the ternary operator here? Everything before the question mark is already giving you the Bool you need 😉

    By the way, if you would hypothetically need this often in your App, I’d even suggest the following which is more readable in the end:

    extension Int {
    var isCool: Bool {
    return (self % 11 == 0) || (self % 11 == 1)

    22.isCool // true
    23.isCool // true
    24.isCool // true

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 )

Facebook photo

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

Connecting to %s