Hot answers tagged


GolfScript Dear Boss Man. It came to my attention that my keyboard needs replacement; the keys required to write the symbols ~ $ ` . and } are not functioning properly. It's very difficult to work like this! Please instruct the IT department to exchange the faulty keyboard as soon as possible. Sincerely, Dennis Try it online! How it works


PHP Defines a function called item that will sort an array that you pass it. Dear Boss, I have successfully discovered all brackets. The ones marked with question marks are the ones which I am not sure about. The ones marked with asterisks can be used both as an opening and closing delimiter. ( ) { } [ ] >? <? /* '* "* Thank you for reading my memo. ...


Python 2 ''''''''''''''''''''''''''''''''''''''''''''' One of the phones in the office seems to be broken, so it needs to be fixed. '''''''''''''''''''' This memo was made while testing the functionality of its buttons since some of them didn't seem to work. '''''''' 1 (no alphabets) working with no problem '''''''' abc working with no problem ''''''''' ...


Python 2 ''' 5th of September 2014 Dear Boss, I am writing this Mail because i want to discuss the recent incident. I am Thankful that you did not fire me, and gave me a secretary position instead. I dont have any experience in being a sec retary and I am not very. good at writing mail, so please excuse ...


NetLogo To Manager [IT] Let Sue sort it; then show Sue the end to the end With indentation and capitalization changes, the code becomes clear(er). This defines a function called manager which takes a list as input and prints the list sorted. to manager [IT] let sue sort IT; then (semicolons introduce a comment) show sue the end to the end


C Input as space-separated list through STDIN, output as space-separated list through STDOUT. Dear Boss, I have made for you a decision about my employment a t your company. At about noon a letter explaining this shall be presented to you, as I am a lazy person. As you are a fool, I will say no more. And I look forward to never seeing you again. ...


Pyth, 10 bytes jb_.T.T_.z Try it online in the Pyth Compiler/Executor. Idea We can achieve the desired output by applying four simple transformations: Reverse the order of the lines: Golf Code & Puzzles Programming Transpose rows and columns: GC&PP oour ldzo fezg lr ea sm m i n g This top justifies, collapsing the original columns. Transpose ...


GolfScript, 1 byte $ Yes, only 1 byte. Try it here.


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.


Jelly, 19 bytes 11ị“bMAanlseovc”iµÞ This is a monadic link that takes a list as argument and sorts it. Try it online! Background Jelly uses modular, 1-based indexing. If we repeat the months names often enough to obtain 11 characters, we get the following array. J a n u a r y J a n u F e b r u a r y F e b M a r c h M a r c h M A p r i l A p r i l A M a ...


Haskell, 62 bytes import Data.List p=reverse;o=transpose f=unlines.p.o.o.p.lines I'm very mature.


Python, 53 bytes f=lambda n,i=1:n*[f]and[i]+f(n-1,2*i)+i%2*f(n-1,i-~i) Try it online! The recursive function generates the sorted list as a pre-order walk down this tree (example with n=4): 1 / \ 2 3 / / \ 4 6 7 / / / \ 8 12 14 15 1 2 4 8 3 6 12 7 14 15 Left branches double the value, and right branches do i->i*2+...


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 ...


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 ...


J (11) (\:+/"1@#:) This is a function that takes a list: (\:+/"1@#:) 15342 28943 16375 3944 11746 825 32425 28436 21826 15752 19944 16375 15342 32425 28943 11746 28436 19944 3944 15752 825 21826 If you want to give it a name, it costs one extra character: f=:\:+/"1@#: f 15342 28943 16375 3944 11746 825 32425 28436 21826 15752 19944 16375 ...


Japt, 5 3 bytes ñg9 Test it online! Explanation I, too, have added a sorting function to my language in the last few weeks :-) ñ takes in an array and a function and sorts the array as if each item had been mapped through that function. The g function on a string takes in a number n and returns the nth char in the string, wrapping if n is negative or ...


Python 2 & 3 Unfortunately, the employees of today just can't stop using hashtags all over the place... #WritingALetter #Business Dear Boss, #SecondLine I found this scrap of paper on the floor. It said " def sortl(l): # define a function return sorted(l) # returns the list, sorted " #ScrapOfPaper Just thought I should let ...


C (with x86), 61 bytes s[];main(){qsort(s,read(0,s,99),1,"YXZQQQ\x8a\x00*\x02\x0f\xbe\xc0\xc3");puts(s);} That string contains raw bytes, not actual \x.. codes, and it's a raw machine code callback passed to qsort. Works on x86 only: 59 pop ecx 58 pop eax 5a pop edx 51 push ecx 51 push ecx 51 push ...


Python 2, 58 54 bytes lambda x:sorted(x,key=lambda y,B10=0:eval(y[1:]+'10')) Try it online! How it works y y[1:]+'10' eval(y[1:]+'10') ======================================= VB B10 0 (a variable we defined) V0 010 8 (an octal literal) V0+ 0+10 10 V1 110 110 V2 210 ...


05AB1E, 2 bytes Code: œß Same algorithm as the Jelly answer. Computes all permutations of the input and pops out the smallest one. Try it online! A more efficient method is: E[ß,Ž Performs selection sort. Uses CP-1252 encoding. Try it online!


Jelly, 1 byte Z Try it online! The “transpose” built-in will do exactly this to a list of strings.


Haskell, 67 59 58 bytes (q:r)!x|x<last q=q:r!x|1<2=(q++[x]):r _!x=[[x]] foldl(!)[] Explanation: Given a list of lists (that are already sorted) and a value x, the ! operator will place x at the end of the first list whose last element is less than or equal to x. If no such list exists, the list [x] is placed at the end. Try it online.


JavaScript (ES6), 26 bytes 1-indexed. a=>>o[x]=-~o[x]) Try it online! Commented a => // a[] = input array = // assign the callback function of map() to the variable o, so that // we have an object that can be used to store the counters x => // for each value x in a[]: ...


Dogescript It's basically English, right? shh oooot! my keyybr oad is brokn. i ne ed neew 1. such fixs much keys keys dose sort wow keys translates to: // oooot! my keyybr oad is brokn. i ne ed neew 1. function fixs(keys) { keys.sort(); return keys; }


Python, 113 P=[] for n in sorted(input())[::-1]: for p in P: if p[-1][1]>=n[1]:p+=[n];break else:P+=[[n]] print sum(P,[]) After sorting the list of books in descending order (by width first and then height), this partitions the books into piles without overlaps. To determine where to place each book, its height is compared with the height of the top ...


J, 10 9 bytes #~(=>./\) Working version of my CJam idea (in fewer bytes). E.g.: f =: #~(=>./\) f 10 10 10 9 10 10 10 10 10 f 1 2 5 4 3 7 1 2 5 7 Explanation First, we get the maximum of each prefix, with: >./\ (Here, >. is the maximum operator, / folds that operator onto a list, and \ gets all the prefixes of the input.) Then ...


APL, 2 bytes ⍋⍋ The “grade up” built-in, applied twice. Works if indexing starts at 0, which isn’t the default for all flavors of APL. Try it here! Why does this work? ⍋x returns a list of indices that would stably sort x. For example: x ← 4 4 0 1 1 2 0 1 ⍋x 2 6 3 4 7 5 0 1 because if you take element 2, then 6, then 3… you get a stably sorted ...


Python 3, 40 39 bytes 1 byte thanks to Jonathan Allan. lambda s:sorted(s,key="145926870".find) Try it online!


Detour Dear Boss Man I thought I had put your recovered files on drive z. In reality it was downloaded to the main drive, C://users/boss/recovery. Sorry for the confusion! Interpreter Permalink How it works: Simplified version: Detour Dear Boss Man z. :// Try it online!


Stuck, 4 bytes sc$d This language was documented on the wiki just yesterday! Mmm, fresh esolangs.

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