Flip and Mirror numbers

flip number display
pick 3 rundown
pick 3 worksheet
lottery predictor
pick 4
cash 3
lottery post
ga lottery

I have just picked up an interview question from the Internet and practicing with Swift.

Question is as follows:

Given an input of an array of string, verify if, turned 180 degrees, it is the "same".

For instance:

[1, 6, 0, 9, 1] => return true 
[1, 7, 1] => return false

I have come up with the following approach which I put mirroring numbers in the dictionary and check whether or not if any number in the given array do not match with dictionary numbers.

It seems it works with basic test cases, but I wonder if I am missing anything ?

func checkRotation (nums : [Int]) -> Bool
{
    var dict = [Int : Int]()
    dict  = [0:0, 1:1, 2:5, 5:2, 6:9, 8:8, 9:6]

    for n in nums
    {
        guard let exist = dict[n] else
        {
            return false
        }
    }
    return true
}
extension Collection where Element == Int {
    func isFlipMirrored() -> Bool {
        let mirrors = [0:0, 1:1, 6:9, 8:8, 9:6]
        return zip(self, self.reversed()) // Create tuples of each element and its opposite
            .allSatisfy {                 // Return whether all of them match the rule:
                mirrors[$0] == $1         // That the element matches its opposite's mirror
        }
    }
}

This isn't as efficient as it could be, but it's very simple and to the point. It just verifies that each element of the sequence is the same as the mirrored elements in the reverse order.

It could be more efficient to only check the first half of the elements, but it's a pretty minor optimization that requires extra conditionals, so I'm not sure if it would really be faster for reasonably small N. You'd need to profile before complicating the code too much.

Of course, just because it's not actually slower (i.e. I haven't profiled it to know), that doesn't mean that an interviewer won't baulk at the fact that this code makes redundant checks. There are a lot of misunderstandings about performance, and they all seem to show up in interview questions. So, let's make the interviewer happy and only check the first half of the list against the last half.

extension Collection where Element == Int {
    func isFlipMirrored() -> Bool {
        let mirrors = [0:0, 1:1, 6:9, 8:8, 9:6]

        // May test one more thing than we technically have to, but fewer conditionals
        let midpoint = count / 2 + 1

        return zip(self.prefix(midpoint),             // Create tuples of the left-half of the list,
                   self.reversed().prefix(midpoint))  //    and the right half
            .allSatisfy {                 // Return whether all of them match the rule:
                mirrors[$0] == $1         //     that the element matches its opposite's mirror
        }
    }
}

Mirrors, played 6 numbers day before, used Flip numbers..I will try mirror next.Duration: 6:06 Posted: Jan 9, 2019 1. Draw 2 four by four grids side by side. 2. Lookup the last 4 drawing result for the pick 4 lottery you want to do the rundown for. 3. Place these results into the grid on the left. The latest result goes on the top line. Place the other 3 results in 4. Use the following lookup chart to find

Today I walk through a new pick 4 lottery system that includes sums, flip numbers​, and mirror Duration: 15:06 Posted: Mar 18, 2019 Flip and Mirror numbers. Ask Question Asked 1 year, 4 months ago. Active 1 year, 4 months ago. Viewed 397 times -1. I have just picked up an interview question from

My approach would be to use prefix to limit the data set and enumerated to enumerate over indexes and values simultaneously. Throw in lazy so you don't make lots of array copies and only process what's relevant.

extension Array where Element == Int {
    func isMirrored() -> Bool {
        let flipped = [0:0, 1:1, 2:5, 5:2, 6:9, 8:8, 9:6]

        return lazy                         // means we won't make 3 copies of arrays
            .prefix((count + 1) / 2)        // stops the enumeration at the midway point
            .enumerated()                   // enumerates over (index, value)
            .allSatisfy { (index, value) in // verify all elements meet the criteria below

            // make sure each reversed element matches it's flipped value
            // Note you don't have to explicitly check for nil, since
            // '==' works on Optional<Int>
                return flipped[value] == self[count - index - 1]
            }
    }
}

[1, 6, 0, 9, 1].isMirrored()
[1, 7, 1].isMirrored()

This rundown is just like the Pick 3 flip numbers rundown just with a few more numbers. I use Duration: 6:47 Posted: Jan 21, 2019 Today I walk through a new pick 4 lottery system that includes sums, flip numbers, and mirror numbers. I combine these lottery factors to come up with some pick 4 numbers you can use in the

I have some issues with your code, which I've annotated below:

func checkRotation /* Why the space here? */ (nums /* Why the space here? */ : [Int]) -> Bool
{ // Brackets like this aren't Swift's code style
    // Dict is a horrible name. I can see that it's a dictionary. What is it a dict *of*?!
    var dict = [Int : Int]() // Why is this a `var` variable, that's assigned an empty initial value
    dict  = [0:0, 1:1, 2:5, 5:2, 6:9, 8:8, 9:6] // only to be immediately overwritten?

    for n in nums // This should be a `contains(_:)` call, rather than explicit enumeration
    {
        // If you're not using a `contains(_:)` check, you should at least use a `where` clause on the for loop
        guard let exist = dict[n] else // "exist" is a bad variable name, and it's not even used. Replace this with a `dict[n] != nil` check.
        {
            return false
        }
    }
    return true
}

Here is how I would write it in a similar way:

func checkRotation(nums: [Int]) -> Bool {
    let mirroredDigits = [0:0, 1:1, 2:5, 5:2, 6:9, 8:8, 9:6]

    for n in nums where mirroredDigits[n] == nil {
        return false
    }
    return true
}

Much the same as the mirror number rundown, the flip number rundown relies on simple Duration: 6:06 Posted: Jan 10, 2019 993 using the 993 as a base number you +1 starting with the 3 . 765. 894. 993. box 3 he mirror his base number. 660=115 in box three the 115 is the base number and you +1 starting with the 5. 987

You can try

func checkRotation (nums : [Int]) -> Bool
{
    var dict = [0:0, 1:1, 2:5, 5:2, 6:9, 8:8, 9:6]
    return nums.filter{ dict[$0] != nil }.count == nums.count

}

Or

func checkRotation (nums : [Int]) -> Bool
{
    var dict = [0:0, 1:1, 2:5, 5:2, 6:9, 8:8, 9:6]
    return nums.compactMap{ dict[$0]}.count == nums.count

}

Use Mirror #'s Use prs. with your Key* numbers the most Vivid thing in your dream go up or down on #'s. Flip 6=9 `9=6 Bullseyes 0 or 1 for Pick  Today I walk through how to do a Pick 3 lottery strategy using the +1 and -1 tic tac toe rundown with mirror numbers. I use the Georgia Midday Pick 3 lottery as an example and step through how to

First write down the mirror numbers: 0 - 5 1 - 6 2 - 7 3 - 8 4 - 9. Next, Write down last drawn number (in this case we'll write 905). 9..0..5. Unicode text tools for generating portable effects like anti-surveillance, reversing words, flipping text, mirror words, reducing text, and text shrinking. A secret encoder/decoder for sending private messages in public places like Facebook and Twitter.

How to Win Pick 4 Strategy - Mirror Number Lotto Strategy!!! Increase your odds of winning pick 4 with this box strategy!!! This works for cash 4, daily 4, play 4,  Occasionally you need a ‘reverse’ ‘mirror’ or ‘flip’ effect in a Word document. When people say those terms they can mean different things so we’ll look at many options and how to do them. Let’s start with an easy one. A mirror / reflection effect like this ‘Half Reflection – touching’ preset.

extension Collection where Element == Int { func isFlipMirrored() -> Bool { let mirrors = [0:0, 1:1, 6:9, 8:8, 9:6] return zip(self, self.reversed())  The Importance Of Playing Flip And/or Mirrow Numbers Budget Flip Clock Flip Out 14:36. Pick 3 Rundown With Mirror Numbers For The Illinois Lottery - Duration: 5:34. Lottery

Comments
  • This belongs on codereview.stackexchange.com.
  • @RobNapier, this question is being asked by Facebook and Google. I even remember that this question was being asked before by one of the company that I had interview before.
  • [1, 0, 9, 1] shouldn't work. if "exist", check the value of "n" at nums[n-indexOfIt].
  • Yeah; Facebook and Google are pretty notorious about horrible interview questions.
  • Also you only need to go until the half size of the array + "center" (if count is even).
  • could you please add extra comment on zip(self, self.reverse()).allsatisfy{} line. It is high order method and very very compact and quite impressing!
  • Your mirrors is missing 2:5.
  • @hotspring You should break it down. Play around with zip first, see what it does, then play around with allSatisfy, and then see what happens when you combine the two together.
  • Yes, because count / 2 + 1 is 2 (integer math), so it's going to check [1, 7] against [7, 1]. It will fail on the first test
  • In my 30 years of professional programming, I've never passed a whiteboard interview, so you probably can't take my advice on these things. :D
  • could you please add your solution here?
  • @hotspring Added working Python example to demonstrate approach
  • Please check @Larme comments, it seems we both are missing the case. I have up-voted your effort. By the way, thanks a lot for commenting out on my code as well. it is really valuable.
  • could you please add a short explanation? It seems you are filtering numbers in the given array with a set of key(dict) and checking whether or not we have same input array length. why did you use compactMap operation?
  • Please check @Larme comments, it seems we both are missing the case. I have up-voted your effort.