Hide the buildings












15














Shorter version of Skyscrapers Challenge



Task



Given an array of building heights and a positive integer k, find all the permutations(without duplicates) of the heights such that exactly k buildings are visible.



Any building will hide all shorter or equal height buildings behind it.



Any format for input and output is valid.



Input array will never be empty.



In case it is not possible to see exactly as many buildings, output anything that cannot be an answer but no error.



Examples:



(Length of output is shown for very long outputs,but your output should be all possible permutations)



input:[1,2,3,4,5],2
output: 50

input:[5,5,5,5,5,5,5,5],2
output:

input:[1,2,2],2
output:[(1,2,2)]
Seeing from the left, exactly 2 buildings are visible.

input:[1,7,4],2
output:[(4, 7, 1), (1, 7, 4), (4, 1, 7)]

input:[1,2,3,4,5,6,7,8,9],4
output:67284

input:[34,55,11,22],1
output:[(55, 34, 11, 22), (55, 22, 34, 11), (55, 34, 22, 11), (55, 11, 34, 22), (55, 22, 11, 34), (55, 11, 22, 34)]

input:[3,4,1,2,3],2
output:31


This is code-golf so shortest code wins



Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.










share|improve this question
























  • Should the output be all qualifying permutations, or the number thereof?
    – Luis Mendo
    Nov 15 '18 at 6:49










  • It should be all qualifying permutations @LuisMendo
    – Vedant Kandoi
    Nov 15 '18 at 6:54










  • Suggested test case: [1,2,3,4,5],5 -> [(1,2,3,4,5)]. None of the current test cases ensure that answers can support showing all buildings (though I don't know whether any actually have a problem with that).
    – Kamil Drakari
    Nov 15 '18 at 15:27
















15














Shorter version of Skyscrapers Challenge



Task



Given an array of building heights and a positive integer k, find all the permutations(without duplicates) of the heights such that exactly k buildings are visible.



Any building will hide all shorter or equal height buildings behind it.



Any format for input and output is valid.



Input array will never be empty.



In case it is not possible to see exactly as many buildings, output anything that cannot be an answer but no error.



Examples:



(Length of output is shown for very long outputs,but your output should be all possible permutations)



input:[1,2,3,4,5],2
output: 50

input:[5,5,5,5,5,5,5,5],2
output:

input:[1,2,2],2
output:[(1,2,2)]
Seeing from the left, exactly 2 buildings are visible.

input:[1,7,4],2
output:[(4, 7, 1), (1, 7, 4), (4, 1, 7)]

input:[1,2,3,4,5,6,7,8,9],4
output:67284

input:[34,55,11,22],1
output:[(55, 34, 11, 22), (55, 22, 34, 11), (55, 34, 22, 11), (55, 11, 34, 22), (55, 22, 11, 34), (55, 11, 22, 34)]

input:[3,4,1,2,3],2
output:31


This is code-golf so shortest code wins



Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.










share|improve this question
























  • Should the output be all qualifying permutations, or the number thereof?
    – Luis Mendo
    Nov 15 '18 at 6:49










  • It should be all qualifying permutations @LuisMendo
    – Vedant Kandoi
    Nov 15 '18 at 6:54










  • Suggested test case: [1,2,3,4,5],5 -> [(1,2,3,4,5)]. None of the current test cases ensure that answers can support showing all buildings (though I don't know whether any actually have a problem with that).
    – Kamil Drakari
    Nov 15 '18 at 15:27














15












15








15


1





Shorter version of Skyscrapers Challenge



Task



Given an array of building heights and a positive integer k, find all the permutations(without duplicates) of the heights such that exactly k buildings are visible.



Any building will hide all shorter or equal height buildings behind it.



Any format for input and output is valid.



Input array will never be empty.



In case it is not possible to see exactly as many buildings, output anything that cannot be an answer but no error.



Examples:



(Length of output is shown for very long outputs,but your output should be all possible permutations)



input:[1,2,3,4,5],2
output: 50

input:[5,5,5,5,5,5,5,5],2
output:

input:[1,2,2],2
output:[(1,2,2)]
Seeing from the left, exactly 2 buildings are visible.

input:[1,7,4],2
output:[(4, 7, 1), (1, 7, 4), (4, 1, 7)]

input:[1,2,3,4,5,6,7,8,9],4
output:67284

input:[34,55,11,22],1
output:[(55, 34, 11, 22), (55, 22, 34, 11), (55, 34, 22, 11), (55, 11, 34, 22), (55, 22, 11, 34), (55, 11, 22, 34)]

input:[3,4,1,2,3],2
output:31


This is code-golf so shortest code wins



Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.










share|improve this question















Shorter version of Skyscrapers Challenge



Task



Given an array of building heights and a positive integer k, find all the permutations(without duplicates) of the heights such that exactly k buildings are visible.



Any building will hide all shorter or equal height buildings behind it.



Any format for input and output is valid.



Input array will never be empty.



In case it is not possible to see exactly as many buildings, output anything that cannot be an answer but no error.



Examples:



(Length of output is shown for very long outputs,but your output should be all possible permutations)



input:[1,2,3,4,5],2
output: 50

input:[5,5,5,5,5,5,5,5],2
output:

input:[1,2,2],2
output:[(1,2,2)]
Seeing from the left, exactly 2 buildings are visible.

input:[1,7,4],2
output:[(4, 7, 1), (1, 7, 4), (4, 1, 7)]

input:[1,2,3,4,5,6,7,8,9],4
output:67284

input:[34,55,11,22],1
output:[(55, 34, 11, 22), (55, 22, 34, 11), (55, 34, 22, 11), (55, 11, 34, 22), (55, 22, 11, 34), (55, 11, 22, 34)]

input:[3,4,1,2,3],2
output:31


This is code-golf so shortest code wins



Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.







code-golf permutations






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 7:23







Vedant Kandoi

















asked Nov 15 '18 at 6:34









Vedant KandoiVedant Kandoi

1,073226




1,073226












  • Should the output be all qualifying permutations, or the number thereof?
    – Luis Mendo
    Nov 15 '18 at 6:49










  • It should be all qualifying permutations @LuisMendo
    – Vedant Kandoi
    Nov 15 '18 at 6:54










  • Suggested test case: [1,2,3,4,5],5 -> [(1,2,3,4,5)]. None of the current test cases ensure that answers can support showing all buildings (though I don't know whether any actually have a problem with that).
    – Kamil Drakari
    Nov 15 '18 at 15:27


















  • Should the output be all qualifying permutations, or the number thereof?
    – Luis Mendo
    Nov 15 '18 at 6:49










  • It should be all qualifying permutations @LuisMendo
    – Vedant Kandoi
    Nov 15 '18 at 6:54










  • Suggested test case: [1,2,3,4,5],5 -> [(1,2,3,4,5)]. None of the current test cases ensure that answers can support showing all buildings (though I don't know whether any actually have a problem with that).
    – Kamil Drakari
    Nov 15 '18 at 15:27
















Should the output be all qualifying permutations, or the number thereof?
– Luis Mendo
Nov 15 '18 at 6:49




Should the output be all qualifying permutations, or the number thereof?
– Luis Mendo
Nov 15 '18 at 6:49












It should be all qualifying permutations @LuisMendo
– Vedant Kandoi
Nov 15 '18 at 6:54




It should be all qualifying permutations @LuisMendo
– Vedant Kandoi
Nov 15 '18 at 6:54












Suggested test case: [1,2,3,4,5],5 -> [(1,2,3,4,5)]. None of the current test cases ensure that answers can support showing all buildings (though I don't know whether any actually have a problem with that).
– Kamil Drakari
Nov 15 '18 at 15:27




Suggested test case: [1,2,3,4,5],5 -> [(1,2,3,4,5)]. None of the current test cases ensure that answers can support showing all buildings (though I don't know whether any actually have a problem with that).
– Kamil Drakari
Nov 15 '18 at 15:27










9 Answers
9






active

oldest

votes


















6















05AB1E, 10 9 bytes



œÙʒη€àÙgQ


Try it online or verify (almost) all test cases (test case [1,2,3,4,5,6,7,8,9],4 times out).

Footer of the TIO does what OP asked at the bottom:




Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.




Explanation:





œ            # Permutations of the (implicit) input-list
# i.e. [1,2,2] → [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
Ù # Only leave the unique permutations
# i.e. [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
# → [[1,2,2],[2,1,2],[2,2,1]]
ʒ # Filter it by:
η # Push the prefixes of the current permutation
# i.e. [1,2,2] → [[1],[1,2],[1,2,2]]
ۈ # Calculate the maximum of each permutation
# i.e. [[1],[1,2],[1,2,2]] → [1,2,2]
Ù # Only leave the unique maximums
# i.e. [1,2,2] → [1,2]
g # And take the length
# i.e. [1,2] → 2
Q # And only leave those equal to the second (implicit) input
# i.e. 2 and 2 → 1 (truthy)





share|improve this answer



















  • 1




    Impressive, every single byte here is part of the function tree!
    – lirtosiast
    Nov 15 '18 at 9:23






  • 1




    @lirtosiast Yeah, 05AB1E has some pretty short builtins sometimes, which were perfect in this challenge. :) It's actually very similar to your Pyth answer I see. Funny thing is, is that the footer for if length is greater than 20: print length; else print answer; is a̶ ̶b̶y̶t̶e̶ ̶l̶o̶n̶g̶e̶r̶ of equal length in comparison to the program itself. xD
    – Kevin Cruijssen
    Nov 15 '18 at 9:25





















5














Haskell, 73 bytes



import Data.List
f n=filter((n==).length.nub.scanl1 max).nub.permutations


Try it online!






share|improve this answer





























    5















    Jelly, 12 10 bytes



    Œ!Q»QL=ʋƇ


    Try it online!



    -2 bytes by @Erik the Outgolfer



    This is a dyadic function taking the building heights and k in that order.



    Œ!                All permutations of first input
    Œ!Q Unique permutations of first input
    » Running maximum
    Q Unique values
    L Length of this array
    = Equals k
    ʋ Create a monad from these 4 links
    »QL=ʋ "Are exactly k buildings visible in arrangement x?"
    Ƈ Filter if f(x)
    Œ!Q»QL=ʋƇ All distinct perms of first input with k visible buildings.





    share|improve this answer



















    • 1




      Hail the new ʋ! (it's pretty older than Ƈ, actually :P)
      – Erik the Outgolfer
      Nov 15 '18 at 12:36





















    4














    Pyth, 18 16 bytes



    fqvzl{meSd._T{.p


    Try it here.



    Note that the online version of the Pyth interpreter throws a memory error on the largest test case.



    f                       Filter lambda T:
    q Are second input and # visible buildings equal?
    v z The second input value
    l { The number of unique elements in
    m the maximums
    e S d ...
    ._ T of prefixes of T
    { .p over unique permutations of (implicit first input)





    share|improve this answer























    • Welcome back! :-)
      – Luis Mendo
      Nov 15 '18 at 12:49



















    2















    Perl 6, 81 63 bytes



    -18 bytes thanks to nwellnhof!





    {;*.permutations.unique(:with(*eqv*)).grep:{$_==set [max] @_}}


    Try it online!



    Anonymous code block that takes input curried, e.g. f(n)(list). That .unique(:with(*eqv*)) is annoyingly long though :(



    Explanation:



    {;                                                            }  # Anonymous code block
    *.permutations.unique(:with(*eqv*)) # From all distinct permutations
    .grep:{ } # Filter where
    set [max] @_ # Visible buildings
    $_== # Equals num





    share|improve this answer



















    • 1




      FWIW, I just filed a Rakudo issue so we might get rid of that annoying ; eventually ;)
      – nwellnhof
      Nov 15 '18 at 9:55



















    2















    Japt, 11 bytes



    á f_åÔâ Ê¥V


    Try it online!



    For the longer outputs, adding } l to the end will output the length instead. The online interpreter times out for the [1,2,3,4,5,6,7,8,9],4 test case, regardless of outputting the length or the list.



    Explanation:



    á              :Get all permutations
    f_ :Keep only ones where:
    åÔ : Get the cumulative maximums (i.e. the visible buildings)
    â Ê : Count the number of unique items
    ¥V : True if it's the requested number





    share|improve this answer





























      1














      JavaScript (ES6), 108 107 bytes



      Takes input as (k)(array). Prints the results with alert().





      k=>P=(a,p=,n=k,h=0)=>a.map((v,i)=>P(a.filter(_=>i--),[...p,v],n-(v>h),v>h?v:h))+a||n||P[p]||alert(P[p]=p)


      Try it online!



      Commented



      k =>                        // k = target number of visible buildings
      P = ( // P = recursive function taking:
      a, // a = list of building heights
      p = , // p = current permutation
      n = k, // n = counter initialized to k
      h = 0 // h = height of the highest building so far
      ) => //
      a.map((v, i) => // for each value v at position i in a:
      P( // do a recursive call:
      a.filter(_ => i--), // using a copy of a without the i-th element
      [...p, v], // append v to p
      n - (v > h), // decrement n if v is greater than h
      v > h ? v : h // update h to max(h, v)
      ) // end of recursive call
      ) // end of map()
      + a || // unless a was not empty,
      n || // or n is not equal to 0,
      P[p] || // or p was already printed,
      alert(P[p] = p) // print p and store it in P





      share|improve this answer































        0















        Python 2, 114 113 bytes





        lambda a,n:{p for p in permutations(a)if-~sum(p[i]>max(p[:i])for i in range(1,len(p)))==n}
        from itertools import*


        Try it online!



        -1 byte, thanks to ovs






        Python 3, 113 bytes





        lambda a,n:{p for p in permutations(a)if sum(v>max(p[:p.index(v)]+(v-1,))for v in{*p})==n}
        from itertools import*


        Try it online!






        share|improve this answer































          0














          J, 43 38 bytes



          -5 bytes after incorporating an optimization from Kevin's O5AB13 answer



          (]#~[=([:#@~.>./)"1@])[:~.i.@!@#@]A.]


          Try it online!



          ungolfed



          (] #~ [ = ([: #@~. >./)"1@]) ([: ~. i.@!@#@] A. ])


          explanation



          we're merely listing all possible perms i.@!@#@] A. ], taking uniq items thereof with ~., then filtering those by the number of visible building, which must equal the left input.



          the key logic is in the parenthetical verb which calcs the number of visible buildings:



          ([: #@~. >./)


          Here we use a max scan >./ to keep a tally of the tallest building seen so far. Then we just take the unique elements of the max scan, and that's the number of visible buildings.






          share|improve this answer























            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "200"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175970%2fhide-the-buildings%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            9 Answers
            9






            active

            oldest

            votes








            9 Answers
            9






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            6















            05AB1E, 10 9 bytes



            œÙʒη€àÙgQ


            Try it online or verify (almost) all test cases (test case [1,2,3,4,5,6,7,8,9],4 times out).

            Footer of the TIO does what OP asked at the bottom:




            Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.




            Explanation:





            œ            # Permutations of the (implicit) input-list
            # i.e. [1,2,2] → [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            Ù # Only leave the unique permutations
            # i.e. [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            # → [[1,2,2],[2,1,2],[2,2,1]]
            ʒ # Filter it by:
            η # Push the prefixes of the current permutation
            # i.e. [1,2,2] → [[1],[1,2],[1,2,2]]
            ۈ # Calculate the maximum of each permutation
            # i.e. [[1],[1,2],[1,2,2]] → [1,2,2]
            Ù # Only leave the unique maximums
            # i.e. [1,2,2] → [1,2]
            g # And take the length
            # i.e. [1,2] → 2
            Q # And only leave those equal to the second (implicit) input
            # i.e. 2 and 2 → 1 (truthy)





            share|improve this answer



















            • 1




              Impressive, every single byte here is part of the function tree!
              – lirtosiast
              Nov 15 '18 at 9:23






            • 1




              @lirtosiast Yeah, 05AB1E has some pretty short builtins sometimes, which were perfect in this challenge. :) It's actually very similar to your Pyth answer I see. Funny thing is, is that the footer for if length is greater than 20: print length; else print answer; is a̶ ̶b̶y̶t̶e̶ ̶l̶o̶n̶g̶e̶r̶ of equal length in comparison to the program itself. xD
              – Kevin Cruijssen
              Nov 15 '18 at 9:25


















            6















            05AB1E, 10 9 bytes



            œÙʒη€àÙgQ


            Try it online or verify (almost) all test cases (test case [1,2,3,4,5,6,7,8,9],4 times out).

            Footer of the TIO does what OP asked at the bottom:




            Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.




            Explanation:





            œ            # Permutations of the (implicit) input-list
            # i.e. [1,2,2] → [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            Ù # Only leave the unique permutations
            # i.e. [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            # → [[1,2,2],[2,1,2],[2,2,1]]
            ʒ # Filter it by:
            η # Push the prefixes of the current permutation
            # i.e. [1,2,2] → [[1],[1,2],[1,2,2]]
            ۈ # Calculate the maximum of each permutation
            # i.e. [[1],[1,2],[1,2,2]] → [1,2,2]
            Ù # Only leave the unique maximums
            # i.e. [1,2,2] → [1,2]
            g # And take the length
            # i.e. [1,2] → 2
            Q # And only leave those equal to the second (implicit) input
            # i.e. 2 and 2 → 1 (truthy)





            share|improve this answer



















            • 1




              Impressive, every single byte here is part of the function tree!
              – lirtosiast
              Nov 15 '18 at 9:23






            • 1




              @lirtosiast Yeah, 05AB1E has some pretty short builtins sometimes, which were perfect in this challenge. :) It's actually very similar to your Pyth answer I see. Funny thing is, is that the footer for if length is greater than 20: print length; else print answer; is a̶ ̶b̶y̶t̶e̶ ̶l̶o̶n̶g̶e̶r̶ of equal length in comparison to the program itself. xD
              – Kevin Cruijssen
              Nov 15 '18 at 9:25
















            6












            6








            6







            05AB1E, 10 9 bytes



            œÙʒη€àÙgQ


            Try it online or verify (almost) all test cases (test case [1,2,3,4,5,6,7,8,9],4 times out).

            Footer of the TIO does what OP asked at the bottom:




            Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.




            Explanation:





            œ            # Permutations of the (implicit) input-list
            # i.e. [1,2,2] → [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            Ù # Only leave the unique permutations
            # i.e. [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            # → [[1,2,2],[2,1,2],[2,2,1]]
            ʒ # Filter it by:
            η # Push the prefixes of the current permutation
            # i.e. [1,2,2] → [[1],[1,2],[1,2,2]]
            ۈ # Calculate the maximum of each permutation
            # i.e. [[1],[1,2],[1,2,2]] → [1,2,2]
            Ù # Only leave the unique maximums
            # i.e. [1,2,2] → [1,2]
            g # And take the length
            # i.e. [1,2] → 2
            Q # And only leave those equal to the second (implicit) input
            # i.e. 2 and 2 → 1 (truthy)





            share|improve this answer















            05AB1E, 10 9 bytes



            œÙʒη€àÙgQ


            Try it online or verify (almost) all test cases (test case [1,2,3,4,5,6,7,8,9],4 times out).

            Footer of the TIO does what OP asked at the bottom:




            Optional: If possible, can you add something like if length is greater than 20: print length else print answer. In the footer, not in the code.




            Explanation:





            œ            # Permutations of the (implicit) input-list
            # i.e. [1,2,2] → [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            Ù # Only leave the unique permutations
            # i.e. [[1,2,2],[1,2,2],[2,1,2],[2,2,1],[2,1,2],[2,2,1]]
            # → [[1,2,2],[2,1,2],[2,2,1]]
            ʒ # Filter it by:
            η # Push the prefixes of the current permutation
            # i.e. [1,2,2] → [[1],[1,2],[1,2,2]]
            ۈ # Calculate the maximum of each permutation
            # i.e. [[1],[1,2],[1,2,2]] → [1,2,2]
            Ù # Only leave the unique maximums
            # i.e. [1,2,2] → [1,2]
            g # And take the length
            # i.e. [1,2] → 2
            Q # And only leave those equal to the second (implicit) input
            # i.e. 2 and 2 → 1 (truthy)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 15 '18 at 9:27

























            answered Nov 15 '18 at 9:15









            Kevin CruijssenKevin Cruijssen

            36k554189




            36k554189








            • 1




              Impressive, every single byte here is part of the function tree!
              – lirtosiast
              Nov 15 '18 at 9:23






            • 1




              @lirtosiast Yeah, 05AB1E has some pretty short builtins sometimes, which were perfect in this challenge. :) It's actually very similar to your Pyth answer I see. Funny thing is, is that the footer for if length is greater than 20: print length; else print answer; is a̶ ̶b̶y̶t̶e̶ ̶l̶o̶n̶g̶e̶r̶ of equal length in comparison to the program itself. xD
              – Kevin Cruijssen
              Nov 15 '18 at 9:25
















            • 1




              Impressive, every single byte here is part of the function tree!
              – lirtosiast
              Nov 15 '18 at 9:23






            • 1




              @lirtosiast Yeah, 05AB1E has some pretty short builtins sometimes, which were perfect in this challenge. :) It's actually very similar to your Pyth answer I see. Funny thing is, is that the footer for if length is greater than 20: print length; else print answer; is a̶ ̶b̶y̶t̶e̶ ̶l̶o̶n̶g̶e̶r̶ of equal length in comparison to the program itself. xD
              – Kevin Cruijssen
              Nov 15 '18 at 9:25










            1




            1




            Impressive, every single byte here is part of the function tree!
            – lirtosiast
            Nov 15 '18 at 9:23




            Impressive, every single byte here is part of the function tree!
            – lirtosiast
            Nov 15 '18 at 9:23




            1




            1




            @lirtosiast Yeah, 05AB1E has some pretty short builtins sometimes, which were perfect in this challenge. :) It's actually very similar to your Pyth answer I see. Funny thing is, is that the footer for if length is greater than 20: print length; else print answer; is a̶ ̶b̶y̶t̶e̶ ̶l̶o̶n̶g̶e̶r̶ of equal length in comparison to the program itself. xD
            – Kevin Cruijssen
            Nov 15 '18 at 9:25






            @lirtosiast Yeah, 05AB1E has some pretty short builtins sometimes, which were perfect in this challenge. :) It's actually very similar to your Pyth answer I see. Funny thing is, is that the footer for if length is greater than 20: print length; else print answer; is a̶ ̶b̶y̶t̶e̶ ̶l̶o̶n̶g̶e̶r̶ of equal length in comparison to the program itself. xD
            – Kevin Cruijssen
            Nov 15 '18 at 9:25













            5














            Haskell, 73 bytes



            import Data.List
            f n=filter((n==).length.nub.scanl1 max).nub.permutations


            Try it online!






            share|improve this answer


























              5














              Haskell, 73 bytes



              import Data.List
              f n=filter((n==).length.nub.scanl1 max).nub.permutations


              Try it online!






              share|improve this answer
























                5












                5








                5






                Haskell, 73 bytes



                import Data.List
                f n=filter((n==).length.nub.scanl1 max).nub.permutations


                Try it online!






                share|improve this answer












                Haskell, 73 bytes



                import Data.List
                f n=filter((n==).length.nub.scanl1 max).nub.permutations


                Try it online!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 7:35









                niminimi

                31.5k32185




                31.5k32185























                    5















                    Jelly, 12 10 bytes



                    Œ!Q»QL=ʋƇ


                    Try it online!



                    -2 bytes by @Erik the Outgolfer



                    This is a dyadic function taking the building heights and k in that order.



                    Œ!                All permutations of first input
                    Œ!Q Unique permutations of first input
                    » Running maximum
                    Q Unique values
                    L Length of this array
                    = Equals k
                    ʋ Create a monad from these 4 links
                    »QL=ʋ "Are exactly k buildings visible in arrangement x?"
                    Ƈ Filter if f(x)
                    Œ!Q»QL=ʋƇ All distinct perms of first input with k visible buildings.





                    share|improve this answer



















                    • 1




                      Hail the new ʋ! (it's pretty older than Ƈ, actually :P)
                      – Erik the Outgolfer
                      Nov 15 '18 at 12:36


















                    5















                    Jelly, 12 10 bytes



                    Œ!Q»QL=ʋƇ


                    Try it online!



                    -2 bytes by @Erik the Outgolfer



                    This is a dyadic function taking the building heights and k in that order.



                    Œ!                All permutations of first input
                    Œ!Q Unique permutations of first input
                    » Running maximum
                    Q Unique values
                    L Length of this array
                    = Equals k
                    ʋ Create a monad from these 4 links
                    »QL=ʋ "Are exactly k buildings visible in arrangement x?"
                    Ƈ Filter if f(x)
                    Œ!Q»QL=ʋƇ All distinct perms of first input with k visible buildings.





                    share|improve this answer



















                    • 1




                      Hail the new ʋ! (it's pretty older than Ƈ, actually :P)
                      – Erik the Outgolfer
                      Nov 15 '18 at 12:36
















                    5












                    5








                    5







                    Jelly, 12 10 bytes



                    Œ!Q»QL=ʋƇ


                    Try it online!



                    -2 bytes by @Erik the Outgolfer



                    This is a dyadic function taking the building heights and k in that order.



                    Œ!                All permutations of first input
                    Œ!Q Unique permutations of first input
                    » Running maximum
                    Q Unique values
                    L Length of this array
                    = Equals k
                    ʋ Create a monad from these 4 links
                    »QL=ʋ "Are exactly k buildings visible in arrangement x?"
                    Ƈ Filter if f(x)
                    Œ!Q»QL=ʋƇ All distinct perms of first input with k visible buildings.





                    share|improve this answer















                    Jelly, 12 10 bytes



                    Œ!Q»QL=ʋƇ


                    Try it online!



                    -2 bytes by @Erik the Outgolfer



                    This is a dyadic function taking the building heights and k in that order.



                    Œ!                All permutations of first input
                    Œ!Q Unique permutations of first input
                    » Running maximum
                    Q Unique values
                    L Length of this array
                    = Equals k
                    ʋ Create a monad from these 4 links
                    »QL=ʋ "Are exactly k buildings visible in arrangement x?"
                    Ƈ Filter if f(x)
                    Œ!Q»QL=ʋƇ All distinct perms of first input with k visible buildings.






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 15 '18 at 13:16

























                    answered Nov 15 '18 at 8:39









                    lirtosiastlirtosiast

                    15.7k436107




                    15.7k436107








                    • 1




                      Hail the new ʋ! (it's pretty older than Ƈ, actually :P)
                      – Erik the Outgolfer
                      Nov 15 '18 at 12:36
















                    • 1




                      Hail the new ʋ! (it's pretty older than Ƈ, actually :P)
                      – Erik the Outgolfer
                      Nov 15 '18 at 12:36










                    1




                    1




                    Hail the new ʋ! (it's pretty older than Ƈ, actually :P)
                    – Erik the Outgolfer
                    Nov 15 '18 at 12:36






                    Hail the new ʋ! (it's pretty older than Ƈ, actually :P)
                    – Erik the Outgolfer
                    Nov 15 '18 at 12:36













                    4














                    Pyth, 18 16 bytes



                    fqvzl{meSd._T{.p


                    Try it here.



                    Note that the online version of the Pyth interpreter throws a memory error on the largest test case.



                    f                       Filter lambda T:
                    q Are second input and # visible buildings equal?
                    v z The second input value
                    l { The number of unique elements in
                    m the maximums
                    e S d ...
                    ._ T of prefixes of T
                    { .p over unique permutations of (implicit first input)





                    share|improve this answer























                    • Welcome back! :-)
                      – Luis Mendo
                      Nov 15 '18 at 12:49
















                    4














                    Pyth, 18 16 bytes



                    fqvzl{meSd._T{.p


                    Try it here.



                    Note that the online version of the Pyth interpreter throws a memory error on the largest test case.



                    f                       Filter lambda T:
                    q Are second input and # visible buildings equal?
                    v z The second input value
                    l { The number of unique elements in
                    m the maximums
                    e S d ...
                    ._ T of prefixes of T
                    { .p over unique permutations of (implicit first input)





                    share|improve this answer























                    • Welcome back! :-)
                      – Luis Mendo
                      Nov 15 '18 at 12:49














                    4












                    4








                    4






                    Pyth, 18 16 bytes



                    fqvzl{meSd._T{.p


                    Try it here.



                    Note that the online version of the Pyth interpreter throws a memory error on the largest test case.



                    f                       Filter lambda T:
                    q Are second input and # visible buildings equal?
                    v z The second input value
                    l { The number of unique elements in
                    m the maximums
                    e S d ...
                    ._ T of prefixes of T
                    { .p over unique permutations of (implicit first input)





                    share|improve this answer














                    Pyth, 18 16 bytes



                    fqvzl{meSd._T{.p


                    Try it here.



                    Note that the online version of the Pyth interpreter throws a memory error on the largest test case.



                    f                       Filter lambda T:
                    q Are second input and # visible buildings equal?
                    v z The second input value
                    l { The number of unique elements in
                    m the maximums
                    e S d ...
                    ._ T of prefixes of T
                    { .p over unique permutations of (implicit first input)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 15 '18 at 9:01

























                    answered Nov 15 '18 at 6:58









                    lirtosiastlirtosiast

                    15.7k436107




                    15.7k436107












                    • Welcome back! :-)
                      – Luis Mendo
                      Nov 15 '18 at 12:49


















                    • Welcome back! :-)
                      – Luis Mendo
                      Nov 15 '18 at 12:49
















                    Welcome back! :-)
                    – Luis Mendo
                    Nov 15 '18 at 12:49




                    Welcome back! :-)
                    – Luis Mendo
                    Nov 15 '18 at 12:49











                    2















                    Perl 6, 81 63 bytes



                    -18 bytes thanks to nwellnhof!





                    {;*.permutations.unique(:with(*eqv*)).grep:{$_==set [max] @_}}


                    Try it online!



                    Anonymous code block that takes input curried, e.g. f(n)(list). That .unique(:with(*eqv*)) is annoyingly long though :(



                    Explanation:



                    {;                                                            }  # Anonymous code block
                    *.permutations.unique(:with(*eqv*)) # From all distinct permutations
                    .grep:{ } # Filter where
                    set [max] @_ # Visible buildings
                    $_== # Equals num





                    share|improve this answer



















                    • 1




                      FWIW, I just filed a Rakudo issue so we might get rid of that annoying ; eventually ;)
                      – nwellnhof
                      Nov 15 '18 at 9:55
















                    2















                    Perl 6, 81 63 bytes



                    -18 bytes thanks to nwellnhof!





                    {;*.permutations.unique(:with(*eqv*)).grep:{$_==set [max] @_}}


                    Try it online!



                    Anonymous code block that takes input curried, e.g. f(n)(list). That .unique(:with(*eqv*)) is annoyingly long though :(



                    Explanation:



                    {;                                                            }  # Anonymous code block
                    *.permutations.unique(:with(*eqv*)) # From all distinct permutations
                    .grep:{ } # Filter where
                    set [max] @_ # Visible buildings
                    $_== # Equals num





                    share|improve this answer



















                    • 1




                      FWIW, I just filed a Rakudo issue so we might get rid of that annoying ; eventually ;)
                      – nwellnhof
                      Nov 15 '18 at 9:55














                    2












                    2








                    2







                    Perl 6, 81 63 bytes



                    -18 bytes thanks to nwellnhof!





                    {;*.permutations.unique(:with(*eqv*)).grep:{$_==set [max] @_}}


                    Try it online!



                    Anonymous code block that takes input curried, e.g. f(n)(list). That .unique(:with(*eqv*)) is annoyingly long though :(



                    Explanation:



                    {;                                                            }  # Anonymous code block
                    *.permutations.unique(:with(*eqv*)) # From all distinct permutations
                    .grep:{ } # Filter where
                    set [max] @_ # Visible buildings
                    $_== # Equals num





                    share|improve this answer















                    Perl 6, 81 63 bytes



                    -18 bytes thanks to nwellnhof!





                    {;*.permutations.unique(:with(*eqv*)).grep:{$_==set [max] @_}}


                    Try it online!



                    Anonymous code block that takes input curried, e.g. f(n)(list). That .unique(:with(*eqv*)) is annoyingly long though :(



                    Explanation:



                    {;                                                            }  # Anonymous code block
                    *.permutations.unique(:with(*eqv*)) # From all distinct permutations
                    .grep:{ } # Filter where
                    set [max] @_ # Visible buildings
                    $_== # Equals num






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 15 '18 at 9:49

























                    answered Nov 15 '18 at 7:04









                    Jo KingJo King

                    21.1k248110




                    21.1k248110








                    • 1




                      FWIW, I just filed a Rakudo issue so we might get rid of that annoying ; eventually ;)
                      – nwellnhof
                      Nov 15 '18 at 9:55














                    • 1




                      FWIW, I just filed a Rakudo issue so we might get rid of that annoying ; eventually ;)
                      – nwellnhof
                      Nov 15 '18 at 9:55








                    1




                    1




                    FWIW, I just filed a Rakudo issue so we might get rid of that annoying ; eventually ;)
                    – nwellnhof
                    Nov 15 '18 at 9:55




                    FWIW, I just filed a Rakudo issue so we might get rid of that annoying ; eventually ;)
                    – nwellnhof
                    Nov 15 '18 at 9:55











                    2















                    Japt, 11 bytes



                    á f_åÔâ Ê¥V


                    Try it online!



                    For the longer outputs, adding } l to the end will output the length instead. The online interpreter times out for the [1,2,3,4,5,6,7,8,9],4 test case, regardless of outputting the length or the list.



                    Explanation:



                    á              :Get all permutations
                    f_ :Keep only ones where:
                    åÔ : Get the cumulative maximums (i.e. the visible buildings)
                    â Ê : Count the number of unique items
                    ¥V : True if it's the requested number





                    share|improve this answer


























                      2















                      Japt, 11 bytes



                      á f_åÔâ Ê¥V


                      Try it online!



                      For the longer outputs, adding } l to the end will output the length instead. The online interpreter times out for the [1,2,3,4,5,6,7,8,9],4 test case, regardless of outputting the length or the list.



                      Explanation:



                      á              :Get all permutations
                      f_ :Keep only ones where:
                      åÔ : Get the cumulative maximums (i.e. the visible buildings)
                      â Ê : Count the number of unique items
                      ¥V : True if it's the requested number





                      share|improve this answer
























                        2












                        2








                        2







                        Japt, 11 bytes



                        á f_åÔâ Ê¥V


                        Try it online!



                        For the longer outputs, adding } l to the end will output the length instead. The online interpreter times out for the [1,2,3,4,5,6,7,8,9],4 test case, regardless of outputting the length or the list.



                        Explanation:



                        á              :Get all permutations
                        f_ :Keep only ones where:
                        åÔ : Get the cumulative maximums (i.e. the visible buildings)
                        â Ê : Count the number of unique items
                        ¥V : True if it's the requested number





                        share|improve this answer













                        Japt, 11 bytes



                        á f_åÔâ Ê¥V


                        Try it online!



                        For the longer outputs, adding } l to the end will output the length instead. The online interpreter times out for the [1,2,3,4,5,6,7,8,9],4 test case, regardless of outputting the length or the list.



                        Explanation:



                        á              :Get all permutations
                        f_ :Keep only ones where:
                        åÔ : Get the cumulative maximums (i.e. the visible buildings)
                        â Ê : Count the number of unique items
                        ¥V : True if it's the requested number






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Nov 15 '18 at 15:27









                        Kamil DrakariKamil Drakari

                        3,011416




                        3,011416























                            1














                            JavaScript (ES6), 108 107 bytes



                            Takes input as (k)(array). Prints the results with alert().





                            k=>P=(a,p=,n=k,h=0)=>a.map((v,i)=>P(a.filter(_=>i--),[...p,v],n-(v>h),v>h?v:h))+a||n||P[p]||alert(P[p]=p)


                            Try it online!



                            Commented



                            k =>                        // k = target number of visible buildings
                            P = ( // P = recursive function taking:
                            a, // a = list of building heights
                            p = , // p = current permutation
                            n = k, // n = counter initialized to k
                            h = 0 // h = height of the highest building so far
                            ) => //
                            a.map((v, i) => // for each value v at position i in a:
                            P( // do a recursive call:
                            a.filter(_ => i--), // using a copy of a without the i-th element
                            [...p, v], // append v to p
                            n - (v > h), // decrement n if v is greater than h
                            v > h ? v : h // update h to max(h, v)
                            ) // end of recursive call
                            ) // end of map()
                            + a || // unless a was not empty,
                            n || // or n is not equal to 0,
                            P[p] || // or p was already printed,
                            alert(P[p] = p) // print p and store it in P





                            share|improve this answer




























                              1














                              JavaScript (ES6), 108 107 bytes



                              Takes input as (k)(array). Prints the results with alert().





                              k=>P=(a,p=,n=k,h=0)=>a.map((v,i)=>P(a.filter(_=>i--),[...p,v],n-(v>h),v>h?v:h))+a||n||P[p]||alert(P[p]=p)


                              Try it online!



                              Commented



                              k =>                        // k = target number of visible buildings
                              P = ( // P = recursive function taking:
                              a, // a = list of building heights
                              p = , // p = current permutation
                              n = k, // n = counter initialized to k
                              h = 0 // h = height of the highest building so far
                              ) => //
                              a.map((v, i) => // for each value v at position i in a:
                              P( // do a recursive call:
                              a.filter(_ => i--), // using a copy of a without the i-th element
                              [...p, v], // append v to p
                              n - (v > h), // decrement n if v is greater than h
                              v > h ? v : h // update h to max(h, v)
                              ) // end of recursive call
                              ) // end of map()
                              + a || // unless a was not empty,
                              n || // or n is not equal to 0,
                              P[p] || // or p was already printed,
                              alert(P[p] = p) // print p and store it in P





                              share|improve this answer


























                                1












                                1








                                1






                                JavaScript (ES6), 108 107 bytes



                                Takes input as (k)(array). Prints the results with alert().





                                k=>P=(a,p=,n=k,h=0)=>a.map((v,i)=>P(a.filter(_=>i--),[...p,v],n-(v>h),v>h?v:h))+a||n||P[p]||alert(P[p]=p)


                                Try it online!



                                Commented



                                k =>                        // k = target number of visible buildings
                                P = ( // P = recursive function taking:
                                a, // a = list of building heights
                                p = , // p = current permutation
                                n = k, // n = counter initialized to k
                                h = 0 // h = height of the highest building so far
                                ) => //
                                a.map((v, i) => // for each value v at position i in a:
                                P( // do a recursive call:
                                a.filter(_ => i--), // using a copy of a without the i-th element
                                [...p, v], // append v to p
                                n - (v > h), // decrement n if v is greater than h
                                v > h ? v : h // update h to max(h, v)
                                ) // end of recursive call
                                ) // end of map()
                                + a || // unless a was not empty,
                                n || // or n is not equal to 0,
                                P[p] || // or p was already printed,
                                alert(P[p] = p) // print p and store it in P





                                share|improve this answer














                                JavaScript (ES6), 108 107 bytes



                                Takes input as (k)(array). Prints the results with alert().





                                k=>P=(a,p=,n=k,h=0)=>a.map((v,i)=>P(a.filter(_=>i--),[...p,v],n-(v>h),v>h?v:h))+a||n||P[p]||alert(P[p]=p)


                                Try it online!



                                Commented



                                k =>                        // k = target number of visible buildings
                                P = ( // P = recursive function taking:
                                a, // a = list of building heights
                                p = , // p = current permutation
                                n = k, // n = counter initialized to k
                                h = 0 // h = height of the highest building so far
                                ) => //
                                a.map((v, i) => // for each value v at position i in a:
                                P( // do a recursive call:
                                a.filter(_ => i--), // using a copy of a without the i-th element
                                [...p, v], // append v to p
                                n - (v > h), // decrement n if v is greater than h
                                v > h ? v : h // update h to max(h, v)
                                ) // end of recursive call
                                ) // end of map()
                                + a || // unless a was not empty,
                                n || // or n is not equal to 0,
                                P[p] || // or p was already printed,
                                alert(P[p] = p) // print p and store it in P






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Nov 15 '18 at 10:46

























                                answered Nov 15 '18 at 10:04









                                ArnauldArnauld

                                72.8k689307




                                72.8k689307























                                    0















                                    Python 2, 114 113 bytes





                                    lambda a,n:{p for p in permutations(a)if-~sum(p[i]>max(p[:i])for i in range(1,len(p)))==n}
                                    from itertools import*


                                    Try it online!



                                    -1 byte, thanks to ovs






                                    Python 3, 113 bytes





                                    lambda a,n:{p for p in permutations(a)if sum(v>max(p[:p.index(v)]+(v-1,))for v in{*p})==n}
                                    from itertools import*


                                    Try it online!






                                    share|improve this answer




























                                      0















                                      Python 2, 114 113 bytes





                                      lambda a,n:{p for p in permutations(a)if-~sum(p[i]>max(p[:i])for i in range(1,len(p)))==n}
                                      from itertools import*


                                      Try it online!



                                      -1 byte, thanks to ovs






                                      Python 3, 113 bytes





                                      lambda a,n:{p for p in permutations(a)if sum(v>max(p[:p.index(v)]+(v-1,))for v in{*p})==n}
                                      from itertools import*


                                      Try it online!






                                      share|improve this answer


























                                        0












                                        0








                                        0







                                        Python 2, 114 113 bytes





                                        lambda a,n:{p for p in permutations(a)if-~sum(p[i]>max(p[:i])for i in range(1,len(p)))==n}
                                        from itertools import*


                                        Try it online!



                                        -1 byte, thanks to ovs






                                        Python 3, 113 bytes





                                        lambda a,n:{p for p in permutations(a)if sum(v>max(p[:p.index(v)]+(v-1,))for v in{*p})==n}
                                        from itertools import*


                                        Try it online!






                                        share|improve this answer















                                        Python 2, 114 113 bytes





                                        lambda a,n:{p for p in permutations(a)if-~sum(p[i]>max(p[:i])for i in range(1,len(p)))==n}
                                        from itertools import*


                                        Try it online!



                                        -1 byte, thanks to ovs






                                        Python 3, 113 bytes





                                        lambda a,n:{p for p in permutations(a)if sum(v>max(p[:p.index(v)]+(v-1,))for v in{*p})==n}
                                        from itertools import*


                                        Try it online!







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Nov 15 '18 at 10:22

























                                        answered Nov 15 '18 at 7:57









                                        TFeldTFeld

                                        14.4k21240




                                        14.4k21240























                                            0














                                            J, 43 38 bytes



                                            -5 bytes after incorporating an optimization from Kevin's O5AB13 answer



                                            (]#~[=([:#@~.>./)"1@])[:~.i.@!@#@]A.]


                                            Try it online!



                                            ungolfed



                                            (] #~ [ = ([: #@~. >./)"1@]) ([: ~. i.@!@#@] A. ])


                                            explanation



                                            we're merely listing all possible perms i.@!@#@] A. ], taking uniq items thereof with ~., then filtering those by the number of visible building, which must equal the left input.



                                            the key logic is in the parenthetical verb which calcs the number of visible buildings:



                                            ([: #@~. >./)


                                            Here we use a max scan >./ to keep a tally of the tallest building seen so far. Then we just take the unique elements of the max scan, and that's the number of visible buildings.






                                            share|improve this answer




























                                              0














                                              J, 43 38 bytes



                                              -5 bytes after incorporating an optimization from Kevin's O5AB13 answer



                                              (]#~[=([:#@~.>./)"1@])[:~.i.@!@#@]A.]


                                              Try it online!



                                              ungolfed



                                              (] #~ [ = ([: #@~. >./)"1@]) ([: ~. i.@!@#@] A. ])


                                              explanation



                                              we're merely listing all possible perms i.@!@#@] A. ], taking uniq items thereof with ~., then filtering those by the number of visible building, which must equal the left input.



                                              the key logic is in the parenthetical verb which calcs the number of visible buildings:



                                              ([: #@~. >./)


                                              Here we use a max scan >./ to keep a tally of the tallest building seen so far. Then we just take the unique elements of the max scan, and that's the number of visible buildings.






                                              share|improve this answer


























                                                0












                                                0








                                                0






                                                J, 43 38 bytes



                                                -5 bytes after incorporating an optimization from Kevin's O5AB13 answer



                                                (]#~[=([:#@~.>./)"1@])[:~.i.@!@#@]A.]


                                                Try it online!



                                                ungolfed



                                                (] #~ [ = ([: #@~. >./)"1@]) ([: ~. i.@!@#@] A. ])


                                                explanation



                                                we're merely listing all possible perms i.@!@#@] A. ], taking uniq items thereof with ~., then filtering those by the number of visible building, which must equal the left input.



                                                the key logic is in the parenthetical verb which calcs the number of visible buildings:



                                                ([: #@~. >./)


                                                Here we use a max scan >./ to keep a tally of the tallest building seen so far. Then we just take the unique elements of the max scan, and that's the number of visible buildings.






                                                share|improve this answer














                                                J, 43 38 bytes



                                                -5 bytes after incorporating an optimization from Kevin's O5AB13 answer



                                                (]#~[=([:#@~.>./)"1@])[:~.i.@!@#@]A.]


                                                Try it online!



                                                ungolfed



                                                (] #~ [ = ([: #@~. >./)"1@]) ([: ~. i.@!@#@] A. ])


                                                explanation



                                                we're merely listing all possible perms i.@!@#@] A. ], taking uniq items thereof with ~., then filtering those by the number of visible building, which must equal the left input.



                                                the key logic is in the parenthetical verb which calcs the number of visible buildings:



                                                ([: #@~. >./)


                                                Here we use a max scan >./ to keep a tally of the tallest building seen so far. Then we just take the unique elements of the max scan, and that's the number of visible buildings.







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Nov 17 '18 at 5:49

























                                                answered Nov 17 '18 at 5:21









                                                JonahJonah

                                                2,011816




                                                2,011816






























                                                    draft saved

                                                    draft discarded




















































                                                    If this is an answer to a challenge…




                                                    • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                    • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                      Explanations of your answer make it more interesting to read and are very much encouraged.


                                                    • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                    More generally…




                                                    • …Please make sure to answer the question and provide sufficient detail.


                                                    • …Avoid asking for help, clarification or responding to other answers (use comments instead).






                                                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                    Please pay close attention to the following guidance:


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175970%2fhide-the-buildings%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    鏡平學校

                                                    ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                                                    Why https connections are so slow when debugging (stepping over) in Java?