4 kyu

Solving a puzzle by matching four corners

138 of 215tonylicoding
Description
Loading description...
Games
Performance
Puzzles
  • Please sign in or sign up to leave a comment.
  • brodiemark Avatar

    This comment has been hidden.

  • Luke_W_M Avatar

    Thanks for the kata Tony!

  • SolitudeRain Avatar

    This comment has been hidden.

  • Ryanman Avatar

    This was a great Kata. Similar to other solver feedback, named Tuples would have been a nice to have (but I think your approach seems very common on code wars). Another minor point of feedback is that I totally missed for an attempt or two the fact that puzzles can be rectangular. In hindsight, it's very obvious, since you have width and height variables, but with the square example I got a bit lost in the sauce. Finally, a very very minor grammatical point: In notes, I would change "Be careful about performances" to "Be careful about performance".

    A lot of the solutions I've seen were huge and/or O(n2), I believe this is solvable in O(n).

    Thanks for your work!

  • Shiv  Singh Avatar

    Great Kata!

  • hilechen Avatar

    Very nice and challenging kata! Took me a lot of thinking to solve this.

  • hladkky Avatar

    Thank you so much for this brainstorming kata. Through pain and suffering finally got it. It was a good experience for me.

  • docgunthrop Avatar

    @tonylicoding, Nice kata; do you plan to translate it to other languages?

  • Hana1989 Avatar

    Does each number appers only once (e.g. up to 4 times in one place in the puzzle)? I've just read the kata now so I will figure it out soon, but it should be mentioned... (You wrote thtat pieces are uniqe, but this is not the same)

  • hobovsky Avatar

    Is it guaranteed that each side of the puzzle has a border of Nones? Since all edges are unique, I don't think the border is really required for all puzzles. Will it be always there?

  • thalweg7 Avatar

    Good kata! I'm still working on it, but I wanted to point out an issue with the sample data given in the description: puzzle piece with id 8 does not match the output.

  • teoriachaosu Avatar

    May I ask for some little hint, as a beginner? What advanced topic (data structure or something) do I need to know to complete this?

  • hladkky Avatar

    All I do is just sequentially look for pieces. But still my code is too slow. Can you inspirate me by any ideas?

  • LittleFinchy Avatar

    My code runs for just over a second (1.2) in sublime with one of the larger tests. It gets the right answer but it wont pass the Kata tests. I have no idea how to optimize it. I probably need another approach.

  • milg15 Avatar

    Any tips on improving time? I already have a solution but it's too slow.

  • G_kuldeep Avatar

    kata is nice :)

    small suggestion though; replace length with height (more suitable but still a matter of test)

    edit: about perf., you should add perf. (as B$B said) to make it 4

  • Blind4Basics Avatar

    should we enforce performances requirements...?

    I tried using this:

        @test.it('Pure random tests')
        def other_random_tests():
            X = 100
            vals = list(range(X*X))
            ids  = list(range(X*X))
            
            def create_random():
                w,h = (random.randint(2, X) for _ in range(2))
                ...
                
                
            for _ in range(100):
                check(1, *create_random())             
    

    my solution solves the tests in roughly 6-8s, every other ones are timing out, so far (like... really every other ones...)

  • G_kuldeep Avatar

    how to solve puzzle? do i have to arrange puzzle such that 2X2 sub puzzle match all numbers?

  • Blind4Basics Avatar

    hi,

    I didn't actually try yet but you need to clarify the description. All the needed information is in there, but the order is clearly suboptimal, especially considering the length of it. The main problem is that you lose the reader by adding details before giving the main parts. I cannot be more precise right now (need to go to sleep), but this is mainly about splitting the description differently.

    another problem: the representation if the pieces seems suboptimal too. am object would be cool, but you'll have mutation troubles. A namedtuple would be better, on the other hand: namedtuple('Piece','val idx'), for example.

    note: don't close this too quickly, plz. I won't be around for a of time to develop about all of this.