Tag Info

76

CSS, 132 116 115 bytes a:not(:last-child):nth-child(n+2):after,a:nth-last-child(n+3):after{content:","}a+:last-child:before{content:"and " <p> <a>one</a> </p> <p> <a>one</a> <a>two</a> </p> <p> <a>one</a> <a>two</a> <a>three</a> &...

62

APL, 1 byte ⊥ Test it on TryAPL.

53

Python, 32 bytes lambda n:eval('['*n+'n'+']*n'*n) Try it online! Makes a string like "[[[n]*n]*n]*n" with n multiplcations, and evaluates it as Python code. Since the evaluation happens within the function scope, the variable name n evaluates to the function input.

51

Jelly, 7 6 bytes _/ị“ḃ» Typing on phone. Will add description. (1,0) goes to A, (0,1) to B, and (0,0) to C. Arrays in Jelly are 1-based, and the indexing function ị works cyclically. Therefore, we can just fold subtraction over the input. _ [vectorized] subtraction _/ Fold subtraction over the input “ḃ» "ABC" ...

46

Python 2, 35 bytes while 1:b=input();print b;True&=b<1 Try it online! Input and output are lines of True/False. Based on Dennis's solution. Redefines the variable True to be False after a True input is encountered. That way, any further inputs of True will evaluate to False and be printed as such. Python 3 no longer allows True and False to be ...

44

APL, 9 bytes ⊢(/⍨)⊢=⌈\ This is a monadic function train with diagram: ┌─┼───┐ ⊢ ⍨ ┌─┼─┐ ┌─┘ ⊢ = \ / ┌─┘ ⌈ The non-train version is {⍵/⍨⍵=⌈\⍵} This basically checks if each element is equal to the running maximum. Note that Martin Büttner's J solution is the same length as this and was posted first.

40

K, 3 bytes ,// This is a fairly common idiom. "Join over converge". try it here with oK. How it works: Join (,) fuses together atoms or lists to produce a list. Over (/) takes a verb (in this case join) and applies it between each element of a list, left to right. Thus, the compound ,/ will flatten all the top level elements of the list. The symbol / ...

40

Wolfram Language (Mathematica), 42 bytes #&@@CellularAutomaton[{,{},0{,}},{#,0},0]& Try it online! Cellular automata are indeed the answer to life, the universe, and everything.1 How? CellularAutomaton accepts an input array and an optional background value. Thus, {#,0} specifies that a cellular automaton rule should be applied to the input, ...

39

Python, 29 bytes lambda s:ord(s[-1])-ord(s) The sum of the differences forms a telescopic series, so most summands cancel out and (s1 - s0) + (s2 - s1) + … + (sn-1 - sn-2) + (sn - sn-1) = sn - s0. If taking a byte string as input is allowed lambda s:s[-1]-s will work as well for 19 bytes. Test both on Ideone.

38

JavaScript (ES6), 35 bytes Inspired by @user81655's answer: f=a=>a.map?[].concat(...a.map(f)):a

38

Jelly, 3 bytes ṭFẠ F flattens the input list. ṭ tacks on the original input list as an element, which is falsy if and only if it is empty. Ạ then checks if any element in the flattened list, or the original list itself, is falsy. (Original answer) FẠ^Ṇ Thanks to Dennis for encouraging finding a solution matching his. FẠ gives 0 if the input contains ...

36

Pyth, 40 36 31 30 bytes Ju.|G^2slHxMf>FT.:Q2Z|tSIxRJQJ Try it online: Demonstration or Test Suite Each of the big test-cases finishes in a couple of seconds. Explanation: First I'll explain the method and why it works. I'll do this with the example list: [7, 2, 13, 9]. The first two numbers are already wrong (7 > 2). We want to xor with some ...

36

Dyalog APL, 6 2 bytes ⊥⍨ Test it on TryAPL. How it works ⊥ (uptack, dyadic: decode) performs base conversion. If the left operand is a vector, it performs mixed base conversion, which is perfect for this task. For a base vector b = bn, ⋯, b0 and a digit vector a = an, ⋯, a0, b ⊥ a converts a to the mixed base b, i.e., it computes b0⋯...

35

Pyth, 7 bytes n{Q_{_Q Run the code on test cases. n Check whether the following are not equal: {Q The unique elements in order of first appearance _{_Q The unique elements in order of last appearance (done by reversing, taking unique elts, then reversing again) The only way to avoid surrounding is for the countries' leftmost ...

35

awk, 10 bytes Input is expected on STDIN, one number per line. ++a[$1]%$1 Explanation Keeps a counter for each number in an associative array, prints only if the counter value modulo n is not zero. Printing is implicit. Long version: ++a[$1]%$1{print $0} 35 APL, 2 bytes <\ Evaluates to the function "scan using less-than". Try it online! Explanation In APL, the operator \ (scan) reduces each nonempty prefix of an array from the right using the provided function. For example, given the array 0 1 0, it computes 0 (prefix of length 1), 0<1 (prefix of length 2) and 0<(1<0) (prefix of length 2) and ... 35 JavaScript (Node.js), 38 bytes a=>a.map(v=>(n+=v>p&&v-p,p=v),p=n=0)|n Try it online! Simply a greedy algorithm which scan from left to right, only draw lines if needed, and draw it as long as possible. Thanks Arnauld, save 2 3 bytes 34 Ruby, 31 bytes ->x{(0..53).map{|r|x[r*17%54]}} Try it online! Explanation: I'm picking one card, then skipping over the next 16 and start from the first card when I reach the last card of the deck. 17 and 54 are mutually prime, so I'm sure to pick all cards. The 17th position is guaranteed to be a different suit and the difference in value is at least 2:... 33 Jelly, 1 byte x Try it online! Note that this is not the “repeat n n times” built-in — its function is more general than that. For example 4,5,6x1,2,3 equals [4, 5, 5, 6, 6, 6]. Given only one argument, Jelly just happens to use it as both the left and right argument for the supplied link, but this functionality is not inherent to x. If this doesn’t ... 32 J, 4 bytes$~#~ Try it online! Explanation $~#~ Input: integer n #~ Create n copies of n$~ Shape n into an array with dimensions n copies of n

32

Imperative Tampio, 168 bytes Listan x on riippuen siitä,onko sen ensimmäisen alkion pituus suurempi tai yhtä suuri kuin sen jokaisen alkion pituus,joko sen ensimmäinen alkio tai sen hännän x. Online version Ungolfed: Listan pisin alkio on riippuen siitä, onko sen ensimmäisen alkion pituus suurempi tai yhtä suuri kuin sen jokaisen alkion pituus, joko sen ...

31

Pyth, 3 bytes !DQ Explanation: Q Input !D Sort by logical NOT Try it here.

30

C (gcc), 88 75 73 bytes Saved two bytes thanks to ceilingcat. h,e,a;t(int*_){for(h=e=a=0;*_;h+=e>4&a>2)e=*_<25?a=0:++e,a+=*_++>29;e=h;} Try it online!

29

Python 2 - 18 max(d,key=d.count) Since your python answer doesn't seem to print, I expect this is what you want. Add 6 bytes for print normally.

29

MATL, 7 12 11 9 8 6 bytes Thanks a lot to @lirtosiast for removing 2 bytes ud7BXf Truthy is an array of nonzero values. Falsy is empty array (no output displayed). As of release 16.2.0, u is stable by default. So the code needs an extra S to sort the output: uSd7BXf (7 bytes). The link includes this modification. Try it online! u % input array ...

29

Jelly, 3 bytes Ṣ.ị Try it online! Sort the array, and then takes the 0.5-th element. Jelly uses 1-indexing, and floating points indexing means take its floor and its ceil. So the 0.5-th element would give you the 0th element and the 1st element. The 0th element is the last element.

29

Retina, 4 bytes 00 0 Try it online!

28

J, 31 30 14 12 11 bytes [:;<@|.`</. Ych. Too big. Takes a matrix as input. Explanation J has an advantage here. There's a command called oblique (/.) which takes the oblique lines in turn and applies a verb to them. In this case I'm using a gerund to apply two verbs alternately: < (box) and <@|. (reverse and box). Then it's just a matter of ...

28

Mathematica, 18 bytes #~TakeWhile~EvenQ& Another glorious built-in that is beaten by a factor of 3 by golfing languages without the built-in...

28

05AB1E,  8 7  5 bytes Saved 2 bytes thanks to @Adnan 0š¥þO Try it online! How? This is using the algorithm that was first found by @tsh. If you like this answer, make sure to upvote their answer as well! Each time a skyscraper is lower than or as high as the previous one, it can be painted 'for free' by simply extending the brushstrokes. For instance, ...

Only top voted, non community-wiki answers of a minimum length are eligible