text
stringlengths
180
608k
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/26905/edit). Closed 9 years ago. [Improve this question](/posts/26905/edit) **Here's the challenge:** Order an Array from the Lowest to the Highest digit from a number, which is conveniently represented in an array. The trick here is that you cannot use any array methods, nor other sorts of loopholes. You have to stick to the basics (Arrays, Mathematical Operators /not Math Class/, no recursion. You can use any variable type of your chosing (eg: String, int), and evidently repetitive cicles, you can't however use "advanced" expressions, such as ArrayList or ParseInt for Java) For an user input of `2014`, the output should be `0124` Yes, the 0 must be represented **Scoring Method** Simply a codegolf challenge, shortest code wins. **Origin of the challenge:** I've been reading quite a bit of codegolf for a while, and decided to create a challenge based on an issue that I had with java to order the digits of a number. I did manage to get a solution, but I wasn't quite pleased with it (it took a significant ammount of bytes which I wanted to avoid), I am interested in creative, short awnsers to counter my own =) [Answer] In [Racket](http://racket-lang.org/), without explicit recursion :-P ``` (define Y (lambda (f) ((lambda (x) (x x)) (lambda (x) (lambda (y) ((f (x x)) y)))))) (define a (Y (lambda (f) (lambda (c) (cond ((null? c) c) ((null? (cdr c)) c) ((> (car c) (cadr c)) (f (cons (cadr c) (cons (car c) (cddr c))))) (#t (cons (car c) (f (cdr c))))))))) (define b (Y (lambda (f) (lambda (c) (let ((s (a c))) (if (equal? s c) c (f s))))))) ``` Call: ``` (b '(2 0 1 4)) ``` where * `Y` is the [Y-Combinator](http://mvanier.livejournal.com/2897.html) * `a` is one iteration of Bubble Sort * `b` is the bubble sort algorithm ]
[Question] [ # Sussing It Out (The Core Part) How good is your logical reasoning? In this challenge, you'll rewrite an existing program that solves simple logic puzzles like those published in Dell, Penny Press, and other magazines. ## The Details In a logic puzzle, a finite, countable set of attributes is used to identify individuals within a group. For example, out of 5 individuals there might be a group of 2 associated with a specific colour or type of apparel. You'd identify them as the person with the brown shoes,or the girl with the tan bandana. With that information and enough clues, you'll be able to solve the puzzle. In the solution, the complete set of attributes belonging to all individuals are identified in whatever groups they belong to. To solve the puzzle, you'll write a program that exhaustively applies three rules (more about them later) to rows and columns of a table. The diagram here shows the input and output. The table on the left is input to the program; the table on the right is the corresponding solution. ``` ====================================== ====================================== |1 |1 | |??|???| | | 1 |1 |1 |1 |1 |000| 2 |1 | 1 | 2 | 2 | |??|???| | | 2 | 2 | 2 | 2 | 2|000| 4 | 2 | 2 | 3 | 3 | |??|???| | | 3 | 3 | 3 | 5|00| 3|1 | 5| 3 | 4 | 4 | |??|???| | | 4 | 4 | 4 | 3 |00|1 | 3 | 4 | 4 | 5| 5| |??|???| | | 5 | 5| 5| 4 |00| 2 | 5| 3 | 5 ====================================== ====================================== | | |1 |1 |???| | | 6 |1 |1 |1 |1 |000| 2 |1 | 6 | | | 2 | 2|???| | | 7 | 2 | 2 | 2 | 2|000| 4 | 2 | 7 | | | 3 |??|1 | | | 8 | 4 | 4 | 3 |00|1 | 3 | 4 | 8 | | | 4 |??| 2 | | | 9 | 5| 5| 4 |00| 2 | 5| 3 | 9 | | | 5|??| 3| | | 10 | 3 | 3 | 5|00| 3|1 | 5| 10 ====================================== ====================================== | | | |??|???|1 | | 11 | 3 | 3 | 5|00| 3|1 | 5| 11 | | | |??|???| 2 | | 12 |1 |1 |1 |1 |000| 2 |1 | 12 | | | |??|???| 3 | | 13 | 4 | 4 | 3 |00|1 | 3 | 4 | 13 | | | |??|???| 4 | | 14 | 2 | 2 | 2 | 2|000| 4 | 2 | 14 | | | |??|???| 5| | 15 | 5| 5| 4 |00| 2 | 5| 3 | 15 ====================================== ====================================== | | | |??|???| |1 | 16 |1 |1 |1 |1 |000| 2 |1 | 16 | | | |??|???| | 2 | 17 | 2 | 2 | 2 | 2|000| 4 | 2 | 17 | | | |??|???| | 3 | 18 | 5| 5| 4 |00| 2 | 5| 3 | 18 | | | |??|???| | 4 | 19 | 4 | 4 | 3 |00|1 | 3 | 4 | 19 | | | |??|???| | 5| 20 | 3 | 3 | 5|00| 3|1 | 5| 20 ====================================== ====================================== | | | |00| 2 | | | 21 | 5| 5| 4 |00| 2 | 5| 3 | 21 | | | |00|???| 3 | | 22 | 4 | 4 | 3 |00|1 | 3 | 4 | 22 | | | |??|???| | 5| 23 | 3 | 3 | 5|00| 3|1 | 5| 23 ====================================== ====================================== | | 2 | | 2|000| | | 24 | 2 | 2 | 2 | 2|000| 4 | 2 | 24 ====================================== ====================================== | | | |??|000| 4 | 2 | 25 | 2 | 2 | 2 | 2|000| 4 | 2 | 25 ====================================== ====================================== | |1 | |??|000| | | 26 |1 |1 |1 |1 |000| 2 |1 | 26 ====================================== ====================================== | | | |1 |000| |1 | 27 |1 |1 |1 |1 |000| 2 |1 | 27 ====================================== ====================================== | | | |00| 3|1 | | 28 | 3 | 3 | 5|00| 3|1 | 5| 28 ====================================== ====================================== | | 5| |??|???| 5| | 29 | 5| 5| 4 |00| 2 | 5| 3 | 29 ====================================== ====================================== | | 4 | |??|???| | 4 | 30 | 4 | 4 | 3 |00|1 | 3 | 4 | 30 ====================================== ====================================== ``` ## Reading the Input The input is in table form and starts and end with a string of '=' characters. The same string of '=' characters also separates one group of individuals (i.e. the clue) from the next. Any line that ends with a number denotes a description of an individual in the group. Preceding the number, you'll find a row of columns delimited by the '|' character. A column's width stays the same for all rows in the table. The number of columns stays the same too. Inside the table, all column contents are sets that contain numbers ranging from 0 to w, where w is the width of the column. When reading the input, the actual values of the column content vary from case to case: Case 1: all spaces or all dashes In this case, the content is the set of integers from 1 to w Case 2: all question marks In this case, the content is the set of integers from 0 to w Case 3: all zeros In this case, the content is the set {0} Case 4: a parseable integer from 0 to w Parse the integer and store the value in a set where it is the only member **The portions of the code responsible for parsing the input as described are not counted in the code-golf score.** ## Writing the Output On output, all columns consist of a set with exactly one member: a value from 0 to w, where w is the width of the column. The value is printed anywhere inside the column as a parseable integer. The exception is the case of zero, which may be a string of zeros filling the full column width. The value of each column is generated using the algorithm described in the next section. **The portions of the code responsible for printing the output as described here are not counted in the code-golf score.** ## Here's Where You Fit In Here is the pseudo-code that solves puzzles expressible as described above: ``` tryAgain = True while tryAgain: solver.assertDistinctWithinGroup() newKnowns = solver.assertQuotaWithinSubGroup() changed = solver.matchAndMate() if newKnowns < 1 and not changed: tryAgain = False ``` You'll need to apply code golf skills to the pseudo-code above and to the three algorithms described in more detail below: 1. assertDistinctWithinGroup * for any row within a group, if the contents of a column is a single value from 1 to w, then remove that value from corresponding column for any other row in the same group. If after doing so, more rows than before have sets with a single value from 1 to w, then repeat until no longer the case. 2. assertQuotaWithinSubGroup * most columns will be identical width, which I'll call W. Any group of consecutive columns with width less than W is a subgroup. Subgroups are the only columns that may contain 0 in the set of values. For a given row and a given subgroup, exactly one of the subgroup's columns will have a non-zero value in the solution. Therefore, if all but one column in a subgroup are single value sets containing {0}, then the remaining column cannot have zero in its set. Remove the zero from that column. * furthermore, if a column in a subgroup has width w, and there are already W-w rows in the group with the single-valued set {0} in that column, then the remaining rows cannot have 0 in the column. Remove the 0 from the column for those rows. * return a positive integer if any resulting set is reduced to a single value. 3. matchAndMate * for a given column, two rows in the table may have the same single-valued but non-zero set. You'll assume that these two rows refer to the same individual. Replace the contents of all columns in the two rows with the intersection of the sets found in both rows. If the operation changes the value of any row, return true. ## For Further Information If you want to get a head start, fork the reference code which can be found on [my GitHub page](https://github.com/ABridgeTooFar/codeGolfLogicChallenge). The repo supports codespaces so you can use Visual Studio Code to try out the initial implementation in a sandboxed environment. Whatever environment you decide to use, run the default example using python3. The relevant code for this part of the code golf challenge is found in the file named solver.py of the main branch. The default table for testing is stored in a file named PCgbWI.in. ``` python3 ./solver.py ``` To try a second example (or your own when you get used to the syntax), pass clues in table format to the program. For example: ``` python3 ./solver.py TCSA.in ``` Ignore the other files there: they were from before I extracted this small, algorithmically-interesting core part and split it into its own challenge ]
[Question] [ **This question already has answers here**: [Largest Number Printable](/questions/18028/largest-number-printable) (93 answers) Closed 6 years ago. This is a brainfuck version of [Largest Number Printable](https://codegolf.stackexchange.com/questions/18028/largest-number-printable), and [this](http://djm.cc/bignum-results.txt). --- Let's think about [brainfuck](https://esolangs.org/wiki/Brainfuck) interpreter such that, 1. Has array that can be stretched left & right arbitrary large 2. Each cell can contain arbitrary large integer * Can contain negative integer too 3. When the interpreter starts, every cell is intialized by 0 4. `.` prints integer representation of value of cell, then LF. For example, `<<+++.>--.` prints ``` 3 -2 ``` , then terminate. --- # Description Your goal is to write a brainfuck program that prints a number/numbers. The bigger the number, the more points you'll get. There are some rules to follow. * Your program **must** terminate. * You **should not** use `,`. * You **can** print multiple integers. * Your score will be largest number that the program prints. * Maximum code length is 1024 bytes. (Only `[]+-><.` counts) [Here](https://gist.github.com/0xrgb/3b71cc150073d4e9a251ef8303db11ee) is sample brainfuck interpreter that you could test. --- # Leaderboards :) [Answer] # Score: 2↑↑45306 Edit: Replaced it with a more modifiable version. Try [2↑↑2](https://tio.run/##lVPRjqsgEH1ev4I3NVSym/u2ofwI5RJXcZdEkaDdrf353gG5ttrEZEmMcGbOGeYAdhq/evPndtOd7d2IhmlI4tSppFYNqlpVGln1tcou@XuCYDg1np2BHxnOH5lL@d8TP4kToQwXIj2gFL5LHtiNNrVs@94u5AkdUa2rMcvD8gpLLsK06R3SSINwaT5V1ioDpMjyQzfowrVAxyNKeXrHgwwprVWmznS@4Kp9ZIgNw6lvKH0lFvZWvOWr2BRIPmUDA@IDOsDlMCg3hn1ec1/jNX@0ZwoGuLPJvHkH5F2I3XQWRF7DtLpPPxrZqW5tz8@XbpVPosjX8UprRzzCKzv3iDc9zoq88@G4IJ9qzDp7gM0ijN7WZq3Eit@JFbtiZCNmnTZj9qSS70iwjQSYiI@7Rekzo9hnbK8VxJ879Se9TlsO0p@xF9spsb2HK97KxSo2CApSmrJTUgYFKbtSGymjEGzQFwAVeLxkGGttiFNlHW/QPfzwkiO4ZPj6kHF/rasEf4cjcPifnd9uGCcMY5rwkMR4wRhmmFI6t88YC/85/EJ5QTHFjIllDckieWGsCIgAZI6BRJGIhJF/), [2↑↑3](https://tio.run/##lVPRjqsgEH1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AVeLxkGGttiFNlHW/QPfzwkiO4ZPj6kHF/rasEf4cjcPifnd9uGEbCMKYJD2mMF4xhhimlswGMsfCfwy@UFxRTzJhY1pAskhfGioAIQOYYSBSJSBj5Bw) ([2↑↑5](https://tio.run/##lVPRjqsgEH1ev4I3NVSym/u2ofwI5RJXcZdEkaDdrf353gG5ttrEZEmMcGbOGeYAdhq/evPndtOd7d2IhmlI4tSppFYNqlpVGln1tcou@XuCYDg1np2BHxnOH5lL@d8TP4kToQwXIj2gFL5LHtiNNrVs@94u5AkdUa2rMcvD8gpLLsK06R3SSINwaT5V1ioDpMjyQzfowrVAxyNKeXrHgwwprVWmznS@4Kp9ZIgNw6lvKH0lFvZWvOWr2BRIPmUDA@IDOsDlMCg3hn1ec1/jNX@0ZwoGuLPJvHkH5F2I3XQWRF7DtLpPPxrZqW5tz8@XbpVPosjX8UprRzzCKzv3iDc9zoq88@G4IJ9qzDp7gM0ijN7WZq3Eit@JFbtiZCNmnTZj9qSS70iwjQSYiI@7Rekzo9hnbK8VxJ879Se9TlsO0p@xF9spsb2HK97KxSo2CApSmrJTUgYFKbtSGymjEGzQFwAVeLxkGGttiFNlHW/QPfzwkiO4ZPj6kHF/rasEf4cjcPifnd9u2I@EYUwTHvIYLxjDDFNKZwcYY@E/h18oLyimmDGxrCFZJC@MFQERgMwxkCgSkTDyDw) times out) Just testing the waters with a short answer. ``` +>+>++>++>++>++++>++[>[<+++++>-]<<]> >++< [ >[->>+>+<<<] >>> [ <[-<+<+>>] <[->+<] >>- ] <[-]<<<- ] >. ``` The ↑↑ indicate [Knuth's arrow notation](https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation), where a single ↑, such as `X↑Y`, means (((X\*Y)\*Y)\*Y)... X times = X^Y, and two ↑↑s means (((X↑Y)↑Y)↑Y)... X times. For example, 2↑↑4 = 2222. (I'm not familiar with bignum notation, so please tell me if there's a shorter way of representing this, or there's an error in my calculations) # Explanation: ``` +>+>++>++>++>++++>++[>[<+++++>-]<<]> ``` Produces the number 45306. (Taken from the [brainfuck constants page on Esolangs](https://esolangs.org/wiki/Brainfuck_constants#45306), an immensely useful page). This will be used as the counter. ``` >++< ``` Sets the current value as two and move back to the counter ``` [ Loop until the counter is 0 Square the current value >[->>+>+<<<] >>> [ <[-<+<+>>] <[->+<] >>- ]<[-] Decrement the counter <<<- ] ``` A few ways to extend this: * Increase the counter. Pretty easy to do. * Increase the initial value. To be simple, you could just set the initial value and the counter as the same number * Remove the clear cell in the squaring operation, which compounds the result * Create another counter and put another loop around the whole thing + This effectively adds another Knuth's Arrow to the result (I think) + Further addition, for each iteration of the outer loop, copy the current value to use as the inner loop's counter + And then put another loop around the whole lot again. ]
[Question] [ **This question already has answers here**: [Connect-n time!](/questions/65977/connect-n-time) (12 answers) Closed 6 years ago. # Four-In-A-Row AI Tournament Today, we will be playing a [Four-In-A-Row](https://en.wikipedia.org/wiki/Connect_Four) tournament. However, it is not us humans playing... instead, we must have our computers battle instead! This challenge is completely in C#. ## **Rules** ### Basic Game Rules If you have never played, there are simple rules. 2 players take turns putting pieces into a 6x7 grid. The player chooses one of the 7 holes at the top of the grid, and puts a piece in. Gravity pulls the piece down, until it hits another piece underneath it. The game is won when a player gets four of their pieces in a straight line, either vertical or horizontal. Diagonal lines **do not** count in this challenge, as I was lazy when programming my simulator. This will also make it easier for you to code your AIs. ### Code Format You will write code that goes into a function that gets called when it is your turn. You can receive an argument, `states[,] board` where `states` is an enum with `defender, attacker, empty`. This represents the occupation of a space. Your method must return an int. ### Game Ending The game ends when someone gets a four-in-a-row, or makes an illegal move. An illegal move is when your program returns an int that is 1) off the board (< 0 or > 6) or in a column that is completely filled. In the case of an illegal move, the opponent immediately wins. Additionally, if your program exits the function or the program, you automatically lose the match. If your program causes a runtime error, you lose the match. **You *are* allowed to try to make the other program cause a runtime error.** ### Variables You are not allowed to access any variables, properties, or run any methods outside of your function's scope. You are not allowed to define any variables outside of your function's scope. One exception is the `Dictionary<string, object>` names `variables` I have provided for your convenience. It is in the class `Programs`, so it will keep it's data for the whole match. However, the opponent uses the same dictionary to save its data. One strategy is to sabotage the enemy program by modifying the data it uses. ### Closing the Loopholes Your submission may not make any external requests, for example to an online API. Your submission may not include a library that is made to solve four-in-a-row games. As a rule of thumb, your program shouldn't need to use anything except `system` or anything included in the `system` library. You may not exploit any loopholes, either stated or implied in the rules, unless you have asked me through comments and I agreed. ### Tournament Format This is a [king-of-the-hill](/questions/tagged/king-of-the-hill "show questions tagged 'king-of-the-hill'") tournament, so the AI will be competing against each other. I will post the first answer. The next person will have to beat my program. To beat a program, you must never lose to it. You are only required to beat the program right before you. This process goes on until an answer has not been superseded after one week. You may answer as many times as you want, but you may not counter your own program. You may make edits to your code until it has been superseded. In a nutshell, you must write a program that never loses to its predecessor. ### Testing [Click here to see my match simulation.](https://github.com/yummypasta/FourInARowEngine) Paste in your code in the `Programs.cs` file, in your corresponding function. The attacker is the one who is trying to supersede a program. The defender is the one whos program is attempting to hold its place. The defender always moves first. After your program has been pasted in, run it. The console will open, and it will run the simulation. ### Submission Format Your submission must be in C#. Your submission must compile correctly. Your submission must follow this format: ``` #<answer number> [Previous](<Permalink to previous answer>) CODE HERE CODE HERE ``` ### TL;DR Basically, you will be coding AIs to compete in four-in-a-row. However, read the whole thing if you want to compete! # Good luck! [Answer] # 1 First answer! ``` if(!variables.ContainsKey("randy")){ variables["randy"] = new Random(); } return ((Random)variables["randy"]).Next(0, 7); ``` ]
[Question] [ **This question already has answers here**: [Find sum of odd numbers](/questions/2487/find-sum-of-odd-numbers) (6 answers) Closed 7 years ago. ## Challenge Given an integer `n`, calculate the sum of **all even numbers** between 0 and `n` ## Examples ``` n output ------------- 100 2550 255 16256 1000 2502500 ``` --- Shortest code in bytes wins [Answer] ## Scala - 18 bytes shortest I could figure: ``` (0 to i by 2).sum ``` Using an anonymous function: ``` val i = (N:Int) => (0 to N by 2).sum ``` ]
[Question] [ **This question already has answers here**: [Electron Configurations](/questions/37657/electron-configurations) (6 answers) Closed 7 years ago. Given a atomic number, print how many electrons are in each shell of the element that the atomic number corresponds to. ## Expected input/output: ``` Input -> Output 1 -> 1 2 -> 2 3 -> 2, 1 4 -> 2, 2 5 -> 2, 3 6 -> 2, 4 7 -> 2, 5 8 -> 2, 6 9 -> 2, 7 10 -> 2, 8 11 -> 2, 8, 1 12 -> 2, 8, 2 13 -> 2, 8, 3 14 -> 2, 8, 4 15 -> 2, 8, 5 16 -> 2, 8, 6 17 -> 2, 8, 7 18 -> 2, 8, 8 19 -> 2, 8, 8, 1 20 -> 2, 8, 8, 2 21 -> 2, 8, 9, 2 22 -> 2, 8, 10, 2 23 -> 2, 8, 11, 2 24 -> 2, 8, 13, 1 25 -> 2, 8, 13, 2 26 -> 2, 8, 14, 2 27 -> 2, 8, 15, 2 28 -> 2, 8, 16, 2 29 -> 2, 8, 18, 1 30 -> 2, 8, 18, 2 31 -> 2, 8, 18, 3 32 -> 2, 8, 18, 4 33 -> 2, 8, 18, 5 34 -> 2, 8, 18, 6 35 -> 2, 8, 18, 7 36 -> 2, 8, 18, 8 37 -> 2, 8, 18, 8, 1 38 -> 2, 8, 18, 8, 2 39 -> 2, 8, 18, 9, 2 40 -> 2, 8, 18, 10, 2 41 -> 2, 8, 18, 12, 1 42 -> 2, 8, 18, 13, 1 43 -> 2, 8, 18, 13, 2 44 -> 2, 8, 18, 15, 1 45 -> 2, 8, 18, 16, 1 46 -> 2, 8, 18, 18 47 -> 2, 8, 18, 18, 1 48 -> 2, 8, 18, 18, 2 49 -> 2, 8, 18, 18, 3 50 -> 2, 8, 18, 18, 4 51 -> 2, 8, 18, 18, 5 52 -> 2, 8, 18, 18, 6 53 -> 2, 8, 18, 18, 7 54 -> 2, 8, 18, 18, 8 55 -> 2, 8, 18, 18, 8, 1 56 -> 2, 8, 18, 18, 8, 2 57 -> 2, 8, 18, 18, 9, 2 58 -> 2, 8, 18, 19, 9, 2 59 -> 2, 8, 18, 21, 8, 2 60 -> 2, 8, 18, 22, 8, 2 61 -> 2, 8, 18, 23, 8, 2 62 -> 2, 8, 18, 24, 8, 2 63 -> 2, 8, 18, 25, 8, 2 64 -> 2, 8, 18, 25, 9, 2 65 -> 2, 8, 18, 27, 8, 2 66 -> 2, 8, 18, 28, 8, 2 67 -> 2, 8, 18, 29, 8, 2 68 -> 2, 8, 18, 30, 8, 2 69 -> 2, 8, 18, 31, 8, 2 70 -> 2, 8, 18, 32, 8, 2 71 -> 2, 8, 18, 32, 9, 2 72 -> 2, 8, 18, 32, 10, 2 73 -> 2, 8, 18, 32, 11, 2 74 -> 2, 8, 18, 32, 12, 2 75 -> 2, 8, 18, 32, 13, 2 76 -> 2, 8, 18, 32, 14, 2 77 -> 2, 8, 18, 32, 15, 2 78 -> 2, 8, 18, 32, 17, 1 79 -> 2, 8, 18, 32, 18, 1 80 -> 2, 8, 18, 32, 18, 2 81 -> 2, 8, 18, 32, 18, 3 82 -> 2, 8, 18, 32, 18, 4 83 -> 2, 8, 18, 32, 18, 5 84 -> 2, 8, 18, 32, 18, 6 85 -> 2, 8, 18, 32, 18, 7 86 -> 2, 8, 18, 32, 18, 8 87 -> 2, 8, 18, 32, 18, 8, 1 88 -> 2, 8, 18, 32, 18, 8, 2 89 -> 2, 8, 18, 32, 18, 9, 2 90 -> 2, 8, 18, 32, 18, 10, 2 91 -> 2, 8, 18, 32, 20, 9, 2 92 -> 2, 8, 18, 32, 21, 9, 2 93 -> 2, 8, 18, 32, 22, 9, 2 94 -> 2, 8, 18, 32, 24, 8, 2 95 -> 2, 8, 18, 32, 25, 8, 2 96 -> 2, 8, 18, 32, 25, 9, 2 97 -> 2, 8, 18, 32, 27, 8, 2 98 -> 2, 8, 18, 32, 28, 8, 2 99 -> 2, 8, 18, 32, 29, 8, 2 100 -> 2, 8, 18, 32, 30, 8, 2 101 -> 2, 8, 18, 32, 31, 8, 2 102 -> 2, 8, 18, 32, 32, 8, 2 103 -> 2, 8, 18, 32, 32, 8, 3 104 -> 2, 8, 18, 32, 32, 10, 2 105 -> 2, 8, 18, 32, 32, 11, 2 106 -> 2, 8, 18, 32, 32, 12, 2 107 -> 2, 8, 18, 32, 32, 13, 2 108 -> 2, 8, 18, 32, 32, 14, 2 109 -> 2, 8, 18, 32, 32, 15, 2 110 -> 2, 8, 18, 32, 32, 16, 3 111 -> 2, 8, 18, 32, 32, 17, 2 112 -> 2, 8, 18, 32, 32, 18, 2 113 -> 2, 8, 18, 32, 32, 18, 3 114 -> 2, 8, 18, 32, 32, 18, 4 115 -> 2, 8, 18, 32, 32, 18, 5 116 -> 2, 8, 18, 32, 32, 18, 6 117 -> 2, 8, 18, 32, 32, 18, 7 118 -> 2, 8, 18, 32, 32, 18, 8 ``` Psst... take a closer look at the output, it's not always the last shell incrementing. Remember, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the smallest number of bytes wins. ## Leaderboards Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language. To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template: ``` # Language Name, N bytes ``` where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance: ``` # Ruby, <s>104</s> <s>101</s> 96 bytes ``` If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header: ``` # Perl, 43 + 2 (-p flag) = 45 bytes ``` You can also make the language name a link which will then show up in the leaderboard snippet: ``` # [><>](http://esolangs.org/wiki/Fish), 121 bytes ``` ``` var QUESTION_ID=94753,OVERRIDE_USER=12537;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i; ``` ``` body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px} ``` ``` <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> ``` [Answer] # Mathematica, 42 bytes ``` Tr/@#~ElementData~"ElectronConfiguration"& ``` ]
[Question] [ **This question already has answers here**: [Convert from binary to negabinary](/questions/4447/convert-from-binary-to-negabinary) (12 answers) Closed 7 years ago. We already have a [base conversion question](https://codegolf.stackexchange.com/questions/69155/base-conversion-with-strings), but not one with negative bases (nope, [this](https://codegolf.stackexchange.com/questions/4447/convert-from-binary-to-negabinary) doesn't count). ([Corresponding wiki article](https://en.wikipedia.org/wiki/Negative_base).) You will receive a number (may be negative) and a base (must be negative), and your task is to convert the number into the base. The base will only be from `-10` to `-2`. ### Specs * You may receive the number in any positive base, including unary. * You may choose receive the magnitude of the base instead (`10` instead of `-10`). * The input can be taken in any reasonable format. ### Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest solution in bytes wins. ### Testcases ``` input output 8163, -10 12243 -8163, -10 9977 17, -3 212 ``` [Answer] ## Jelly, 1 byte ``` b ``` Jelly supports negative bases with its base conversion builtin. [Try it online!](http://jelly.tryitonline.net/#code=Yg&input=&args=ODE2Mw+LTEw) (`bV` at two bytes if the output must be a single integer.) ]
[Question] [ **This question already has answers here**: [Rotate an ASCII art image](/questions/5194/rotate-an-ascii-art-image) (5 answers) [Rotate simple ASCII art [closed]](/questions/20154/rotate-simple-ascii-art) (11 answers) Closed 9 years ago. ## Rules * Write a program in a language of your choice. * That program is designed to rotate a block of text. Example: ``` BOB 90 deg DCB CAT --> OAO DOG CW GTB ``` * You may assume the blocks of text are loaded into a variable `block`. * You may assume a square block, but of any size. * You may assume the line-endings are `\n`. * You're not allowed to use a library that already rotates blocks of text. * Code Golf rules, shortest program wins. [Answer] # GolfScript, 11 characters ``` n/-1%zip n* ``` Explanation: ``` n/ # split on newline -1% # reverse array zip # "rotate" (will turn ['abc' 'def' 'ghi'] into ['adg' 'beh' 'cfi']) n* # join with newline again ``` [Answer] # Python, 0 bytes My program rotates the block of text by 720 degrees. ]
[Question] [ **This question already has answers here**: [Encode a program with the fewest distinct characters possible](/questions/11690/encode-a-program-with-the-fewest-distinct-characters-possible) (10 answers) Closed 3 years ago. As the title suggests, my task is fairly straightforward: Write a program in your language of choice that will print out the first 20 Fibonacci numbers using the least unique characters. For example in Python 2: ``` def fib(n): a,b = 1,1 for i in range(n-1): a,b = b,a+b return a for i in range(1,21):print fib(i) ``` This would have a score of 24, as it has 24 unique characters **including whitespace**. [Answer] # CJam, 2 unique characters (1070 bytes) ``` S))))))))))))))))))SS))))))))))))))))))SS)))))))))))))))))))SS))))))))))))))) )))))SS))))))))))))))))))))))SS)))))))))))))))))))))))))SS))))))))))))))))))S ))))))))))))))))))))SS)))))))))))))))))))S))))))))))))))))))SS))))))))))))))) )))))S)))))))))))))))))))))SS))))))))))))))))))))))S))))))))))))))))))))))SS) ))))))))))))))))))))))))S))))))))))))))))))))))))))SS))))))))))))))))))S))))) ))))))))))))))))S)))))))))))))))))))))SS)))))))))))))))))))S))))))))))))))))) )))S))))))))))))))))))))SS))))))))))))))))))))S))))))))))))))))))))))))S))))) )))))))))))))))))))SS)))))))))))))))))))))))S))))))))))))))))))S))))))))))))) ))))SS))))))))))))))))))))))))))S)))))))))))))))))))))))))S)))))))))))))))))) ))))))SS))))))))))))))))))S))))))))))))))))))))))S))))))))))))))))))))))))))S ))))))))))))))))))))))))SS)))))))))))))))))))S))))))))))))))))))))))S)))))))) )))))))))))))))))S)))))))))))))))))))))SS)))))))))))))))))))))S)))))))))))))) ))))S)))))))))))))))))))))))))S))))))))))))))))))SS)))))))))))))))))))))))S)) ))))))))))))))))))))))S)))))))))))))))))))))))S)))))))))))))))))))))) ``` The linefeeds are included for "readability". Try it online in the [CJam interpreter](http://cjam.aditsu.net/#code=S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29SS%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29S%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29%29). ### How it works For starters, we don't actually calculate Fibonacci numbers, but build the string ``` 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 ``` byte by byte. Keeping that in mind, we only need two characters to obtain the desired output: * `S` pushes the string `" "`. * `)` serves two purposes here: 1. When the topmost item on the stack is a string, `)` pops its last character. `S)` leaves an empty string and the space character on the stack. 2. When the topmost item on the stack is a character, `)` increments its code point. This way, `S))))))))))))))))))` pushes the character `1`. After the program finishes, CJam automatically prints all items on the stack. Fortunately, the empty strings pushed by `S)` aren't visible in the output. [Answer] # Unary - 1 unique character You all knew it was coming. ``` 16552026807580920665211491750921730725235456808115643715721126181201732948544576109630429486831063241863270261670172778716193514984700165915528962410601287909151038925505538654870723736863226948250191139201776105749450716207585389147819928943248825902527229387923577427801786113554433618089574276607647435912941850901589122233248109334271085540771125628916636 0's ``` The equivalent brainfuck program: ``` -[----->+<]>--.>++++++++++.[->+++++<]>-.>++++++++++.[->+++++<]>.>++++++++++.[->+++++<]>+.>++++++++++.-[----->+<]>.>++++++++++.+[->+++++<]>+.>++++++++++.[->+++++<]>-.++.>++++++++++.[->+++++<]>.-.>++++++++++.[->+++++<]>+.+.>++++++++++.-[----->+<]>..>++++++++++.+[->+++++<]>+.+.>++++++++++.[->+++++<]>-.+++..>++++++++++.[->+++++<]>.+..>++++++++++.[->+++++<]>+.++++..>++++++++++.-[->++++++<]>.-----.-.>++++++++++.+[->+++++<]>++.-.-.>++++++++++.[->+++++<]>-.++++.++++.--.>++++++++++.[->+++++<]>.+++.+++.----.>++++++++++.-[----->+<]>-.---.+++++++.-------.>++++++++++.-[->++++++<]>.+.-.-. ``` It doesn't even bother doing anything with Fibonacci's, just prints the literals. [Answer] # Whitespace, 3 unique characters Dammit, CJam. Space characters are replaced into `S`, and tabs are `T`, line feeds are `L`. ``` SSSLSSSTSTSTLTTSSSSLSSSTLLSSLSSSLTTTSSSTLTSSTSLSLTSTLSSSLSLTTTSSLSTLSTSSSTSTSLTLSSSLTSTSSTSLTSSSLSLLLSSTLLLL ``` or xxd. ``` $ xxd fib.ws 0000000: 2020 200a 2020 2009 2009 2009 0a09 0920 . . . .... 0000010: 2020 200a 2020 2009 0a0a 2020 0a20 2020 . ... . 0000020: 0a09 0909 2020 2009 0a09 2020 0920 0a20 .... ... . . 0000030: 0a09 2009 0a20 2020 0a20 0a09 0909 2020 .. .. . .... 0000040: 0a20 090a 2009 2020 2009 2009 200a 090a . .. . . . ... 0000050: 2020 200a 0920 0920 2009 200a 0920 2020 .. . . .. 0000060: 0a20 0a0a 0a20 2009 0a0a 0a0a . ... ..... ``` --- I made it from [Whitelips](http://whitespace.kauaveel.ee/) by compiling assembly(?) code. You can compile and run below at Whitelips. ``` ;;;; store repeat count to heap push 0 push 21 store ;;;; initial setup push 0 push 1 ;;;; repeat repeat: ;;;; check end of loop push 0 retrieve push 1 sub dup jz end push 0 swap store ;;;; print dup printi push 10 printc ;;;; add swap copy 2 add jmp repeat ;;;; end end: end ``` [Answer] ## Python 2, 8 unique chars Uses characters `print+1,`. 35444 chars total. Because of SE character limits, I post an abbreviated version below that only prints the first 14 Fibonacci numbers, but I think it should be clear how to extend it. ``` print+1,+1,+1+1,+1+1+1,+1+1+1+1+1,+1+1+1+1+1+1+1+1,+1+1+1+1+1+1+1+1+1+1+1+1+1,+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1,+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1,+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1,+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1,+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1,+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1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1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1 ``` Here is code to generate the code string `s`: ``` def fib(n): a,b = 1,1 for i in range(n-1): a,b = b,a+b return a s="print" for i in range(1,21): n=fib(i) s+="+1"*n+',' s=s[:-1] ``` In Python REPL, as well as in many languages, one could omit the `print`, reducing the score to 3. [Answer] # Brainfuck, 2 unique characters ## 7801 characters ``` +++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++.++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++.+.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++.+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++.+++..++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++.+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++.++++..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++.++++.++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++.+++.+++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++.+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. ``` **Output:** `1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765` [Ideone](http://ideone.com/0vZqqK) Here is the code that wrote this program: ``` ans = "1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765" x=[ord(c) for c in ans] s="" n=0 for q in x: if q > n: d = q - n elif q < n: d = 256 - n d += q else: d=0 s+= "+"*d + "." n += d if n>255: n-=256 print s ``` [Answer] # Ruby, 6 unique characters, ~~183~~ 118 bytes, actually does the calculation. 183 byte version with `p+=1` space and `\n` ``` p p=1 p pp=1 p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p p p=p+pp p pp=pp+p ``` It looks like some oddball esolang (like Brainfuck or Perl for example), but it's valid ruby. We have 2 variables `p` and `pp` to accumulate the numbers in, and we print by means of the `p` command at the beginning of the line. **118 byte version, with comma instead of newline, and += instead of addition.** ``` p p=1,pp=1,p+=pp,pp+=p,p+=pp,pp+=p,p+=pp,pp+=p,p+=pp,pp+=p,p+=pp,pp+=p,p+=pp,pp+=p,p+=pp,pp+=p,p+=pp,pp+=p,p+=pp,pp+=p ``` [Answer] # dc, 5 unique Shortest "non-esoteric" answer so far. Characters used are `2i10P` ``` 2i110001001000000011000100100000001100100010000000110011001000000011010100100000001110000010000000110001001100110010000000110010001100010010000000110011001101000010000000110101001101010010000000111000001110010010000000110001001101000011010000100000001100100011001100110011001000000011001100110111001101110010000000110110001100010011000000100000001110010011100000110111001000000011000100110101001110010011011100100000001100100011010100111000001101000010000000110100001100010011100000110001001000000011011000110111001101100011010100001010P ``` I guess its open to debate whether or not `dc` is esoteric. [Answer] # [Fish (><>)](http://esolangs.org/wiki/Fish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1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1--111-1-1-1-1-1-1-1-1-1-1-1-1-1-1--1p ``` Actually calculates the Fibonacci numbers using the program ``` 01aa+v @+&1->:?!;&:nao: ``` which is placed into the codebox using only `-1p`. [Answer] # JavaScript, 6 unique ``` [][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]()[+!+[]+[!+[]+!+[]]]+[+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[!+[]+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[!+[]+!+[]+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[+!+[]]+[!+[]+!+[]+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[!+[]+!+[]]+[+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[!+[]+!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]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+!+[]+!+[]]+[+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]()[+!+[]+[!+[]+!+[]]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]])() ``` This has a total of 6547 characters and alerts the string `"1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765"`. [Answer] # [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 2 unique, 6786 bytes ``` zzppzpzpzzpzzzpzzzzzpzzzzzzzzpzzzzzzzzzzzzzpzzzzzzzzzzzzzzzzzzzzzpzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzpzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzpzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzpzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzpzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzpzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz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zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzp ``` [Try it online!](https://tio.run/nexus/dc#7dZbCgARFADQLfu@m7@ilA8p05TSOR4hhGYiI0qJFlrsaeRzYVHbt552@XXczZlfWZCdOnnwiQH@bQDcHgAAfH8YZlY "dc – TIO Nexus") The only characters used are `p` and `z`. Here's a run with output: ``` $ dc -f fibo 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 ``` [Answer] # SmileBASIC, 3 unique chars (409 bytes) Characters used: `?`, `1`, `-` (Line breaks inserted for readability) ``` ?1 ?1 ?1--1 ?1--1--1 ?1--1--1--1--1 ?11-1-1-1 ?11--1--1 ?11--11-1 ?11--11--11--1 ?11--11--11--11--11 ?111-11-11 ?111--11--11--11--11--11 ?111--111--11 ?111--111--111--11--11--11--11 ?111--111--111--111--111--11--11--11--11--11 ?1111-111-11-1-1 ?1111--111--111--111--111--11--11--11--11-1-1 ?1111--1111--111--111--111--11--11--11-1-1-1-1 ?1111--1111--1111--1111-111-111-11-11-11-11--1--1--1 ?11111-1111-1111-1111-1111--111-11-1-1 ``` `?` is the same as `PRINT` I used `-` instead of `+` to allow both addition and subtraction, which (probably) makes it shorter (not that it matters). Probably works in other BASIC dialects, as long as they don't care about the lack of separation between lines. Also works in my unfinished [language](https://github.com/12Me21/language/). (Online interpreter: <https://12me21.github.io/language/wasm/>) [Answer] # Golfscript, 4 unique characters Uses `1 +p` (literal space) Only pasting the first 7.... ``` 1p 1p 1 1+p 1 1+1+p 1 1+1+1+1+p 1 1+1+1+1+1+1+1+p 1 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+p ``` It gets out of hand quickly. Copy, paste, copy, paste, copy, paste the same sequence. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 2 unique chars ``` ‘ṄṄ‘Ṅ‘Ṅ‘‘Ṅ‘‘‘Ṅ‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Ṅ‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ ``` [Try it online!](https://tio.run/##7djBCYAgFADQabuIC3jr0BCt0ji2yC8IIoIghCLowUM@KioqKqYu5xIx92OdhtUW7OkxOMVXOXeKmms@18LXOvrJOM0Glgy7F8BpAwAuSgAA8CYHAAAAAD9XAAAAAAAAALwsYgE "Jelly – Try It Online") ]
[Question] [ ## The program Given a number, program must return the alphabet letter correspondent. ## Rules * The challenge here is to make it as short as possible, everyone knows it is a very easy program to do. * The number is not zero-based, it means `1` is `A`, `2` is `B`, `3` is `C` and so it goes... * Any language will be accepted. [Answer] ## APL (4) (Full program) ``` ⎕⌷⎕A ``` Explanation: `⎕` (user input) `⌷` (index) `⎕A` (alphabet) (They're supposed to be boxes, it's not an encoding problem.) [Answer] # Brainfuck, 107 bytes ``` >,----------[>++++++[-<------>],----------]<[<]>>[<--[->++++++++++<]>>]+++++++[-<+++++++++>]<-.>++++++++++. ``` [Answer] # [brainfuck](https://github.com/TryItOnline/brainfuck), ~~64 56~~ 50 bytes *Thanks to Dorian for saving 3 bytes and inspiring 3 more* ``` ,>,[<+[-<+>[-<]>>]<[<++<-]>++>>]<<+++[->+++++<]>+. ``` [Try it online!](https://tio.run/##SypKzMxLK03O/v9fx04n2kY7WtdG2w5IxNrZxdoA@do2urF22togHpADlAZygAAor633/7@hAQA "brainfuck – Try It Online") ## How it works ``` ,>, Gets input [ if a two digit number <+[-<+>[-<]>>] Gets modulo 2 of first number plus 1 <[<++<-] Sets the fives cell to 2 if the first number is a 2 >++ Adds another 2 to the fives cell >>] Moves to cell after ones cell <<+++ Adds 3 to fives cell [->+++++<] Multiply the fives cell by 5 and add it to the ones cell >+. Add one and print ``` [Answer] # DC - 6 characters *Full program* including input and output. ``` ?64+af ``` save to file and run with `$ dc file` [Answer] ## R, 11 characters ``` LETTERS[x] ``` Usage: ``` LETTERS[21] [1] "U" ``` [Answer] # [Befunge-93](https://github.com/catseye/Befunge-93), ~~7~~ 6 bytes ``` "&++,@ ``` [Try it online!](https://tio.run/##S0pNK81LT/3/X0lNW1vH4f9/QwA "Befunge-93 – Try It Online") Takes advantage of the extra spaces at the end of a wrapping string literal by adding two spaces (`32*2 = 64`) to the inputted number to turn it into the corresponding alphabetic character. Funnily enough, if we use a implementation that doesn’t include the wrapping spaces, we can do `"&+.@` to add the `@` (64) to the number instead. [Answer] ## J, 7 characters ``` a.{~64+ ``` Usage: ``` a.{~64+1 A ``` [Answer] # TI-Basic, 34 bytes ``` sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",Ans,1 ``` This is as short as it gets... [Answer] # PHP, 17 bytes ``` <?=chr(64+$argn); ``` Run s pipe with `-F` [Answer] # [Ly](https://github.com/LyricLy/Ly), 6 bytes ``` n8:*+o ``` [Try it online!](https://tio.run/##y6n8/z/PwkpLO///fyMTAA "Ly – Try It Online") [Answer] # [Husk](https://github.com/barbuz/Husk), 4 bytes ``` c+64 ``` [Try it online!](https://tio.run/##yygtzv7/P1nbzOT///9GZgA "Husk – Try It Online") Boring, but probably optimal. Adds 64 to the given number and converts it to ASCII. `!¡→'A` is cuter (awww, the exclamation marks are friends!) but one byte longer. [Answer] # Pyth - ~~5~~ 3 Bytes ``` @Gt ``` Saved two bytes thanks to ovs Completely forgot about `t` and implicit `Q` Explanation: ``` @ Index G in alphabet of t one less than Q Input (implicitly added to solve arity) ``` [Answer] # Perl, 20 characters ``` chr(($ARGV[0] + 64)) ``` Verification : ``` risk@skynet:~/perl$ for x in {1..26}; do perl ./ord.pl $x; done; ABCDEFGHIJKLMNOPQRSTUVWXYZrisk@skynet:~/perl$ ``` [Answer] # [Hexagony](https://github.com/m-ender/hexagony), 10 Bytes [Try it online!](https://tio.run/##y0itSEzPz6v8/19BwVFBQ6GaS0FfQV1BW8Gayx7IclDQU9DjAhEQBoT@/9/QCAA) ``` A({/'+;?/@ ``` Expanded: ``` A ( { / ' + ; ? / @ . . . . . . . . . ``` This honestly took me way longer than it should have, as it's just 2 simple reflections. --- The simplest version for this problem is only 2 bytes longer ``` A ( { . . . . ? ' + ; @ . . . . . . . ``` [Answer] # Powershell 6, 17 bytes ``` ('@'..'Z')[$args] ``` [Answer] # PowerShell, 19 18 bytes -1 byte thanks to @mazzy lol I don't think it'll get much shorter than this. ``` [char](64+"$args") ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Pzo5I7EoVsPMRFtJJbEovVhJ8/9/AA "PowerShell – Try It Online") Takes input from a command line argument. [Answer] # [MATL](https://github.com/lmendo/MATL), 4 bytes ``` 64+c ``` [Try it online!](https://tio.run/##y00syfn/38xEO/n/fyMA "MATL – Try It Online") Because, why not. Takes input implicitly, pushes `64` and adds it to the input number. Finally it converts the number to its ASCII-equivalent using `c`. [Answer] # q/k (7) As partially applied composition: ``` 10h$64+ ``` [Answer] ## Ruby 1.9 (10) ``` (x+64).chr ``` Reading from STDIN and printing to STDOUT: ``` $><<(gets.to_i+64).chr ``` [Answer] # Burlesque (6 characters) Assuming the number is already on the stack: ``` 64.+L[ ``` (see [here](http://eso.mroman.ch/cgi/burlesque.cgi?q=3+64.%2BL%5b) in action.). Does the usual: Add 64, convert to character based on ASCII value. If number is supplied as a string via stdin to stdout (10 characters): ``` ri64.+L[sh ``` Alternative version without using ASCII value conversion: ``` '@'Zr@\/!! ``` [Answer] ## Javascript, 25 chars ``` String.fromCharCode(66-x); ``` ## PHP, 22 chars ``` echo chr(66-$argv[0]) ``` [Answer] # GolfScript, 7 ``` 64+]''+ ``` ### Commentary ``` 64 # corresponds to '@' in ASCII (65 is 'A') +] # add the input to 64. ']' is used for ASCII. ''+ # the conversion process ``` **[1 corresponds to A](http://golfscript.apphb.com/?c=OyAxCjY0K10nJys%3D)** **[26 corresponds to Z](http://golfscript.apphb.com/?c=OyAyNgo2NCtdJycrCg%3D%3D)** [Answer] # Classic ASP (14 bytes): ``` <%=Chr(c+64)%> ``` *Expects `c` to hold the character number.* [Answer] **C#** 4,50KB (196 characters) My first time here =) ``` using System; namespace W { class P { static void Main(string[] args) { Console.WriteLine(" abcdefghijklmnopqrstuvwxyz".ToCharArray()[int.Parse(Console.ReadLine())]); } } } ``` [Answer] # C#, 87 ``` class P{static void Main(string[]a){System.Console.Write((char)(int.Parse(a[0])+64));}} ``` Complete program (not some (part of a) "function" expecting foo to be bar to work), accepts command line parameter: `foo.exe 1` prints `A`, `foo.exe 16` prints `P` # C#, 10 When I make the same assumptions as, for example, the 'code-golfers' that posted the [~~VSCript~~ Classic ASP](https://codegolf.stackexchange.com/a/21448/14039), [Python](https://codegolf.stackexchange.com/a/7326/14039), [Burlesque](https://codegolf.stackexchange.com/a/7318/14039), [Ruby](https://codegolf.stackexchange.com/a/7317/14039), [C](https://codegolf.stackexchange.com/a/7316/14039) solutions we can get it down to 10: ``` (char)x+64 ``` "Assuming `x` is magically initialized / passed in / on the stack / whatever excuse" and the contest doesn't explicitly require me to print it, just "return" it (which most of the above solutions don't do, either). [Answer] # [Tcl](http://tcl.tk/), 30 bytes ``` puts [expr [scan $argv %c]-64] ``` [Try it online!](https://tio.run/##K0nO@f@/oLSkWCE6taKgSCG6ODkxT0ElsSi9TEE1OVbXzCT2////jgA "Tcl – Try It Online") [Answer] # Python 2, 9 bytes ``` chr(64+x) ``` ### Or, reading from stdin and printing to stdout: 21 ``` print chr(64+input()) ``` [Answer] BrainFuck, 66 ``` ,>,----------[<[->++++++++++<]++++++[>+++++++<-]>>]++++[<++++>-]<. ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes ``` ịØA ``` [Try it online!](https://tio.run/##y0rNyan8///h7u7DMxz///9vCgA "Jelly – Try It Online") [Answer] # SmileBASIC, 18 bytes ``` INPUT N?CHR$(N+64) ``` ]
[Question] [ Given an input array having minimum length `2` and maximum length `9` having any initial values output an array having length `2` consisting of the 1-based indexes of the array represented as either an integer or string in forward and reverse order. The values of the array or string do not matter and are ignored. For example: ``` [undefined,null] -> [12,21] ``` **Test cases** Input -> Output ``` ["a","e","i","o","u"] -> [12345,54321] // valid [{"a":1},{"b":2},{"c":3}] -> [123,321] // valid [-1,22,33,44,55,66,77,88,99] -> ["123456789","987654321"] // valid [0,1] -> [01,10] // invalid, not a 1-based index, `01` is not a valid integer [1999,2000] -> [12,"21"] invalid, output either integers or strings ``` **Winning criteria** Least bytes. [Answer] # [Python 2](https://docs.python.org/2/), 53 bytes ``` n=len(input())+1 b=10**n/81-n/9 print[b,10**n/90*n-b] ``` [Try it online!](https://tio.run/##K6gsycjPM/qfnJ@SqmCroK6u/j/PNic1TyMzr6C0RENTU9uQK8nW0EBLK0/fwlA3T9@Sq6AoM68kOkkHImhpoJWnmxT7H6iTK7UiNVkBbJKWguX/aEMdw1guEImgkVmobHQeJh@bCFAMAA "Python 2 – Try It Online") For example, for \$n=5\$: \begin{align} 12345 &= 11111 + 1111 + 111 + 11 + 1 \\ &= (11111.\bar1 + 1111.\bar1 + \dots + 1.\bar1) - (0.\bar1 \times 5) \\ &= \frac{10}{9} \left( \sum\_{k=0}^{n-1} 10^{k} \right) - \frac n9 \\ &= \frac{10}{9} \left( \frac{1-10^n}{1-10} \right) - \frac{n}{9} \\ &= \frac{10^{n+1}-1}{81}-\frac{n+1}{9} \end{align} We use integer (floor) division, so the surplus \$\frac{1}{81}\$ gets rounded away. For the descending part, if `b=12345` we compute something like `66666-12345 == 54321`. [Answer] # [Python 2](https://docs.python.org/2/), 44 bytes ``` s='123456789'[:len(input())] print s,s[::-1] ``` [Try it online!](https://tio.run/##LcvLCsMgEEDRdfyK2Y1CCtG@B/IlIQvb2kRIJqIG2q@3z/U9NzzzuLAp9yXC5HjII3iGaHlw0tSgG0Wi8hzWDC1Mdr7cLP3zjytRuYe7AiKW1KI2293@cDydsaM3kN9VKtWLED1nSHXqiDa6L5/hBQ "Python 2 – Try It Online") [Answer] # [Python 2](https://docs.python.org/2/), ~~55~~ 52 bytes ``` a='' for i in input():a+=`-~len(a)` print[a,a[::-1]] ``` [Try it online!](https://tio.run/##HYxbCoMwEEX/XUXIT7QdIYn1kYArkYCpTWmgJCIKLWK3nk4Lc@bCPczM7/URg0xTvDnSE8ZYsj1j2T0uxBMfcOZtzQttz/1Yfp4u5LYYs3nxYR0s2EHrUhiT8DBzLzeR/6MTqdNALQXqEI9EZKMmG3astThgp1eq5S8nqqsDTSlASqgquFygrqFpoG2h60AplBwEbqGUAsk5N18 "Python 2 – Try It Online") Explanation: ``` # initial value: empty string a='' # iterate over input # will work with any iterable object: list, tuple, dict, set, string, etc. for i in input(): # add to a string representation of its length+1 a+=`-~len(a)` # print list, composed from a and its reversed version print[a,a[::-1]] ``` # [Python 2](https://docs.python.org/2/), 66 bytes ``` lambda i:`map(abs,range(-len(i),-~len(i)))`[1::3].split('0')[::-1] ``` [Try it online!](https://tio.run/##JY1BCsIwFAX3PUXIxgR@JUlraz54A28QA021aqBNQ60LEb16TXExzINZvPia72NQy/FwWno3tBdHPDaDi8y1D5hcuHUs77vAPIf8@x@cN0YiFnb7iL2f2UZsuEHMpV2u40R8iAliDHUUaJfwiTHxpBZIZt4poPzAm7YU1eozxeJjITO5BKWgKKAsYbeDqoK6hv0etF6rALlKaq1BCSGsxYzEyYeZHFm65csP "Python 2 – Try It Online") Explanation: ``` lambda i:`map(abs,range(-len(i),-~len(i)))`[1::3].split('0')[::-1] # unnamed lambda # example input: ['q', 'w', 'e', 'r', 't'] # create range from minus length of input to length+1 # ['q', 'w', 'e', 'r', 't'] -> [-5,-4,-3,-2,-1,0,1,2,3,4,5] range(-len(i),-~len(i)) # change every value in range to its absolute value # [-5,-4,-3,-2,-1,0,1,2,3,4,5] -> [5,4,3,2,1,0,1,2,3,4,5] map(abs,range(-len(i),-~len(i))) # get string representaion of list # [5,4,3,2,1,0,1,2,3,4,5] -> '[5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5]' `map(abs,range(-len(i),-~len(i)))` # get each third element from string, starting from index 1, returns string # '[5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5]' -> '54321012345' `map(abs,range(-len(i),-~len(i)))`[1::3] # split string over '0', returns list of 2 values # '54321012345' -> ['54321','12345'] `map(abs,range(-len(i),-~len(i)))`[1::3].split('0') # reverse list # ['54321','12345'] -> ['12345','54321'] `map(abs,range(-len(i),-~len(i)))`[1::3].split('0')[::-1] ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes ``` J,JṚ$Ḍ ``` ## Explanation ``` J # Converts an array to [1, ...len(arr)] , # Paired with JṚ$ # The same array as before, reversed. Ḍ # Convert the digits to integers. ``` I'm no Jelly master, so likely sub-optimal. [Try it online!](https://tio.run/##y0rNyan8/99Lx@vhzlkqD3f0/P//P9pQR8FCR8FER8FYR8FIR8EyFgA "Jelly – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` ā‚J ``` [Try it online](https://tio.run/##yy9OTMpM/f//SOPhpkcNs7z@/49WSlTSUUoF4kwgzgfiUqVYAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/I42Hmx41zPL6r/M/OlopUUlHKRWIM4E4H4hLlWJ1FCDihrE60UpJSjpGIDpZScc4FiSla6hjZKRjbKxjYqJjaqpjZqZjbq5jYaFjaRkbCwA). **Explanation:** ``` ā # List in the range [1, length of (implicit) input-list] # i.e. ["a","e","i","o","u"] → [1,2,3,4,5]  # Bifurcated (short for Duplicate & Reverse copy) ‚ # Pair both list into a single list of lists # i.e. [1,2,3,4,5] and [5,4,3,2,1] → [[1,2,3,4,5],[5,4,3,2,1]] J # Join the individual items of the inner lists together (and output implicitly) # i.e. [[1,2,3,4,5],[5,4,3,2,1]] → ["12345","54321"] ``` [Answer] # [Husk](https://github.com/barbuz/Husk), 6 bytes ``` S¤,d↔ŀ ``` [Try it online!](https://tio.run/##yygtzv7/P/jQEp2UR21Tjjb8B4JoXUMdIyMdY2MdExMdU1MdMzMdc3MdCwsdS8tYAA "Husk – Try It Online") ## Explanation ``` S¤,d↔ŀ -- input xs (list) ŀ -- indices [1..length xs] S ↔ -- do the following with itself and itself reversed: ¤,d -- | undigits and join as tuple ``` [Answer] # [Java (JDK)](http://jdk.java.net/), 76 bytes ``` a->{String[]r={"",""};int i=1;for(var x:a){r[1]=i+r[1];r[0]+=i++;}return r;} ``` [Try it online!](https://tio.run/##ZU@xboMwEN3zFSdLSFAS1Ky4ROrSreqQbojBAROZgo3OR9QI@dupgZClw@l07929964RN3Foqp9Jdb1BgsbPyUCqTV747h9WD7okZfRMlq2wFj6F0jDuAPrh0qoSLAny7WZUBZ3nwjOh0te8AIFXGy2rAB8PnbevSyNLyov9tnaCOpvE4TRuAGYjY3vGHFeaQGVHXhsMbwLhNxXRiPmxyFQ8N475axH7IeYOJQ2oAbmb@OK4GfkgJC1ZyB5RAEYmvIH0pXwZXwNzC@fW29lwu1@u01Ujekqc75Zkl5iBkt7HpjpkgU0hsIFme3hHFHebVFL232b9K5wFoidFG1wnou/b@0pH0eo/h3E7N/0B "Java (JDK) – Try It Online") [Answer] # [MathGolf](https://github.com/maxbergmark/mathgolf), 6 bytes ``` £╒y_xα ``` [Try it online!](https://tio.run/##y00syUjPz0n7///Q4kdTJ1XGV5zb@P9/tFKiko5SKhBnAnE@EJcqxQIA "MathGolf – Try It Online") ``` £╒y_xα £ Length of input array ╒ Range from 1 to n y Join _x Duplicate and reverse α Wrap top two elements in array ``` [Answer] # JavaScript (ES6), 43 bytes Returns an array of 2 strings. ``` a=>a.map(_=>(a+=++i,b=i+b),i=a=b='')&&[a,b] ``` [Try it online!](https://tio.run/##bcpNCoMwEIbhfY@RRVUyivE/wngRkTKxWlKskdp2I549TbfFxcvAfM@dPrT2T728wtlcBzuiJWwoetDiX7DxiSPnGhRqrgLQSKjQ84LzuSVQne3NvJppiCZz80e/ZcSADS7tMq4364Lg9Kc2x2qxw8YUq5Pf7Vmd7gcyFJAkkKaQZZDnUBRQllBVIOUBjkEcfIWUEpI4jt1mvw "JavaScript (Node.js) – Try It Online") [Answer] # [Python 2](https://docs.python.org/2/), ~~64~~ 60 bytes ``` a=''.join(map(str,range(1,-~len(input())))) print[a,a[::-1]] ``` [Try it online!](https://tio.run/##HYxNCsIwFIT3PUXIJlFeJUl/E@hJQhexBo1oWmoLSqlXr68OfDMwAzN8plsf1db1F08awhjbXMPY6d6HyJ9u4K9phNHFq@cS0u/DRx7iME/8sCsZxhAn68BZY1LZthseJP7tO/I/PJJis9RRoB4JSI/MtE3sgrWRKyz0TI3as6MmW3FJJSgFWQZ5DkUBZQlVBXUNWuMoQKJLrTUoIUT7Aw "Python 2 – Try It Online") -1 with thanks to @KevinCruijssen -3 with thanks to @DeadPossum [Answer] # [Python 2](https://docs.python.org/2/), 52 bytes ``` x=0 for _ in input():x=x*10+x%10+1 print x,`x`[::-1] ``` [Try it online!](https://tio.run/##DcRLCoAgFAXQeatwEvS5QppZCa4kJEdRExMxeK3egsOJbz7vIEshO1THndjOrvCLT25aQ5Y6MfRU/4kqpitkRvDkN2O4cKVsXEBKjCOUwjRBa8wzlgXr6j4 "Python 2 – Try It Online") [Answer] # [Haskell](https://www.haskell.org/), 42 bytes *-4 bytes thanks to [ovs](/u/64121).* ``` ((,)=<<reverse).(`take`"123456789").length ``` [Try it online!](https://tio.run/##ZYzLCoMwFET3/YohdKFwlcR3QL@kFQw2PjA@UNvPb6rbOouzGM5Mp7ZBG2Ob4mkdh9wiz1f90eumXd@pdjXoiokgjOIkzSRzfaOndu/sqPoJBV7zDUeWtZ923NHgwRQjMH2iPzGfeLPy3/MEIQgIYUiIIkIcE5KEkKaELCNIeZlwgriUQkp5PHHOS/utG6PazXr1svwA "Haskell – Try It Online") [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/Code-page) ``` JṚƬḌ ``` **[Try it online!](https://tio.run/##y0rNyan8/9/r4c5Zx9Y83NHz////6GqlRCUrw1qdaqUkJSsjEJ2sZGVcGwsA "Jelly – Try It Online")** ### How? ``` JṚƬḌ - Link: list L e.g. ['ant','bee','cat','dog','elk','frog'] J - range of length [1,2,3,4,5,6] Ƭ - 'till (collect up until results are no longer unique): Ṛ - reverse 1:[6,5,4,3,2,1] , 2:[1,2,3,4,5,6]=1st - -> [[1,2,3,4,5,6],[6,5,4,3,2,1]] Ḍ - from base ten [123456,654321] ``` [Answer] # Japt, ~~9~~ 8 bytes ``` Êõ ¬pÔò¶ ``` [Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=yvUgrHDU8rY=&input=WzAsMSwyLDNd) --- ## Explanation ``` Ê :Length õ :Range [1,Ê] ¬ :Join p :Concatenate Ô : Reverse ò :Partition ¶ : Between equal characters ``` [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 10 bytes ``` ⟦⭆θ⊕κ⮌⭆θ⊕κ ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRCM6uARIp/smFmgU6ih45iUXpeam5pWkpmhka2rqKASllqUWFadq4FOlGatp/f9/dLRSopKOUioQZwJxPhCXKsXG/tctywEA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: ``` θ θ Input array ⭆ ⭆ Map over elements and join κ κ Current index (0-indexed) ⊕ ⊕ Increment ⮌ Reverse ⟦ Collect into an array ``` [Answer] # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 39 bytes ``` -join(1..($x=$args.count));-join($x..1) ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XzcrPzNPw1BPT0OlwlYlsSi9WC85vzSvRFPTGiKlUqGnZ6j5//9/k//G/40A "PowerShell – Try It Online") Takes input via splatting, which on the command-line prompt looks like, e.g., `$a=(4,3,2); .\array-to-indices.ps1 @a`, and on TIO manifests as separate arguments for each entry. We take the `.count` of the input `$args`, store that into `$x`. Then construct a range `..` from `1` up to `$x` and `-join` it into a string. Finally we `-join` the range the other direction. Those two strings are left on the pipeline and output is implicit. [Answer] # [Clean](https://github.com/Ourous/curated-clean-linux), 53 bytes ``` import StdEnv $l#n=take(size l)['1'..] =[n,reverse n] ``` [Try it online!](https://tio.run/##JcuxCsIwEADQvV9x0EIV0mLcOmSrg@AgdCwdjvQqweQiSSyo@OtGwfENT1tCzs7Pd0vg0HA27uZDgiHNB16LypasEl5pE82TwG7HWtZtOxVqZBFopRAJeMpDwl9SUMGrlAK6TkAj9wJ27/zRi8VLzM3xlPsHozP6j7PFtPjgvg "Clean – Try It Online") [Answer] # Scala (60 bytes) ``` def%(s:Seq[Any])={val a=(1 to s.size)mkString;(a,a.reverse)} ``` [Try it online](https://tio.run/##VYxPC4JAEEfvfYplQdiFUVCzsjDoA3TqGB1GncKy1dxN@kOf3cZTdHj8YHjzbIE1Dk1@psKJLVZG0MORKa3YtK14DyUdPWWXO7rtN@Z50Nm7x1pgpkLhGmEDW71IXy8711XmtFIIGHTUU2dJf4aWj642ylP8ryRKkMRUTMPcpdZ68pO22I6Svw5ByJw34i14Yx24hhN/9pj0Q4giiGOYTiFJYDaD@RwWC0jTsfwZvg) [Answer] # [J](http://jsoftware.com/), 15 bytes ``` 4(,:|.)@u:48+#\ ``` [Try it online!](https://tio.run/##y/qvpKegnqZga6WuoKNQa6VgoADE/000dKxq9DQdSq1MLLSVY/5rcqUmZ@QrpCkYGioYGSkYGyuYmCiYmsJEjYyBPBNjBUM4A0qDKDMzUxOgiv8A "J – Try It Online") ### How it works ``` 4(,:|.)@u:48+#\ #\ Generate 1-based indices of given array 48+ Convert digits to ASCII value 4 @u: Convert to string (,:|.) Append its reverse ``` [Answer] ## JavaScript, 58 bytes ``` _=>[_.map((_,i)=>t.unshift(++i),t=[]),t].map(_=>+_.join``) ``` [Try it online!](https://tio.run/##bcpLDoMgEIDhfY/BCuJowDcmeBFj0FptMRZM1W6MZ6e0y8bFP5PMfGP7bpfupebV1@bW20FYKcpKBs92xliCIqJcg00vDzWs2PMUgVVUtZv1jzjsyWA0SjcNsZ3Ri5n6YDJ3POAKtQhQ71Iu49pQTcjlT@2OFeyAHV1REX53h4roOJE@gzCEKII4hiSBNIUsgzwHzk8wBXZyZZxzCCml7mc/) Pass current index of array plus `1` to `.unshift()` to fill first array with a second array's `.length`, `.join()` each resulting array without any characters separating elements and convert to integer. Returns an array of two integers. ]
[Question] [ **This question already has answers here**: [Operations with Lists](/questions/6257/operations-with-lists) (17 answers) Closed 7 years ago. ## Mama Say Mama Sa Mama Coosa I'm sure all of you have heard of Michael Jackson and some of you have listened to MJ's song "Wanna be starting something". The line "Mama Say Mama Sa Mama Coosa" is repeated throughout the song. ## Specification In this line, the word "Mama"occurs three times, "Say", "Sa", "Coosa" occurs once. The task is the following: Given the input number of occurrences of the words "Mama", "Say", "Sa", "Coosa", output the number of times MJ can sing "Mama Say Mama Sa Mama Coosa", like in a complete sentence. ## Input Input is a single line with four positive integers denoting the number of times he says the words "Mama", "Say", "Sa","Coosa" respectively . ## Output Output the number of times MJ can sing "Mama Say Mama Sa Mama Coosa" Shortest code wins. ## Testcases ``` Testcase 1 Input --> 3 1 1 1 Output--> 1 Testcase 2 Input --> 6 1 1 1 Output--> 1 Testcase 3 Input --> 1000 3 2 3 Output--> 2 Testcase 4 Input --> 7 3 4 3 Output--> 2 ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes ``` Ḣ:3«Ṃ ``` [Try it online!](https://tio.run/nexus/jelly#@/9wxyIr40OrH@5s@n@4/VHTGvf//6ONdRQMIShWRyHaDIVnaGBgoKMAVGEEJEEC5mCeCYgHAA "Jelly – TIO Nexus") ### How it works ``` Ḣ:3«Ṃ Main link. Argument: [a, b, c, d] Ḣ Head; pop and yield a. :3 Perform integer division by 3, Ṃ Yield the minimum of [b, c, d]. « Take the minimum of a and the result to the right. ``` [Answer] # [Python 2](https://docs.python.org/2/), 23 bytes ``` lambda a,*x:min(a/3,*x) ``` [Try it online!](https://tio.run/nexus/python2#S1OwVYj5n5OYm5SSqJCoo1VhlZuZp5Gobwxkav5Pyy9S0EjUUUjSUUjWUUjRVMjMU9Aw1lEwhCBNHQUNMxSeoYGBgY4CUIURkAQJmIN5JiCeFRdnQVFmXolCGrKR/wE "Python 2 – TIO Nexus") [Answer] # [Perl 6](http://perl6.org/), 19 bytes ``` {min $^a div 3,|@_} ``` [Try it online!](https://tio.run/nexus/perl6#y61UUEtTsP1fnZuZp6ASl6iQklmmYKxT4xBf@784sVIhTcHQwMBAByikYAQkrf8DAA "Perl 6 – TIO Nexus") ### How it works ``` { } # A lambda. $^a # First argument. div 3 # Integer division by 3. @_ # All regaining arguments as a list. , | # Slipped into the outer list. min # Smallest number in the list. ``` The `$^a` and `@_` are in-place parameter declarations for the surrounding block lambda. One is a positional parameter, and the other to a slurpy parameter that takes all remaining positional arguments. [Answer] # MATL, ~~9~~ 8 bytes *1 byte saved thanks to @Luis* ``` I7Bh/kX< ``` [**Try it at MATL Online**](https://matl.io/?code=I7Bh%2FkX%3C&inputs=%5B7+5+5+5%5D&version=19.7.4) **Explanation** ``` % Implicitly grab input as an array I % Push the literal 3 to the stack 7B % Push 7 and convert to binary ([1, 1, 1]) and push it to the stack h % Horizontally concatenate the two to create the array [3 1 1 1] / % Perform element-wise division k % Round all values towards minus infinity X< % Compute the minimum of the resulting array % Implicitly display the result ``` [Answer] # MATLAB / Octave, 26 bytes ``` @(a)min(fix(a./[3 1 1 1])) ``` Creates an anonymous function named `ans` which you can then pass the input array as: `ans([3 1 1 1])` [Online Demo](http://ideone.com/3cKLmd) [Answer] # [Cubix](https://github.com/ETHproductions/cubix), 24 bytes ``` O;@sI3,>I?;^>..^.-!..;;? ``` [Try it here](https://ethproductions.github.io/cubix/?code=ICAgIE8gOwogICAgQCBzCkkgMyAsID4gSSA/IDsgXgo+IC4gLiBeIC4gLSAhIC4KICAgIC4gOwogICAgOyA/Cg==&input=NyA4IDkgMTA=&speed=20) ``` O ; @ s I 3 , > I ? ; ^ > . . ^ . - ! . . ; ; ? ``` `I` Read number from the input `3,` Push 3 onto the stack and integer divide `>` Redirect to the right `I?` Read number from input and test if 0 (end of input), `;` remove from stack. `^` redirect to top face, `O@` Output TOS and quit if positive, `-` subtract from TOS `?` Test. For 0 and positive `;` remove TOS, for negative `;s` remove TOS and swap top items on the stack. This keeps the lowest number at the top. Follow arrows back to the 2nd `I` and repeat until done. [Answer] # Mathematica, 18 bytes ``` ⌊#/3⌋~Min~##2& ``` Pure function taking four integer arguments and returning an integer. Computes the floor of the first argument divided by 3, then finds the minimum of that number and the remaining arguments `##2`. [Answer] ## Batch, 71 bytes ``` @set/am=%1/3 @for %%n in (%*)do @set/a"n=%%n-m,m-=(n>>31)*n @echo %m% ``` Unrolling the loop would have been 7 bytes longer. [Answer] # JavaScript (ES6), 30 bytes ``` a=>Math.min(a[0]/3,...a)|0 ``` ## Usage ``` f=a=>Math.min(a[0]/3,...a)|0 f([2,1,1,1]) ``` ### Output ``` 0 ``` ## Explanation This function takes an array as argument, and then feeds all its elements to `Math.min` as well as the first element devided by three. Since `a[0]/3` is smaller than `a[0]` (because `a[0]` is guaranteed to be positive), we don't have to remove it from the main array. `Math.min` returns the minimum value, which is then floored and returned. [Answer] # C#, 62 bytes ## Golfed ``` int i(int a,int b,int c,int d){return new[]{a/3,b,c,d}.Min();} ``` Pretty self-explanatory I think. [Answer] # [PowerShell](https://github.com/PowerShell/PowerShell), 44 bytes ``` $a,$b=$args;[int]($a/3),$b|measure -mi|% Mi* ``` [Try it online!](https://tio.run/nexus/powershell#@6@SqKOSZKuSWJRebB2dmVcSq6GSqG@sCRSsyU1NLC4tSlXQzc2sUVXwzdT6//@/@X/j/yb/jQE "PowerShell – TIO Nexus") [Answer] # R, 26 bytes As an unnamed function that takes a vector of numbers as the parameter. ``` function(x)min(x,x[1]%/%3) ``` Return the min of the parameter and the first item integer divided by 3. So for an input of `7,8,9,10`, it will return the min of `7,8,9,10,2`. This was shorter than dividing the complete vector by c(3,1,1,1) ]
[Question] [ **This question already has answers here**: [We're no strangers to code golf, you know the rules, and so do I](/questions/6043/were-no-strangers-to-code-golf-you-know-the-rules-and-so-do-i) (73 answers) Closed 8 years ago. Print or return these lyrics: ``` Dea Mortis, iuravi Carissimam servaturum. Dea Mortis, servabo Ut tempora recte ducam. Etsi cor in Chaos, Aut Fortuna bella ferat, Occurram et obviam ibo. ``` The line break must be preserved, and trailing newlines are allowed. **+20%** if you omit the end-of-line punctuation, **+30%** if you omit all punctuation, **+20%** if you change any capitalization, **-40%** if you also print the English translation right after the normal lyrics, separated by a blank line: ``` Goddess of Death, I vowed That I would protect the most dear one. Goddess of Death, I will protect her, As I lead time straight. Even if there is a heart in Chaos, Or if Fortune may bring wars, I will resist and go to fight against it. ``` If you print just the English version, add **+30%**. [And the actual song on YouTube.](https://www.youtube.com/watch?v=Gi05oQJFzuc) Code-golf, so fewest bytes win. [Answer] # [TeaScript](https://github.com/vihanb/TeaScript), 123 + 1 = 124 bytes ~~142~~ +1 byte for "Safely handle unicode" checkbox ``` Ld`Dea MƳs, i¨avi Càmm  rvÂxum. Dea MƳs,  rva¾ Ut ÛZa c Ýóm. Et£ ¬r Cos, A© FÆ·na Þ)a fÀ, Occ¨m et obviam i¾.` ``` Try this in the [interpreter](http://vihanserver.tk/p/TeaScript/). Make sure to check **"Safely handle unicode"** under options. [Pastebin](http://pastebin.com/s8t2uqnw) because StackExchange messed up the special characters. The compression algorithm used encodes similar items in the text rather than a simple base encoding. The general code is pretty simple though: [Answer] # [Bubblegum](https://esolangs.org/wiki/Bubblegum), 116 bytes ``` 00000000: 4d 4d b5 19 82 41 0c ed 33 c5 eb 91 19 f0 0a a9 MM...A..3....... 00000010: 18 20 77 fc 2e e1 8b dc fa 58 45 95 3c 3f 54 8c . w......XE.<?T. 00000020: 8b a8 77 b6 44 17 ca a5 a3 3d 6b 67 d6 4d 3c c1 ..w.D....=kg.M<. 00000030: 2a 2d ec a1 31 ad e9 df f9 e3 93 d0 dd e1 d5 f4 *-..1........... 00000040: 14 65 68 95 bd c2 23 32 7f bc 74 74 eb 90 45 d1 .eh...#2..tt..E. 00000050: cd d8 b7 2c b6 a4 6d 38 4e 9f 7c cc 8c 54 8d 23 ...,..m8N.|..T.# 00000060: a3 ae 94 7d 49 b7 9c 43 f5 b3 56 39 24 95 ee f3 ...}I..C..V9$... 00000070: 75 49 d6 6f uI.o ``` The above is a hexdump, which can be reversed with `xxd -r`. I used [zopfli](https://github.com/google/zopfli) for compression, which uses the DEFLATE format, but achieves a better compression ratio than gzip and zlib. [Answer] # Stuck, 128 bytes So riddled with unprintables I'm not going to even post the raw source code. Here's the hexdump instead: ``` 0000000: 2278 da4d 8d41 0ec2 300c 04ef 79c5 3e20 "x.M.A..0...y.> 0000010: ea1f 500b 37c4 8907 38a9 1196 9a1a 3976 ..P.7...8.....9v 0000020: de4f c489 db68 35ab d998 7057 73e9 1912 .O...h5...pWs... 0000030: 4643 d24a 26bd 4ba3 86ce 36c8 c3a2 2d69 FC.J&.K...6...-i 0000040: fb33 7f7b d1f4 7438 b78f 1ac1 b83a 638f .3.{..t8.....:c. 0000050: 4ad3 4d57 ef82 aa06 39b1 be49 7b4e 9770 J.MW....9..I{N.p 0000060: dce6 3f4e 42e1 e320 bcd8 c873 7ad4 1a66 ..?NB.. ...sz..f 0000070: b3c6 0e2d 4326 49d1 e50b 7fc1 35fe 2244 ...-C&I.....5."D ``` [Answer] # JavaScript (ES6), 252 bytes ``` btoa` æ2íÅÖêÚ¾&j¸¬²)k®ö­º»¦eÞic(®Ø¬]k®ö¡-Zצ¦ÚZ·µå¹Æ¦e¶ÈrÖuª,].µah®Û§ifÞV}êÚµvqË«­©zÕ¨nøh¡`.replace(/[W-Z=]/g,c=>` , .`["WXYZ".search(c)]||"") ``` Note the first newline is a carriage return. ## Hexdump: ``` 00000000: 6274 6f61 600d c3a6 c296 32c2 8ac3 adc2 btoa`.....2..... 00000010: 8ac3 85c3 96c2 8ac3 aac3 9ac2 be26 026a .............&.j 00000020: c2b8 c2ac c2b2 29c2 9ac2 996b 1ec2 aec3 ......)....k.... 00000030: b6c2 adc2 bac2 bbc2 a665 c280 c39e 6963 .........e....ic 00000040: 28c2 aec3 98c2 ac5d 6b1e c2ae c3b6 c29b (......]k....... 00000050: c2a1 c285 2d5a c397 c2a6 c2a6 c28a c39a ....-Z.......... 00000060: 5ac2 b7c2 9cc2 b5c3 a5c2 9dc2 b9c3 86c2 Z............... 00000070: a665 c286 04c2 b6c3 88c2 9672 c28a c396 .e.........r.... 00000080: c28a 75c2 82c2 85c2 aa2c 5dc2 802e c2b5 ..u......,]..... 00000090: 6168 c2ae c39b c2a7 6966 c39e c296 56c2 ah......if....V. 000000a0: 967d c3aa c39a c2b5 760e 71c3 8bc2 abc2 .}......v.q..... 000000b0: adc2 a9c2 967a c395 c2a8 6ec3 b8c2 9ac2 .....z....n..... 000000c0: 9968 c29b c2a1 c296 602e 7265 706c 6163 .h......`.replac 000000d0: 6528 2f5b 572d 5a3d 5d2f 672c 633d 3e60 e(/[W-Z=]/g,c=>` 000000e0: 202c 0a2e 605b 2257 5859 5a22 2e73 6561 ,..`["WXYZ".sea 000000f0: 7263 6828 6329 5d7c 7c22 2229 rch(c)]||"") ``` Edit: I found out that pasting into Firefox console changes carriage returns into line feeds. (Face-palm) Here is a whitespace safe version for two more bytes: ``` btoa`\ræ2íÅÖêÚ¾&j¸¬²)k®ö­º»¦eÞic(®Ø¬]k®ö¡-Zצ¦ÚZ·µå¹Æ¦e¶ÈrÖuª,].µah®Û§ifÞV}êÚµvqË«­©zÕ¨nøh¡`.replace(/[W-Z=]/g,c=>` ,\n.`["WXYZ".search(c)]||"") ``` [Answer] # [Chaîne](http://conorobrien-foxx.github.io/Cha-ne/?code%3DDea%20Mortis%2C%20%7B%3C~%7Diuravi%0ACarissimam%20servaturum.%0A%7B%7Dservabo%0AUt%20tempora%20recte%20ducam.%0A%0AEtsi%20cor%20in%20Chaos%2C%0AAut%20Fortuna%20bella%20ferat%2C%0AOccurram%20et%20obviam%20ibo.||input%3D), ~~154~~ 148 bytes (Linked interpreter currently only works properly on Firefox) ``` Dea Mortis, {<~}iuravi Carissimam servaturum. {}servabo Ut tempora recte ducam. Etsi cor in Chaos, Aut Fortuna bella ferat, Occurram et obviam ibo. ``` Doing the bonus doesn't grant me anything extra (229.2 bytes): ``` Dea Mortis, iuravi Carissimam servaturum. Dea Mortis, servabo Ut tempora recte ducam. Etsi cor in Chaos, Aut Fortuna bella ferat, Occurram et obviam ibo. Goddess of Death, I :/E@: That I :/eY: :*uk: the most dear one. Goddess of Death, I will :*uk: her, As I lead time :-Ep:. Even if :.&L: is a heart in Chaos, Or if :%u?: may bring wars, I will :+XU: and to go to fight :5$: it. ``` ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- This question does not appear to be about code golf or coding challenges within the scope defined in the [help center](https://codegolf.stackexchange.com/help/on-topic). Closed 9 years ago. [Improve this question](/posts/32139/edit) I really hate looking up to the top right of the screen to look at the time on OS X's clock widget; I'd much rather keep my eyes at least *somewhere* near my workspace to check the time. I also hate other people using *my* clock to check the time as they walk by -- after all, it's called a personal computer, right? But we've got a great community here that can surely help me out, right? So here's my really really so much very hard challenge for you guys that would help me so much: write me a clock app. It can be analog or digital or whatever other amazing forms you can think of. Minimum requirements: * It should be very visible * It should display the time in a format that not many people would comprehend (the less people, the better) This is a popularity contest, so fulfill these requirements creatively, and go above and beyond! Ready... Set... Go! [Answer] # Bash ``` #!/bin/bash T="The time is now:" case $1 in --12) F=82;M=0;S=%r;; --24) F=120;M=100;S=%R;; --ipv6) F=112;M=0;S=%H::%M:%S;T="Started download from:";; --posix) F=82;M=0;S=%s;; esac watch 'notify-send "'"$T"'" "<div style=\"font-size:'"$F"'px;margin-left:'"$M"'px;\"> $(date +'"$S"')</div>"' ``` Displays the current time as a desktop notification, updating every two seconds. ### Usage ``` whattimeisit FORMAT --12 May be understood by Australians, Chinese and North Americans. --24 May be understood by everyone else. --ipv6 May be understood by illiterates. --posix May be understood by nerds. ``` ### Example output [![](https://i.stack.imgur.com/6RBdE.png)](https://i.stack.imgur.com/6RBdE.png) [Answer] # Javascript This encodes the hours, minutes, and seconds, as hex, and sets the background color of the page to the concatenation of the string. For example, for the time 9:18:13 PM, the background color would be set to `#15120D`. It is right on a webpage for you, all you have to do is drag a little bit of the window to a different place on the screen or flip tabs. [Here](http://jsfiddle.net/UbFbf/) is a JSFiddle demo. To tell the time, you can use your handy color-picking and base changing skills. ``` function hex(number) { return number.toString(16).length == 1 ? "0" + number.toString(16): number.toString(16); } var display = function() { var now = new Date(); var base = "00" var hours = hex(now.getHours()); var minutes = hex(now.getMinutes()); var seconds = hex(now.getSeconds()); document.body.style.background = "#" + hours + minutes + seconds; console.log("#" + hours + minutes + seconds) } setInterval(display, 1000); ``` [Answer] ## HTML + CSS + JavaScript I made a binary clock, pretty self-explanatory. I have a binary watch and even those who know what binary numbers are may have a hard time telling what time it is sometimes. Like scrblnrd3 said in his answer, all you have to do is position your browser window properly to make it visible. Here's a [fiddle](http://jsfiddle.net/3w5Ly/) of clock in action. P.S.: The hour part has 5 positions in order to support 24 hour format. **JavaScript** ``` function pad(number, digits) { return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number; } var updateClock = function() { var date = new Date(); var childDivs = [ document.getElementsByClassName('hours')[0].children, document.getElementsByClassName('minutes')[0].children, document.getElementsByClassName('seconds')[0].children ]; var binaryTime = [ pad(date.getHours().toString(2), 5), pad(date.getMinutes().toString(2), 6), pad(date.getSeconds().toString(2), 6) ]; for(i=0; i < childDivs.length; i++) { for(j=0; j < childDivs[i].length; j++) { childDivs[i][j].className = binaryTime[i][j] == '1' ? 'highlight' : ''; } } } setInterval(updateClock, 1000); ``` **CSS** ``` .wrapper div { width: 30px; height: 30px; border-radius: 50px; border: 1px solid black; display: inline-block; margin: auto; } .highlight { background-color: green; } ``` **HTML** ``` <div class="wrapper hours"> <div></div> <div></div> <div></div> <div></div> <div></div> </div> <div class="wrapper minutes"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> <div class="wrapper seconds"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> ``` [Answer] ## C I have been finding it annoying, that though computers can easily keep time with an accuracy of a few ms by using NTP, some software displaying time haven't bothered with updating it at the right time. For example if you display time with hours and minutes by simply displaying the time and then sleep for 60 seconds in a loop, the displayed clock will on average be 30 seconds behind. Here is my suggestion on how to implement a highly accurate clock (which displays time as seconds since midnight GMT in octal). ``` #include <stdio.h> #include <time.h> #include <sys/time.h> int main() { struct timeval tv; struct timespec ts; while (1) { do { gettimeofday(&tv,NULL); } while ((ts.tv_nsec=((999999-tv.tv_usec)*1000)-1)<1); printf("\x0d%lo ", tv.tv_sec%86400); fflush(stdout); ts.tv_sec=0; nanosleep(&ts,NULL); } } ``` > > Replace the `printf` with `s=ctime(&tv.tv_sec);` `c=strchr(s,'\n');` `if (c) *c=0;` `printf("\x0d%s ",s);` if you want human readable output. > > > [Answer] ## Javascript This is an ASCII clock with A=0. ``` <body onload="tick()"> <p id="p">0</p> <script> function tick() { console.log("tick"); var a = "A"; var i = a.charCodeAt(0); var dt = new Date(); var h = String.fromCharCode(i+dt.getHours()); var m = String.fromCharCode(i+dt.getMinutes()); var s = String.fromCharCode(i+dt.getSeconds()); var t = h+":"+m+":"+s; document.getElementById("p").innerHTML = t; setTimeout('tick()',1000); } </script> </body> ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/3359/edit). Closed 7 years ago. [Improve this question](/posts/3359/edit) Generic Lorem Ipsum: > > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris felis > dolor, bibendum at tincidunt vel, imperdiet eget libero. Cras vel > felis purus. Phasellus a vestibulum enim. Sed eu orci ac nisl sodales > scelerisque in id mi. Duis et nunc et nisl blandit aliquet ornare sed > risus. Sed arcu magna, porttitor vel tincidunt quis, placerat non > urna. Donec ut dolor eros, et viverra diam. Aliquam luctus, justo sed > cursus imperdiet, velit nulla gravida nibh, vel scelerisque neque sem > eget enim. Nunc in urna a velit adipiscing fermentum. Donec euismod > faucibus purus. Vestibulum pretium, ligula commodo facilisis > sollicitudin, nibh dolor adipiscing augue, nec tempus leo lectus eu > enim. Vestibulum non erat velit, eget vulputate metus. Praesent at > tincidunt elit. > Add some stuff to it? !@#$%^&\*()-\_=+\|]}[{'";:/?.>,<`~ > > > Nunc pretium metus sed elit dignissim porta. Cras at dui quam. Mauris > at elementum tellus. Sed placerat volutpat enim convallis egestas. > Suspendisse consectetur egestas mattis. Proin interdum, lectus a > tincidunt sollicitudin, mauris ligula accumsan nisi, et suscipit > lectus enim id mi. In est ipsum, cursus nec eleifend id, sollicitudin > ac sem. Nam augue felis, dapibus in faucibus sit amet, ultrices eget > purus. Etiam suscipit mauris at velit fringilla molestie. Cum sociis > natoque penatibus et magnis dis parturient montes, nascetur ridiculus > mus. Vivamus faucibus tortor in libero convallis pharetra. Donec eros > diam, tincidunt vitae euismod ut, bibendum non orci. Nullam quam > tortor, accumsan id malesuada nec, dignissim vitae magna. Suspendisse > mi odio, commodo ut tempor porttitor, congue sit amet risus. Praesent > feugiat lacus quis orci sodales cursus. Vivamus ac lorem id sem > iaculis interdum. > > > [Answer] ## PHP (16) (35) (28) The default mode of count\_chars() returns "an array with the byte-value as key and the frequency of every byte as value." Edit: Oops, I just realized it's supposed to read in from a file. That adds 19 characters, so it might be beatable now. Edit 2: Reduced it by 7 characters. ``` count_chars(join(file($s))); ``` [Answer] ## C: 50 chars (74 chars if done right) "Return an array" is a pretty rare case when using C, because we can't actually return an array unless it's global or allocated by `malloc()`. So I decided to use a global one. The input is read from STDIN. The function works only on little-endian architectures. ``` n[256],r;*c(){while(read(0,&r,1))n[r]++;return n;} ``` The whole program that uses this function (with indentation added): ``` n[256],r; *c() { while (read(0,&r,1)) n[r]++; return n; } main() { int *num = c(); int i; for (i = 0; i < 256; ++i) printf("%d ", num[i]); } ``` Yeah, I know I won't ever beat anybody with C. **EDIT:** There are some rightful remarks in comments, so I've rewritten the code so that it meets all the requirements. Now it's 74 chars long. ``` n[256],r,*f,*s;*z(){f=fopen(s,"r");while(fread(&r,1,1,f))n[r]++;return n;} ``` And the indented code with `main()` added: ``` n[256],r,*f,*s; *z() { f=fopen(s,"r"); while(fread(&r,1,1,f)) n[r]++; return n; } main(int c,char**a) { int *stat, i; s = a[1]; stat = z(); for (i = 0; i < 256; ++i) printf("%d ", stat[i]); printf("\n"); } ``` [Answer] This one is relatively simple. I chose to do it in Perl (my favorite scripting language). :) ## Perl: 41 characters 63 characters Might be able to reduce it somewhat but this is what I'm starting with. ``` sub s{open(I,"<$_[0]");while(!eof(I)){read(I,$c,1);$s{$c}++}%s} ``` **EDIT:** Got it down further: ``` sub s{foreach(split//,$_[0]){$s{$_}++}%s} ``` [Answer] ## D (87 chars) reads from a passed in file and uses binary reads like migimaru's php function ``` import std.stdio;int[] f(File i){int[256] r;foreach(c;i.byChunk(1))r[c[0]]++;return r;} ``` [Answer] # Ruby, 41 ``` F=->f{h=Hash.new 0 f.chars{|c|h[c]+=1} h} ``` [Answer] Accepting the assumption that the problem doesn't specify how the characters are read (according to Peter Taylor's comment on [Alexander Bakulin's C suggestion](https://codegolf.stackexchange.com/questions/3359/text-statistics-return-a-list-array-of-the-number-of-occurrences-of-each-charact/3363#3363)) and assuming they are already read into a global array s, we can further reduce the C code in a portable way, by defining a function that accepts as an argument an already initialized char frequency table u[256], updates it and returns a pointer to it, like this: # **C - 39 chars (or 24 chars... see Edit below)** ``` *r(int*u){while(*s)u[*s++]++;return u;} ``` And here is a sample, ungolfed program using the above function: ``` #include <stdio.h> #include <stdlib.h> // function selector #define R_MORE_CHARS 0 // globals int*s, u[256]; // ------------------------------------------------------------------------------------ #if R_MORE_CHARS *r(int*u){while(*s)u[*s++]++;return u;} #else r(){while(*s)u[*s++]++;} #endif // ------------------------------------------------------------------------------------ int *read_file(char *fname, int maxfsize) { int i, *s_ = calloc(maxfsize, sizeof(int)); if ( !s_ ) return NULL; FILE *fp = fopen(fname, "r"); if ( !fp ) return NULL; for (i=0; i < maxfsize && (s_[i]= getc(fp)) != EOF; i++) ; s_[i] = 0; fclose(fp); return s_; } // ------------------------------------------------------------------------------------ void print_freq( int freq[256] ) { int i=0; for (; i<256; i++) if ( freq[i] ) printf("ACII(%3d): %3d time(s)\n", i, freq[i]); return; } // ------------------------------------------------------------------------------------ int main( void ) { int *p; // for saving address of s p = s = read_file("lorem.txt", 2000); // get file contents into global s if ( !s ) return 1; #if R_MORE_CHARS print_freq( r(u) ); // print updated frequency table puts("\tmore chars: *r(int*u){while(*s)u[*s++]++;return u;}"); #else r(); // update frequency table print_freq( u ); puts("\tless chars: r(){while(*s)u[*s++]++;}"); #endif free( p ); // free saved s return 0; } ``` **EDIT**: Just thought that if we are to adjust the not so well defined problem to the language features, we could also completely skip the function arguments, working directly on the globals instead. Since in C we don't even need to return anything for the frequency table to get updated, the function can be further reduced down to 24 chars (i have also edited the sample program above, so now it can be used with either of those 2 functions... # **C - 24 chars** ``` r(){while(*s)u[*s++]++;} ``` [Answer] ## Haskell, 2^6 characters ``` import List f=fmap(map(\x->(x!!0,length x)).group.sort).readFile ``` [Answer] ### scala 164 156 ``` val m=collection.mutable.Map[Char,Int]() io.Source.fromFile("f").toArray.foreach(c=>m.update(c,m.getOrElseUpdate(c,0)+1)) m.mkString("\n") ``` Result: ``` > -> 1 + -> 1 _ -> 1 { -> 1 p -> 29 P -> 4 q -> 10 V -> 4 ; -> 1 v -> 20 ``` truncated to 10 lines. [Answer] ## J - 26 characters (or perhaps 20) The 26-character count is for the line that defines the function `f`. ``` NB. f takes a boxed filename, NB. returns an array of integers counting occurrences of each character NB. 26 characters f=.[:<:[:+/"1[:=[:a.&,1!:1 NB. apply f to the file argument in jconsole textstats.ijs filename A =. f 2{ARGV NB. set output parameters so none of A gets elided 9!:37]0,~0,2#+:#0":A NB. output A exit echo A ``` Along the lines of Harry K.'s commentary, if we interpret the question to be about the function that computes the statistics, not also about I/O, `f` can go down to 20 characters: ``` f=.[:<:[:+/"1[:=a.&, A =. f 1!:1]2{ARGV ``` `f` (in its shorter form) works like this: `a.&,` : bond (via `&`) the alphabet `a.` (all characters J knows, in collating order) as the left argument to `,` (append); `f`'s argument is the right argument to append `=` : "self classify": this gives us a table where each row corresponds to a unique element of the argument (which is the result of "`a. ,` *arg* ") and each column is 1 if that row's element appears in the same column of the argument, otherwise 0. For example, row 65 would have a 1 wherever an A appears at the same offset in the input. `[:` in the context here lets us use `=` in its monadic (unary) sense, instead of of its dyadic/binary "equals" usage. `+/"1` : `+/` applies addition between each pair of items, and `"1` makes it do so for the items in each row, instead of using the rows themselves as the items. The result is each row becomes a count from the input of the character corresponding to the row. `<:` : decrement all those counts, because they include the alphabet itself (`a.`). [Answer] **Python 102 54 48 (87 79 78 with I/O)** As a pretty much newbie at this, and ignoring I/O: Edit: Finding out about Counter made a difference: ``` from collections import* r = Counter(s) print(r) ``` The output is definitely not pretty though: ``` Counter({' ': 258, 'i': 155, 'e': 142, 's': 123, ``` Reading from file (removing a space between open() and "as" shaved one character): ``` from collections import* with open("f")as f: s=f.read() r=Counter(s) print(r) ``` which generates the same output as the above example. I don't think I can get it smaller now, but there could be some function I've yet to explore. Older solution: ``` import collections d = collections.defaultdict(int) for c in thestring: d[c] += 1 ``` The counting itself can probably be made shorter through some function I've not encountered/understood yet. I realize it's pretty much cheating by omitting the I/O part, but I'm going to hide behind my newbie tag for a while longer. [Answer] ## JavaScript, 55 Since JS can't read files, I'll assume that `file` is a function that returns the file as a string. (Requires Firefox!) ``` Array.reduce(file(),function(A,b)(A[b]=A[b]+1||1,A),{}) ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/124570/edit). Closed 6 years ago. [Improve this question](/posts/124570/edit) Your code may not contain the letter "e", but must count the number of "e"s in the inputted string and output that as a number. Bonus points if you use a language that is not a codegolf language and a language that actually uses the letter e (unlike brainfuck) --- not a required criteria. [Answer] # [Japt](https://github.com/ETHproductions/japt), ~~7~~ ~~6~~ 4 bytes Nope, definitely didn't use `e`! ``` è'Ev ``` [Try it online](http://ethproductions.github.io/japt/?v=1.4.5&code=6CdFdg==&input=ImVlZWVlZWVlIg==) --- ## Explanation ``` :Implicit input of string U è :Count. 'E :"E". v :Convert to lowercase. :Implicit output of result. ``` [Answer] # [MATL](https://github.com/lmendo/MATL), 5 bytes ``` 101=s ``` [Try it online!](https://tio.run/##y00syfn/39DA0Lb4/391j9ScnHyF8vyinBR1AA "MATL – Try It Online") [Answer] # Mathematica, 42 bytes ``` #~StringCount~StringDrop[ToString[2<1],4]& ``` input > > ["dfhjkeehjke"] > > > output > > 3 > > > [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 5 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` Oċ“d’ ``` A monadic link returning the count. **[Try it online!](https://tio.run/##y0rNyan8/9//SPejhjkpjxpm/v//Xyk8NSc5PzdVoSRfIaAoP70oMTc3My9dIaC0qiontVhBTcE5PyVVwT0/J01RCQA "Jelly – Try It Online")** ### How? ``` Oċ“d’ - Link: list of characters O - cast to ordinals “d’ - base 250 number 101 ċ - count occurrences ``` Alternatives: `O’ċȷ2` - decrement (`’`) and count occurrences of 100 (`ȷ2`); `ƓO’ċ³` - evaluate a line from STDIN (`Ɠ`), decrement (`’`) and count occurrences of 100 (`³`) [Answer] # [CJam](https://sourceforge.net/p/cjam), 8 bytes ``` q'd)f=:+ ``` Case sensitive. [Try it online!](https://tio.run/##S85KzP3/v1A9RTPN1kr7/3@P1JycfB2FnNSSktQiBSVXJUUA "CJam – Try It Online") ### Explanation ``` q Read input string f= For each character in that string, see if it equals 'd character "d" ) increased by 1 (that is, character "e") :+ Sum the results. Implicitly display ``` [Answer] # brainf\*\*\*, 215 bytes case sensitive ``` +[>>>>+++++[-<++>]<[-<++++++++++>]<[-<<->>]<<-[>-<[-]]>+<,]>[>>+>+<<<-]>>>[<<<+>>>-]<<+>[<->[>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]++++++++[<++++++>-]>[<<+>>-]>[<<+>>-]<<]>]<[->>++++++++[<++++++>-]]<[.[-]<]< ``` 155 of the bytes are from printing the number, from [here](http://esolangs.org/wiki/brainfuck_algorithms#Print_value_of_cell_x_as_number_for_ANY_sized_cell_.28ie_8bit.2C_16bit.2C_etc.29). [Try it online!](https://tio.run/##bY4xDgJBDAO/QkcRwgsifyRKAejQISSKA96/zC6coMCNnazt7HE5XG7n5@namqWAdaSHmSoGr3jP4UKEp5yxSha7ElFDsS86EmGwV@ckkvr2EBNxDOTGKYSNVsDOa7Xm5zxNvdT0K7q3f0n6Y@dhT1FUtPaYl2naTNv7Cw) [Answer] # APL, 9 bytes *2 bytes saved thanks to @Adam* ``` ≢⍞∩22⊃⎕AV ``` **How?** ``` 22⊃⎕AV ⍝ 'e' ⍞∩ ⍝ intersect with input ≢ ⍝ count ``` [Answer] ## CJam, 10 bytes It's annoying that the operation to count the number of instances, `e=`, contains an `e`. ``` q"&dd<":)~ ``` This creates a string `&dd<` , increments every code point to get `'ee=`, and then executes it. [Answer] # Python 3, ~~30~~ ~~26~~ 24 bytes Extremely basic: ``` lambda s:s.count('\x65') ``` 4 bytes off thanks to @Challenger's suggestion (adapted to this solution). ~~51~~ ~~46~~ 44 bytes, but I like it better: ``` lambda s:''.join('1'for i in s if i=='\x65') ``` Output is in unary. I found it first in the hopes that the other way was impossible; for once I'm annoyed that Python lets me do things the easy way. 5 bytes off thanks to @Challenger. 2 bytes off of each thanks to @xnor. Attribution for the simple method: <https://stackoverflow.com/questions/1155617/count-occurrence-of-a-character-in-a-string> Attribution for the unary one: <https://stackoverflow.com/questions/1450897/python-removing-characters-except-digits-from-string> [Answer] # [Aceto](https://github.com/aceto/aceto), ~~21~~ 19 bytes ``` Ic!_ o=ML d'I` ,dOp ``` We read a character and duplicate it, then push a "d" and increment its value to have an e. We then store the equality with `M`. *Now* we invert the input to get True when we're done, and conditionally jump to the print command at the end. Otherwise, we load our other truth value (whether it was an e), conditionally increment, and jump back to the `O`rigin. [Answer] # PHP, 27 Bytes ``` <?=count_chars($argn)[101]; ``` [Try it online!](https://tio.run/##K8go@G9jX5BRwKWSWJSeZ6uUkVqUqlCeqpBYlKpkzWVvB5S1Tc4vzSuJT85ILCrWACvTjDY0MIy1/v8fAA "PHP – Try It Online") [Answer] # [Scala](http://www.scala-lang.org/), 20 bytes ``` _.count(_=='\u0065') ``` [Try it online!](https://tio.run/##Fc2xCsIwEIDhV7mtySJZdLBEcHRwchXKNb3WSLiE5CqC@Oxn3X@@vwVMqHl8UhC4YmSgtxBPDc6lwOeFCebjTWrkxZ8uLOB12IW8spjB@@6@OnfYd1Z7KFsjZjZYl2actbb/qmIqDxxJ4raBXCf6Qz8 "Scala – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes ``` Ƶ0ç¢ ``` [Try it online!](https://tio.run/##MzBNTDJM/f//2FaDw8sPLfr/PzEpOSU1LT0jNRUA "05AB1E – Try It Online") ``` Ƶ0 # Push 101 ç # Convert to a character ¢ # Count the occurrences of that character ``` [Answer] # [Retina](https://github.com/m-ender/retina), 11 bytes ``` T`d-f`_f_ f ``` [Try it online!](https://tio.run/##K0otycxL/P8/JCFFNy0hPi2eKw3ISS0uAQA "Retina – Try It Online") `e` is indirectly referred to in the translation by creating a range from `d` to `f`. The `d`s and `f`s are deleted and the `e`s are translated to `f`s (we can't use `d` because that would expand to `0-9`). It then suffices to count the `f`s. ]
[Question] [ Write two functions/programs which take an ASCII code of character (8-bit unsigned integer) and one of them converts char to uppercase and other to lowercase. That is, they must be equivalent to following functions: ``` unsigned char toUpper(unsigned char c){ if (c >= 97 && c <= 122) return c - 32; return c; } unsigned char toLower(unsigned char c){ if (c >= 65 && c <= 90) return c + 32; return c; } ``` However you are not allowed to use branching (`if`s, `goto`s), loops and comparison and logical operators. Recursion, language built-in functions, regular expressions, arrays and objects also not allowed. You may use **only** arithmetic and bitwise operations on 8-bit unsigned integers. **Score:** 1 - for `| & ^ ~ >> <<` operators 1.11 - for `+ -` operators 1.28 - for `*` operator 1.411 - for `/ %` operators Answer with lowest total score (for two functions added) wins. If answers with equal score than first (oldest) answer wins. [Answer] ## C and other languages with integer division, ~~15.204~~ ~~14.644~~ ~~14.084~~ 11.864 ``` unsigned char toUpper(unsigned char c){ return c - ((c/97) ^ (c/123)) << 5; } unsigned char toLower(unsigned char c){ return c + ((c/65) ^ (c/91)) << 5; } ``` [Answer] ## C, C++ and related languages, 6.22 ``` unsigned char toggle(unsigned char c, unsigned char lo, unsigned char hi) { unsigned char m = (unsigned char)((lo - c) ^ (hi - c)) >> 7; return c ^ (m << 5); } unsigned char toUpper(unsigned char c) { return toggle(c, 96, 122); } unsigned char toLower(unsigned char c) { return toggle(c, 64, 90); } ``` [Answer] # C, 11.482 My functions I have found before posting question, I hope there will better ones. ``` unsigned char toUpper(unsigned char c){ unsigned char a = c - 97; return c - ((32 - a / 26) & 32); } unsigned char toLower(unsigned char c){ unsigned char a = c - 65; return c + ((32 - a / 26) & 32); } ``` [Answer] # [C (gcc)](https://gcc.gnu.org/), 9.042 step score ``` uchar toUpper(uchar c){ return c^(((uchar)(c+133)/230)<<5); } uchar toLower(uchar c){ return c^(((uchar)(c+165)/230)<<5); } // 9.042 step score ``` [Try it online!](https://tio.run/##jY/NCsIwEITvfYpBELK02tqqINE38Cp4EEFiWvdgGtIUEemz159gwZtzmGXY3Y9dNamU6v3d6rMu0ZqGK6PPUJeTQ/t22X8KfL2zVjsRkqJHhJec9q0zUEchQoeEimdFQWleZLReL0hGXfQlbOvbn4Tl4oeANMVqms1zNF5bNKp2umfjcT2xEYSACmCWn1DWDoI3mUQcs8R35i3rXqulGI2zfI/BDmaUgJPhUaZkOJmJArWLuv4J "C (gcc) – Try It Online") # [C (gcc)](https://gcc.gnu.org/), 2.11 existance score ``` uchar sub(uchar a, uchar b) {return a-b;} uchar shr(uchar a, uchar b) {return a>>b;} uchar add(uchar a, uchar b) {return sub(a, sub(0, b));} uchar isneg(uchar a) {return shr(a, 7);} uchar reach230(uchar a) {return shr(add(isneg(a),isneg(sub(229,a))),1);} uchar dif(uchar a) {uchar t=reach230(a); t=add(t,t); t=add(t,t); t=add(t,t); t=add(t,t); t=add(t,t); return t;} uchar toUpper(uchar c){ return sub(c,dif(add(c,133))); } uchar toLower(uchar c){ return add(c,dif(add(c,165))); } ``` [Try it online!](https://tio.run/##nZDBboQgEIbvPsVkkyaSZRNX0zYN2X2CXpv00AsCKoeiQUzTbHx2O4iih3YP5QAz8H/zDyNOtRCT@@6UVBUMpte1URJEwy0MfmfTfEA/lGmIOA0vUBK4WeUGa4CfSjYmi7Kx95TX6yblUt6Reku890dG8YFETvdG1Su5A9AZgedNaBUXTV5kf2jRPpTihIbAm@X5C@WEEHreCkld7WqEyF1ieU4Ypr6eo@4f8dKUi36ufes6tQ5SkBvshiKob8fTgp6LAltlsIGv7ddvYJDvwKfHAE7aOPjk2qT4swRwLUNmc1K1FlJ9yRgcj5rBqvGrs4hW6eEhy98hbh/mQEHT@AVNaOxKo@OMj8k4/QA "C (gcc) – Try It Online") ]
[Question] [ **This question already has answers here**: [Run Length Decoding](/questions/12902/run-length-decoding) (51 answers) Closed 7 years ago. Your task is to take an input, for example: `a,b,4,5` And produce an output, which per this example is `aaaabbbbb` `a,b,4,5` means: the lowercase character "a" is repeated 4 times, and is then followed by the lowercase character "b" repeated 5 times, making the total number of characters 4+5=9 Another example: the input `a,B,5,4`, should produce the output `aaaaaBBBB`, which is: the lowercase letter "a" is repeated 5 times, followed by the uppercase letter "B" repeated 4 times. Some more examples: ``` Input --> Output a,b,4,6 --> aaaabbbbbb a,b,c,1,2,3 --> abbccc a,e,d,f,g,1,2,3,4,5 --> aeedddffffggggg A,b,4,5 --> AAAAbbbbb A,b,C,1,2,3 --> AbbCCC A,B,c,D,1,2,3,4 --> ABBcccDDDD ``` Note how the output must have only the required letters, nothing else, except trailing newlines. The format of the input should be exactly as you see in the above examples, so your code does not have to support any additional formats/styles of the input. The output must be displayed in a format exactly as the examples show, this means no commas, spaces, etc, separating the letters. Trailing newlines are okay, if you cannot avoid them. Standard loopholes are disallowed, and the output is case sensitive. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins! [Answer] ## [05AB1E](https://github.com/Adriandmen/05AB1E/), 11 bytes ``` ',¡2äøvy`×? ``` **Explanation** ``` ',¡ # turn input into a list split at commas 2ä # divide that list in 2 ø # zip, turning the list into pairs of [letter, number] v # for each pair y`×? # print letter number of times ``` [Try it online](http://05ab1e.tryitonline.net/#code=JyzCoTLDpMO4dnlgw5c_&input=QSxCLGMsRCwxLDIsMyw0) [Answer] # Pyth - 14 bytes ``` Ac2cz\,s*VGsMH ``` [Try it online here](http://pyth.herokuapp.com/?code=Ac2cz%5C%2Cs%2aVGsMH&input=A%2CB%2Cc%2CD%2C1%2C2%2C3%2C4&debug=0). [Answer] # APL, 26 bytes ``` {(∊(//)C⎕VFI⍵)/⍵~⎕D,C←','} ``` Test: ``` {(∊(//)C⎕VFI⍵)/⍵~⎕D,C←','}'A,b,C,1,2,3' AbbCCC ``` APL has a built-in for this, so all the code is really doing is parsing the string: ``` 1 2 3/'AbC' AbbCCC ``` Explanation: * `⍵~⎕D,C←','`: remove all digits and commas from the input, leaving only the letters. (Since it only has to deal with single letters, this works.) * `∊(//)C⎕VFI⍵`: using the comma as a field separator, get all valid numbers in the input. * `/`: replicate each letter by the required amount [Answer] # Python 2 - 88 bytes ``` X=map(str,input().split(',')) k=len(X)/2 print''.join(X[i]*int(X[i+k])for i in range(k)) ``` Edited to remove whitespace [Answer] # Python 2, 66 bytes ``` i=input();l=len(i)/2 print''.join(s*y for s,y in zip(i[:l],i[l:])) ``` Uses every Python golfer's favourite function, `zip()`. Takes input with letters in quotes e.g.: ``` 'a','b',4,6 ``` [**Ideone it!**](https://ideone.com/yGrsWy) [Answer] # PHP, 84 bytes ``` $b=split(',',$argv[1]);while($i<$n=count($b)/2)echo str_repeat($b[+$i],$b[$n+$i++]); ``` Takes the input string as the first argument as in `php script.php a,B,c,3,2,6`. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/200722/edit). Closed 3 years ago. [Improve this question](/posts/200722/edit) # Challenge You will be given a string as an argument. You need to convert that string to upper case. But you can't use any built in method or function nor any external programs. # Rule No use of built in methods or functions or external programs. Only arithmetic, bitwise, logical operators, regex, replace, split, join, ASCII codes are allowed. # Input The string as an argument. The string can contain spaces and special characters. # Output The string in upper case. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest code wins. [Answer] # [Japt](https://github.com/ETHproductions/japt), 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) ``` ;dCíB ``` [Try it here](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=O2RD7UI&input=IkhlbGxvLCBXb3JsZCEi) [Answer] # [Turing Machine Code](http://morphett.info/turing/turing.html), 279 bytes ``` 0 q Q r 0 0 w W r 0 0 e E r 0 0 r R r 0 0 t T r 0 0 y Y r 0 0 u U r 0 0 i I r 0 0 o O r 0 0 p P r 0 0 a A r 0 0 s S r 0 0 d D r 0 0 f F r 0 0 g G r 0 0 h H r 0 0 j J r 0 0 k K r 0 0 l L r 0 0 z Z r 0 0 x X r 0 0 c C r 0 0 v V r 0 0 b B r 0 0 n N r 0 0 m M r 0 0 _ _ r 0 0 * * r 0 ``` [Try it online!](http://morphett.info/turing/turing.html?1254a1b75ca23153c4298ae1297bd12c) [Answer] # [Keg](https://github.com/JonoCode9374/Keg), 14 bytes ``` (&az⑻•[& -|&], ``` [Try it online!](https://tio.run/##y05N//9fQy2x6tHE3Y8aFkWrKejWqMXq/P/vkZqTk6@jEJ5flJOi@F83s@i/bk4BAA "Keg – Try It Online") Finally! A challenge Keg was designed for! This utilises the fact that a) subtracting 32 from the ordinal value of any lower-case letter gives its upper-case counterpart and b) characters are treated as numbers when arithmetic is applied. The unicode part is to ensure the letter is in the lower case range, without using built-ins. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), ~~8~~ 5 bytes (Once again, a'\_' uses something that I didn't know even existed in 05AB1E.) ``` AžpR‡ ``` ## Explanation ``` # Implicit input A # Push lowercase alphabet žp # Push uppercase alphabet reversed R # And reverse it again ‡ # Transliterate J # Join list ``` [Try it online!](https://tio.run/##yy9OTMpM/f//3FbHo/sKgh41LKz1@v/fPy9VIaQ8Xw8A "05AB1E – Try It Online") # Original solution without ‡, ~~19~~ 18 bytes ``` εDAskD®ÊižpRèës}}J ``` [Try it online!](https://tio.run/##ASoA1f9vc2FiaWX//861REFza0TCrsOKacW@cFLDqMOrc319Sv//T25lIFR3by4 "05AB1E – Try It Online") ## Explanation ``` # Implicit input ε } # Loop on each character εD } # Duplicate ε A } # Push lowercase alphabet ε s } # Swap ε k } # Find index of character in alphabet ε D } # Duplicate for comparison ε ® } # Push -1 (see link below) ε Ê } # Check if equal ε i ë }} # If-else statement ε ižp ë }} # Push uppercase alphabet in reverse ε i R ë }} # Reverse the string (so now it's just the uppercase alphabet) ε i èë }} # Index the uppercase alphabet ε i ës}} # Swap to get character J # Join all the items ``` If you're wondering why `®` returns -1, [go here](https://codegolf.stackexchange.com/a/96417/91569) [Answer] # Batch, ~~245~~ 116 Bytes ``` @Set v=%~1 @for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)do @call set v=%%v:%%A=%%A%% @ECHO(%v% ``` Somewhat ugly and brute forced, using a for loop to enact substring modification on each instance of a character. 129 bytes dropped thanks to Neil [Answer] # [Erlang (escript)](http://erlang.org/doc/man/escript.html), 56 bytes Numeric lists are strings in Erlang. (9 bytes away from C, let's see if I can get this shorter.) ``` f([H|T])->[H-if H>97,H<122->32;1<2->0end]++f(T);f(N)->N. ``` [Try it online!](https://tio.run/##Sy3KScxL100tTi7KLCj5z/U/TSPaoyYkVlPXLtpDNzNNwcPO0lzHw8bQyEjXztjI2tAGSBuk5qXEamunaYRoWqdp@AHV@un9z03MzNOIjtVU0LVTyMy3Ki/KLEnVSNNQynDNqVPS1NT7DwA "Erlang (escript) – Try It Online") ## Explanation ``` f([H | T]) -> % Try to split the input into head & tail [H - % Subtract the current item by: if H > 97, H < 122 -> 32; % If the item's ord code is in the lowercase letter range:Return 32 1 < 2 -> 0 % Otherwise, return 0. 1<2 is 1 byte shorter than true. end ] ++ f(T); % Concatenate with the uppercased tail f(N) -> N. % If the tail is the null list (i.e. it can't be splitted): % Return this operand. ``` ``` [Answer] # [Bash](https://www.gnu.org/software/bash/) + core utilities, 10 bytes ``` tr a-z A-Z ``` [Try it online!](https://tio.run/##S0oszvhfqqFZ/b@kSCFRt0rBUTfqfy1XanJGvoK6R2pOTr6OQnh@UU6KorpCjULpfwA "Bash – Try It Online") [Answer] # [4](https://github.com/urielieli/py-four), 54 bytes Thanks to @PkmnQ for pointing out the bug! ``` 3.6993269897697017008003010098801100009960100950070094 ``` [Try it online!](https://tio.run/##M/n/31jPzNLS2MjM0sLS3MzS3MDQ3MDAwsDA2MDQwMDSwsLAEEgDWZZmYAFTAwOgvKXJ//@BuibmxqqJ4cWuKWnuGVnZOYr2WgA "4 – Try It Online") # [4](https://github.com/urielieli/py-four), 28 bytes (old answer, only supports lower case and nothing else XD) ``` 3.69932700800100009950070094 ``` [Try it online!](https://tio.run/##M/n/31jPzNLS2MjcwMDCwMDQAAgsLU0NDIB8S5P//xOLU9LSM7KycwA "4 – Try It Online") [Answer] # [C (gcc)](https://gcc.gnu.org/), ~~47~~ 45 bytes Saved 2 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!!! ``` f(char*s){for(;*s;++s)*s^=*s>96&*s<123?32:0;} ``` [Try it online!](https://tio.run/##NY3RCoIwFIbve4rToJhzQSkENS266w2CtMiW1mBq7HhT4rPbXHV1fn6@/ztydpey7wsqH5lh6LVFbahgKHwfPYbnmOFmtZwyjBZBuA2D9Vx0vRJlpirqtSNwsyYJTnFL9rnWNYdDbfRtTDi5XtrdMXuTTvw4tMH5VRTYB2oQgKoa0BADNkbnFW0SdfIsBxiXmfVJqv2FK8q8lM8XRT4g/N8WFN19GisqKEnJBFMCsw18U1oRDm4BDuxGXf8B "C (gcc) – Try It Online") [Answer] # APL+WIN, 28 bytes Prompts for string: ``` ⎕av[i-32×(i←⎕av⍳⎕)∊(97+⍳26)] ``` Converts string to relevant indices in APL's atomic vector, identifies indices of lower case letters, decrements only those indices by 32 and converts resulting string back to characters. [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 9 bytes ``` ⭆S§⁺αι⌕βι ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRCO4BEil@yYWaHjmFZSWQLgamjoKjiWeeSmpFRoBOaXFGok6CplAMbfMvBSNJBAbCKypYATXf92yHAA "Charcoal – Try It Online") Link is to verbose version of code. Only 7 bytes longer than the built-in! Explanation: ``` S Input string ⭆ Map over characters and join ⌕ Find index in β Lowercase alphabet of ι Current character § Cyclically index into ⁺ Concatenation of α Uppercase alphabet ι Current character Implicitly print ``` If the input character is not found in the lowercase alphabet, the returned index is `-1`, which represents the last character when passed to the cyclic index function. [Answer] # [Retina](https://github.com/m-ender/retina/wiki/The-Language), 5 bytes ``` T`l`L ``` [Try it online!](https://tio.run/##K0otycxLNPz/PyQhJ8Hn/3@P1JycfB2F8PyinBRFAA "Retina – Try It Online") `T`ransliterate lower case `l`etters into upper case `L`etters. [Answer] ## 16/32/64-bit x86 assembly language, 17 bytes ``` AC l1: lodsb 3C 61 cmp al, 'a' 72 06 jb l2 3C 7A cmp al, 'z' 77 02 ja l2 24 DF and al, 0dfh ;convert to uppercase AA l2: stosb 84 C0 test al, al 75 F0 jne l1 C3 ret ``` Call with (r/e)si pointing to source string, (r/e)di to destination buffer to hold converted text. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/6454/edit). Closed 2 years ago. [Improve this question](/posts/6454/edit) Given an a-by-b sized grid, and a chess knight, determine: * A starting point and path the knight can take to visit every square in the grid * or "NOT POSSIBLE", if not possible. **Input:** Two integers, `a`, `b`. **Output:** Numbers output in an a-by-b grid: ``` 1 4 7 10 8 11 2 5 3 6 9 12 ``` Where `1` is where the knight starts, `a*b` is where the knight ends, and the numbers signify the path the knight must take, in ascending order. The knight cannot land on the same square twice. The rows of the grid must be separated with a newline, and the items in each row must be separated with a space. **Test Cases:** | is a newline. `3 4 -> 1 4 7 10 | 8 11 2 5 | 3 6 9 12` `2 3 -> NOT POSSIBLE` If there is a solution there will be more than one: any valid solution is acceptable. Shortest code wins. **Please do not use any programming languages that are known to produce short programs: e.x. GolfScript, APL, J, K, etc.** [Answer] ### Ruby, 306 284 characters ``` w,h=eval"[#{gets}]" f=Hash.new{|g,k|s,x,y,*r=k x<0||y<0||x<w&&y<h&&s>0&&'$&(,268:'.bytes{|u|r|=f[[s-1,x-2+u%5,y-9+u/5]].select{|l|l[y*w+x]<1}} g[k]=r.map{|l|l=l*1;l[y*w+x]=s;l}} f[[1,0,0]]=[[1]+[0]*(w*h-1)] (s=f[[w*h,w-1,h-1]][0]||(puts"NOT POSSIBLE"))&&s.each_slice(w){|f|puts f*" "} ``` Implementation in Ruby, takes input from STDIN and outputs to STDOUT. Although a little bit optimized it is still extremely slow on large grids. ``` > 5,3 NOT POSSIBLE > 5,4 1 18 5 12 9 6 15 10 19 4 17 2 13 8 11 14 7 16 3 20 ``` *Edit:* Ventero pointed out some improvements whiche saved several chars. I also changed the encoding of possible moves to be much shorter now. [Answer] ## Python, 420 ``` w,h=input() s=w*h d=range def r(l):y=l/w;x=l%w;return[x+p+w*(q+y)for p,q in[(1,2),(2,1),(-2,1),(-1,2),(-1,-2),(-2,-1),(2,-1),(1,-2)]if 0<=x+p<w and 0<=q+y<h] def f(p): a={l:len(r(l))for l in r(p[-1])if l not in p} for l in[k for k in a if a[k]==min(a.values())]: x=f(p+[l]) if len(x)==s:return x return p e=f([0]) print len(e)<s and"NOT POSSIBLE"or'\n'.join([' '.join(`e.index(x+y*w)+1`for x in d(w))for y in d(h)]) ``` I've sacrificed shorter code for reasonable performance, so it should be able to find solutions for boards up to 9x9 in under 3 seconds. [Answer] ### Ruby ~~364~~ 359 ``` K=->a,b{A,B=a,b;(0...A*B).each{|i|Z[[i]]};p"NOT POSSIBLE"} Z=->v{c=v.last abort (0...v.size).map{|i|{:i=>i+1,:x=>v[i]}}.sort_by{|i|i[:x]}.map{|i|i[:i]}.each_slice(B).map{|r|r*' '}*?\n if v.size==A*B ([[1,2],[2,1],[-2,1],[-1,2],[-1,-2],[-2,-1],[2,-1],[1,-2]].map{|d|o=(c/B)+d[0] u=(c%B)+d[1] (o>=0&&0<=u&&A>o&&B>u)?o*B+u :-1}.flatten-[-1]-v).each{|i|Z[v+[i]]}} ``` Same idea as my C# answer. This gets invoked like this: `K[a,b]` and outputs the desired result to the console. **Online demos:** Test case 1: <http://ideone.com/yDiiS> Test case 2: <http://ideone.com/WVUmX> Example of a bigger board (4x5): <http://ideone.com/hItNo> [Answer] ### C# ~~796~~ 793 ``` using System;using System.Collections.Generic;using System.Linq;namespace Z{public class P{public static void Main(){new P().K(3,4);}int x, y;void K(int a, int b){x=a;y=b;for(var s=0;s<x*y;s++)K(new[]{s});Console.WriteLine("NOT POSSIBLE");}void K(int[] v){if(v.Length<x*y)foreach(var m in M(v))K(v.Concat(new[]{m}).ToArray());else{Console.WriteLine(String.Join("\n",v.Select((p,i)=>new{p,i}).OrderBy(e=>e.p).GroupBy(e=>e.p/y).Select(g=>String.Join(" ",g.Select(e=>e.i+1)))));Environment.Exit(0);}}IEnumerable<int> M(int[] v){var c=v.Last();var q=new{X=c/y,Y=c%y};return(from m in new[]{new{X=1,Y=2},new{X=2,Y=1}}from d in Enumerable.Range(0,4).Select(i=>new{X=(i&2)-1,Y=(i&1)*2-1})select new{X=q.X+d.X*m.X,Y=q.Y+d.Y*m.Y}into p where p.X>=0&&p.Y>=0&&p.X<x&&p.Y<y select p.X*y+p.Y).Except(v);}}} ``` This code finds a solution (if any) using brute force. Here's the ungolfed (and slightly refactored) version: <http://pastie.org/4149829> **Input:** Modify the parameters in the `new P().K(...);` call. **Output:** To the console, in the required format **Online demos:** Test Case 1 (3, 4): <http://ideone.com/UU9sw> (another solution than OP's, but it's a valid one) Test Case 2 (2, 3): <http://ideone.com/ZX9xC> A bigger board (4, 7): <http://ideone.com/QKuXL> *(this takes close to 5s to run, so retry if it fails the first time)*. ***Note:** Mono does not have the `String.Join` method overload that takes as a parameter an `IEnumerable<T>`, so in order to get this working on IdeOne I have to modify the code a bit (modify these `IEnumerable<T>`s to `string[]`).* [Answer] # Python, 316 Took about 30 minutes to run on input of `3 4`. I wouldn't try it on anything larger. ``` import itertools as I r=range x,y=map(int,raw_input().split()) m=[(a,b)for a in r(x)for b in r(y)] q=[n for n in I.permutations(m,x*y)if all((abs(o[0]-p[0]),abs(o[1]-p[1]))in((1,2),(2,1))for(o,p)in zip(n,n[1:]))] print'\n'.join(' '.join([`q[0].index(z)+1`for z in m][i:i+y])for i in r(0,x*y,y))if q else"NOT POSSIBLE" ``` I notice the other Python answers get input by doing `x,y=input()` rather than `x,y=map(int,raw_input().split())`, but the question does not allow for commas in the input so it seems the former method would fail. If the question does allow commas in the input, I'll shave an additional 20 characters off my answer. I tried a recursive solution, but the best I could get was 334 characters: ``` r=range x,y=map(int,raw_input().split()) m=[(a,b)for a in r(x)for b in r(y)] o=[] def f(m,x=0): for n in m: if x==0 or map(lambda x,y:abs(x-y),n,x)in([1,2],[2,1])and not o: if len(m)==1 or f(m-{n},n)or o:o.append(n) f(set(m)) print'\n'.join(' '.join([`o.index(z)+1`for z in m][i:i+y])for i in r(0,x*y,y))if o else"NOT POSSIBLE" ``` [Answer] ## Python, 370 367 366 338 Simple recursive solution. It isn't efficient, but works fast for example cases :-) ``` import itertools as I P=I.product a,b=input() r=range;A=r(a);B=r(b);T={} def S(x,y): if 0<=x<a and 0<=y<b and(x,y)not in T: T[x,y]=len(T)+1 for i,j in P((-2,2),(-1,1)):S(x+i,y+j);S(x+j,y+i) if len(T)!=a*b:T.pop((x,y)) for q,w in P(A,B):S(q,w) print"\n".join(" ".join(str(T[i,j])for j in B)for i in A)if len(T)==a*b else'NOT POSSIBLE' ``` [Answer] ## VBA 494 574 833 chars Fixing to account for the transposed example added quite a bit of code... I squeezed a little more out be shifting around some `If` checks to avoid using `End If`. This now correctly handles `4, 5` and `5, 4`, but it takes impossibly long for `4, 7`, and I'm not 100% sure it works for that set. ``` Dim z,v,e,i,j,p,l Sub k(a,b) e=a*b:q:i=2 If c(a,b) Then z(e)=e:j=e+1 For i=1 To e:s=s & z(i) & IIf(i Mod b=0,vbCr,vbTab):Next MsgBox IIf(j-1=e,s,"NOT POSSIBLE") End Sub Sub o() z(l)=j:v(l)=1:p=l:i=p:j=j+1 End Sub Sub u(r,t) z(r)=0:v(r)=0:p=t:j=j-1 End Sub Sub q() ReDim z(1 To e),v(1 To e):z(e)=e:v(e)=1:p=1:z(1)=p:v(1)=p:j=2 End Sub Function w(b) f=(p-1) Mod b+1:m=(l-1) Mod b+1:g=Int((p-1)/b)+1:n=Int((l-1)/b)+1:w=(((f-2=m Or f+2=m) And (g-1=n Or g+1=n)) Or ((f-1=m Or f+1=m) And (g-2=n Or g+2=n))) End Function Function c(a,b) t=p:m=i: If i>1 And i<e Then For h=1 To 8:l=p+Choose(h,(b-2),(b+2),(2*b-1),(2*b+1),-(b-2),-(b+2),-(2*b-1),-(2*b+1)):r=l:If l>1 And l<e Then If v(l)=0 Then If w(b) Then o:If j>=e Then l=j:If w(b) Then c=1 Else u r,t Else c=c(a,b):If c=0 Then u r,t Next:End If If c=(i>=e) Then i=m+1:c=c(a,b) End Function ``` [Answer] # [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 22 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?") ([SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")) ``` ⊃⌂kt,⍥⊆'NOT POSSIBLE'⍨ ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1FX86OepuwSnUe9Sx91tan7@YcoBPgHB3s6@biqP@pd8T/tUduER719IHW9ax71bjm03vhR28RHfVODg5yBZIiHZ/D/NAVjBROuNAUjBWMA "APL (Dyalog Extended) – Try It Online") `⊃` the first of… `⌂kt` the first knights tour (if possible, else: an empty list) `,⍥⊂` juxtaposed with `'NOT POSSIBLE'⍨` the required fall-back value ]
[Question] [ It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, [visit the help center](/help/reopen-questions). Closed 12 years ago. Declare a numeric variable that is **not** floating point and do an operation that changes the value with the largest amount of difference so the result of the variable is far from the original value. Solutions will be scored based on the magnitude of the difference between initial value and the value after changed, and shortness of code. **Edit:** I realize that this was a bit vague - sorry about that, it's my first try on code golf... I want to also emphasize that the result must not cause overflow. So once the variable is declared with a specific type (which must not be floating point), the result would have to be valid within that type. [Answer] ## Java (55 26 19 chars, Diff: 2^64-1 = 18446744073709551615) Given a very unclear spec on what we're supposed to be doing, here's a best try :-) Obviously I will easily be beat out by languages that have arbitrary precision integers like Python or APL/J. ``` long o=Long.MIN_VALUE;o+=Long.MAX_VALUE+Long.MAX_VALUE; ``` Demo: <http://www.ideone.com/7HyCW> **EDIT**: Shorter version, making use of Long underflow to wrap around from `MIN_VALUE` to `MAX_VALUE` (26 chars): ``` long o=Long.MIN_VALUE;o--; ``` Demo: <http://www.ideone.com/Qfao7> **EDIT 2:** Shortest yet taking into account `@ratchet freak`'s suggestions: ``` long o=1L<<63;o=~o; ``` Demo: <http://www.ideone.com/2M9oa> [Answer] ## D (15 chars 2^64-1 difference) ``` ulong o=0;o=~o; ``` uses unsigned long and logical NOT to get max value note that using `ucent` would get me to 2^128-1 difference (if it were to be implemented at least) [Answer] ## Haskell - 8 characters (Infinite difference) `f=f.(+1)` Use `f` on `Integer`. [Answer] ### Golfscript ``` 2{.?}9* ``` 7 chars, unimaginably large difference. (The loop executes 9 times. The first time maps 2 -> 2^2 = 4. The second time maps 4 -> 4^4 = 256. The third time maps 256 -> 256^256 ~= 3.23 \* 10^616. The fourth time overflows memory, but not the datatype...) [Answer] # J - 16 characters ``` a=.<.<:(a=.2)^31 ``` The value of a changes from 2 to 2147483647. The calculation makes the value become float, but the final result is integer. There are also extended integers, but I don't know if they would be acceptable. ``` a=.(a=.0)+!100000x ``` Yes, that really spells out mathematically as !100000. J can crunch it (in a few minutes), brute force. [Answer] ## C with SSE2 (79 chars, Difference: 2^128-1 = 3.4e38) ``` #include<emmintrin.h> main(){__m128i v=_mm_set1_epi8(-1);v=_mm_xor_si128(v,v);} ``` This initially sets the 128 bit unsigned int `v` to its maximum value, and then changes this value to 0 by XORing `v` with itself. [Answer] ## Python (13 chars, Difference: 9^(9^9) (369,693,100 *digits*!)) ``` a=0;a=9**9**9 ``` I believe that the result of this operation is not a float, isn't it? If that's problem because it doesn't yield the result... ## Mathematica (11 chars, Difference: only 15,151,335 digits) ![8^8^8](https://i.stack.imgur.com/U175B.png) If it's still a problem because this value is not the maximum *possible*, then, `a=2^1073741696;a*=-1` (20 chars) will do the work. [Answer] ### bc 15chars: On my system I can go until 8^8^8 without error, but 6^6^6 would already be too long to report it here, so take 5^5^5 as an example; 7^7^7 is in the range of one minute on a single core 2Ghz machine. With 8 you should have some time left. ``` echo "k=8^8^8;k*=-1;k" | bc ``` printable result for one page: ``` echo "k=5^5^5;k*=-1;k" | bc ``` -1911012597945477520356404559703964599198081048990094337139512789246\ 52053024261580301205938651973985026558644015579446223535921278867380\ 69722884101469159866020879618967571957018392816603380476112259755336\ 26101001482651123413147768252411493094447176965282756285196737514395\ 35754247909321920664188301178716912255242107005070906467438287085144\ 99502565861944615431835113798491336917799281274338404315492368555267\ 83596374102105331546031353725325748636909159778690328266459182983815\ 23028693657287369142264813129174376213632573032164528297948686257624\ 53622180176732249405676428193600787207138370723553054463561539464011\ 85348493792719514594505508232749221605848912910945189959948686199543\ 14766693801303717616359259447974616422005088507946980448713320513316\ 07391342305401988725700383298012460501970134673971759090273894939238\ 17315786996845899794781068042822436093783946335265422815704302832442\ 38551508231649096728571217170812323279048181726832751011274678231741\ 09858886837085220007117334922539133223007561471804290075276777933523\ 06200618286012455254243061006894805446584704820650982664319360960388\ 73625851074707434063628697657670269925864995355797631817390255089133\ 12232947439303439561613283340728316634982581452268620043077990846881\ 03804187368324800903873596212919633602583120781673673742533322879296\ 90720549059562140688882599124458184237959786347648431567376092362509\ 03715117989414242622702200662864868678687101829808728025606931019492\ 80830825044198424796792058908817112327192301455582916746795197430548\ 02640464685400273399386079859446596150175258696581144756851004156868\ 77309037124825353438392853975987494584970500382250124892840018265900\ 56251286187629938044407340142347062055785305325034918189589707199305\ 66218851296318750174353596028220103821161604854512103931331225633226\ 07664362366882968502088394961428304847391139916696226499485636852347\ 12873294796680884509405893951104650944137909502276545653133018670633\ 52132302846051943438139981056140065259530073179077271106578349417464\ 26847209561346473277485842382748996687550525043942182321913572230540\ 66715373374248543645663782045701654593218154053548393614250664498585\ 40330746646854189014813434771465031503795417577862281177658587694168\ 0908203125 [Answer] ## BrainF\*\*\*, 3 characters, theoretically unlimited difference ``` [+] ``` Some implementations of BF wrap. "True" BF allows for unlimited integers. This has a difference of whatever you want it to be, plus it's only 3 characters long :) ]
[Question] [ **This question already has answers here**: [Palindrome Hello, World](/questions/59527/palindrome-hello-world) (65 answers) Closed 7 years ago. Your Task: Print "Hello, World!" using a palindrome. Simple, right? Nope. # You have one restriction: **you may not use comments.** "Comments" include * Normal `//` or `#` comments * Adding extraneous characters to a string literal * Triple-quoted string comments * Creating a string literal to hide characters You may not use a pre-defined procedure to print "Hello, World!". (like HQ9+'s H command) This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins. [Answer] ## Stuck, 0 bytes I think this wins? An empty program in stuck prints `Hello, World!` Shamelessly stolen from [this answer](https://codegolf.stackexchange.com/a/55425/32686) [Answer] # Bash, 47 bytes ``` echo Hello, World! exit tixe !dlroW, olleH ohce ``` [Answer] # Gogh, 31 bytes ``` "Hello, World!"Ƥ"!dlroW ,olleH" ``` --- ### Explanation ``` "Hello, World!" “ Push the string literal ” ¡ “ Output the TOS ” "!dlroW ,olleH" “ Push the string literal ” “ Non-implicit output ” ``` [Answer] ## [Help, WarDoq!](http://esolangs.org/wiki/Help,_WarDoq!), 1 byte ``` H ``` Print Hello, World!. ]
[Question] [ Optimize the following function for **number of tokens**: ``` int length(int x) { switch (x) { case 1: return 1; case 3: return 2; case 7: return 3; case 15: return 4; case 31: return 5; case 63: return 6; case 127: return 7; case 255: return 8; case 511: return 9; case 1023: return 10; case 2047: return 11; default: return 0; } } ``` No additional cases besides the 11 shown above need to be handled. The default case will never occur (but Java needs one, or else it does not compile). Any programming language is allowed. Whole programs are also allowed. If you embed another language inside strings, the tokens in the embedded language count as well. **The baseline is 53 tokens**, since separators don't seem to count in [atomic-code-golf](/questions/tagged/atomic-code-golf "show questions tagged 'atomic-code-golf'"). Have fun! [Answer] # Pyth, 4 tokens ``` slhQ ``` Exact same algorithm as my CJam solution. Tokens: ``` s int( l log2( h 1 + Q eval(raw_input()) )) ``` [Try it online here](http://pyth.herokuapp.com/?code=slhQ&input=1023&debug=0) [Answer] # gcc, 4 tokens ``` # define length __builtin_popcount ``` [Answer] # J, 3 tokens ``` #@:#: ``` * `#:`: binary array (`5 -> 1 0 1`) * `@:`: Atop: (`f@:g x -> f(g(x))`) * `#`: Lenght (`# 1 0 1 -> 3`) [Answer] # CJam, 5 tokens This is a simple equation, where y = log2(x + 1) ``` ri)2mL ``` Tokens: ``` r e# Read input token as string i e# Convert to integer ) e# Increment it by 1 2 e# This serves as the base of the log mL e# Log the first number in the base of the second number. i.e. ri) log 2 ``` [Try it here](http://cjam.aditsu.net/#code=ri)2mL&input=2047) [Answer] # Java, 5 tokens ``` x -> +" \1 \2 \3 \4 \5 \6 \7 \10 \11 \12 \13".charAt(x) ``` 1. x 2. + 3. string 4. charAt 5. x [Answer] # Python 2, 7 tokens This function passes the tests, but is not a reliable substitute for log2. ``` lambda x: len(bin(x))-2 ``` [Answer] # [Clip 10](https://esolangs.org/wiki/Clip), 4 tokens ``` lb2n ``` ## Explanation ``` n .- the numeric value of the input -. b2 .- convert to binary -. l .- length; i.e., number of digits -. ``` ]
[Question] [ **This question already has answers here**: [Smallest unique number KoTH](/questions/172178/smallest-unique-number-koth) (42 answers) Closed 1 year ago. The community reviewed whether to reopen this question 1 year ago and left it closed: > > Original close reason(s) were not resolved > > > # King of the Hill: Greed Control ## What is Greed Control Greed control is a **multiplayer** `round-based` game in which in every round, a player bet a number inside a specific range, say 1~100. Say 2 people betted 100, then they'd both get 100/2 which is `50` points in the game. **Basically, the players that choose the same number split the scores evenly (no rounding) and the total of their net score gain is the number they chose**. After a set number of rounds, players compare scores. The highest score generally wins the game overall. ## Your challenge Build a bot in `python`, specifically, `python 3` , that when given input, discussed in the section `input`, they give the number as an integer they bet as output. It must be a`function`. ## Input `information, points, round_number, sum_of_all, user_num`. `information` is a dictionary with integer keys in which each key's value is the number of bots that chose that key's number **last round**. `points` is the list of integers you can choose from. `round_number` is the round number. `sum_of_all` is like `information`, except it is the summation of **all rounds**. `user_num` is the number of players playing. ## We guarantee that We guarantee that `points` stay the same every round and is strictly increasing, all integers. However, it may not be consecutive. ## Controller function ``` from random import choice def random_better(information, points, round_number, sum_of_all, user_num): return choice(points) def greedy_better(information, points, round_number, sum_of_all, user_num): return points[-1] def calculator(information, points, round_number, sum_of_all, user_num): return sorted(points, key=lambda x:x/(information[x]+0.000000000001))[0] def smarty(information, points, round_number, sum_of_all, user_num): return sorted(points, key=lambda x:x/(information[x]+0.000000000001))[choice(range(1,40))] users = [random_better, greedy_better, calculator, smarty] * 10 user_names = [user.__name__.replace('_',' ') for user in users] rounds = 1000 points = sorted(list(range(1,101))) user_num = len(users) bots = [user for user in users] scores = [0.0 for user in users] information = {i:0 for i in points} sum_of_all = {i:0 for i in points} print('\n'*100) for round_number in range(rounds): choices = [bot(information, points, round_number, sum_of_all, user_num) for bot in bots] information = {score:choices.count(score) for score in points} scores = [scores[index] + choices[index]/information[choices[index]] for index in range(user_num)] print(f'\n\n\nRound #{round_number+1} Reports: ') print('\nBots Report: ') print('\n'.join([f'{user_names[index].ljust(20)} ' f'chose {choices[index]} ' f'and got {choices[index]/information[choices[index]]} additional points, ' f'making it now have {scores[index]} points!!! ' for index in range(user_num)])) print('\nDistribution Report: ') print('\n'.join([f'The number of bots who chose {num} is: {information[num]}!!! ' for num in points])) print('\nLeaderboard Report: ') sorted_list = sorted(range(user_num), key=lambda x: -scores[x]) print(f'\n{user_names[sorted_list[0]].ljust(20)} with {scores[sorted_list[0]]} points, ' f'\n{user_names[sorted_list[1]].ljust(20)} with {scores[sorted_list[1]]} points, and' f'\n{user_names[sorted_list[2]].ljust(20)} with {scores[sorted_list[2]]} points!!! ') sum_of_all = {i:sum_of_all[i]+information[i] for i in points} print('\n\n\nFinal Report Card: \n') print('\n'.join([f'{user_names[sorted_list[index]].ljust(20)}: ' f'{scores[sorted_list[index]]} points. ' for index in range(user_num)])) ``` The first part is imports. You may only depend on default python built-ins or the python standard library. Or if you manage to hide it and I out of coincidence have the package... The second part is your functions. Naming your function `bot_name_with_underscores` is encouraged. The third part are game parameters. The number of rounds, the accessible outputs, etc. The fourth part is **running the program**!!! An example output is as follows: ``` Round #1 Reports: Bots Report: random better chose 3 and got 1.5 additional points, making it now have 1.5 points!!! greedy better chose 10 and got 10.0 additional points, making it now have 10.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 1.0 points!!! smarty chose 3 and got 1.5 additional points, making it now have 1.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 0!!! The number of bots who chose 3 is: 2!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 1!!! Leaderboard Report: greedy better with 10.0 points, random better with 1.5 points, and smarty with 1.5 points!!! Round #2 Reports: Bots Report: random better chose 7 and got 7.0 additional points, making it now have 8.5 points!!! greedy better chose 10 and got 5.0 additional points, making it now have 15.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 2.0 points!!! smarty chose 10 and got 5.0 additional points, making it now have 6.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 0!!! The number of bots who chose 3 is: 0!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 1!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 2!!! Leaderboard Report: greedy better with 15.0 points, random better with 8.5 points, and smarty with 6.5 points!!! Round #3 Reports: Bots Report: random better chose 4 and got 4.0 additional points, making it now have 12.5 points!!! greedy better chose 10 and got 10.0 additional points, making it now have 25.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 3.0 points!!! smarty chose 2 and got 2.0 additional points, making it now have 8.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 1!!! The number of bots who chose 3 is: 0!!! The number of bots who chose 4 is: 1!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 1!!! Leaderboard Report: greedy better with 25.0 points, random better with 12.5 points, and smarty with 8.5 points!!! Round #4 Reports: Bots Report: random better chose 6 and got 6.0 additional points, making it now have 18.5 points!!! greedy better chose 10 and got 10.0 additional points, making it now have 35.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 4.0 points!!! smarty chose 2 and got 2.0 additional points, making it now have 10.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 1!!! The number of bots who chose 3 is: 0!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 1!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 1!!! Leaderboard Report: greedy better with 35.0 points, random better with 18.5 points, and smarty with 10.5 points!!! Round #5 Reports: Bots Report: random better chose 2 and got 2.0 additional points, making it now have 20.5 points!!! greedy better chose 10 and got 10.0 additional points, making it now have 45.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 5.0 points!!! smarty chose 6 and got 6.0 additional points, making it now have 16.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 1!!! The number of bots who chose 3 is: 0!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 1!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 1!!! Leaderboard Report: greedy better with 45.0 points, random better with 20.5 points, and smarty with 16.5 points!!! Round #6 Reports: Bots Report: random better chose 3 and got 3.0 additional points, making it now have 23.5 points!!! greedy better chose 10 and got 10.0 additional points, making it now have 55.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 6.0 points!!! smarty chose 2 and got 2.0 additional points, making it now have 18.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 1!!! The number of bots who chose 3 is: 1!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 1!!! Leaderboard Report: greedy better with 55.0 points, random better with 23.5 points, and smarty with 18.5 points!!! Round #7 Reports: Bots Report: random better chose 8 and got 8.0 additional points, making it now have 31.5 points!!! greedy better chose 10 and got 10.0 additional points, making it now have 65.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 7.0 points!!! smarty chose 3 and got 3.0 additional points, making it now have 21.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 0!!! The number of bots who chose 3 is: 1!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 1!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 1!!! Leaderboard Report: greedy better with 65.0 points, random better with 31.5 points, and smarty with 21.5 points!!! Round #8 Reports: Bots Report: random better chose 1 and got 0.5 additional points, making it now have 32.0 points!!! greedy better chose 10 and got 5.0 additional points, making it now have 70.0 points!!! calculator chose 1 and got 0.5 additional points, making it now have 7.5 points!!! smarty chose 10 and got 5.0 additional points, making it now have 26.5 points!!! Distribution Report: The number of bots who chose 1 is: 2!!! The number of bots who chose 2 is: 0!!! The number of bots who chose 3 is: 0!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 2!!! Leaderboard Report: greedy better with 70.0 points, random better with 32.0 points, and smarty with 26.5 points!!! Round #9 Reports: Bots Report: random better chose 3 and got 3.0 additional points, making it now have 35.0 points!!! greedy better chose 10 and got 5.0 additional points, making it now have 75.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 8.5 points!!! smarty chose 10 and got 5.0 additional points, making it now have 31.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 0!!! The number of bots who chose 3 is: 1!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 2!!! Leaderboard Report: greedy better with 75.0 points, random better with 35.0 points, and smarty with 31.5 points!!! Round #10 Reports: Bots Report: random better chose 2 and got 2.0 additional points, making it now have 37.0 points!!! greedy better chose 10 and got 5.0 additional points, making it now have 80.0 points!!! calculator chose 1 and got 1.0 additional points, making it now have 9.5 points!!! smarty chose 10 and got 5.0 additional points, making it now have 36.5 points!!! Distribution Report: The number of bots who chose 1 is: 1!!! The number of bots who chose 2 is: 1!!! The number of bots who chose 3 is: 0!!! The number of bots who chose 4 is: 0!!! The number of bots who chose 5 is: 0!!! The number of bots who chose 6 is: 0!!! The number of bots who chose 7 is: 0!!! The number of bots who chose 8 is: 0!!! The number of bots who chose 9 is: 0!!! The number of bots who chose 10 is: 2!!! Leaderboard Report: greedy better with 80.0 points, random better with 37.0 points, and smarty with 36.5 points!!! Final Report Card: greedy better : 80.0 points. random better : 37.0 points. smarty : 36.5 points. calculator : 9.5 points. ``` ## If any bot runs into an error, it fails. So **CHECK IT**!!! Make it **FOOLPROOF**!!! ## Winner This is [king-of-the-hill](/questions/tagged/king-of-the-hill "show questions tagged 'king-of-the-hill'"). # May the points be EVER in your favor! ``` Current information: Final Report Card: inspector gadget : 97190.0 points. greedy better : 49450.0 points. crab : 49450.0 points. random better : 48090.0 points. smarty : 21715.5 points. calculator : 993.5 points. ``` TO REPEAT, THIS IS NOT A DUPE OF [Smallest unique number KoTH](https://codegolf.stackexchange.com/questions/172178/smallest-unique-number-koth). [Answer] ## Crab ``` def crab(a,b,c,d,e): return 100 ``` If Crab can't get 100 points, nobody can. Might actually be competitive, as simulationist bots will pick a lower number to maximize points and not share, and other bots probably won't go as riskily to pick 100 every time. [Answer] # Inspector Gadget Assume most players who vote high will give the same answer given the same inputs. Run every bot and pick the highest unpicked number, while also telling later copies of ourselves to not step on our toes by giving them an upper bound, via the shared information dictionary. ``` def inspector_gadget(k,i,tt,e,ns): currentpick = 100 try: if "inspector" in k: currentpick=k["inspector"] currentpick -= 1 import inspect from copy import copy users = inspect.stack()[1][0].f_globals["users"] picks = [] for u in users: if u == inspector_gadget: continue try: picks.append(u(copy(k),copy(i),tt,e,copy(ns))) except Exception: pass while currentpick in picks: currentpick -= 1 k["inspector"] = currentpick return currentpick except Exception as e: return currentpick-1 ``` ]
[Question] [ # Background When you run `tail -f file` in bash, the file is outputted and then any subsequent appends. However, when you remove something that has already been displayed, `tail` outputs: ``` tail: nameoffile: file truncated ``` # Your Challenge When given an input `f`, append `tail: [value of f]: file truncated` (with trailing & leading newline) to the file `f`. You can assume that file `f` exists, the device is not full, `f` is not empty, and that you have permissions to write to `f`. # Test Cases Input: `something` File before: ``` Some thing ``` File after: ``` Some thing tail: something: file truncated ``` Input `relative/path/to/file` File before: ``` tail: relative/path/to/file: file truncated ``` File after: ``` tail: relative/path/to/file: file truncated tail: relative/path/to/file: file truncated ``` # Reference Implementation (Node.js) ``` x=>require("fs").appendFileSync(x,` tail: ${x}: file truncated `) ``` [Answer] # [Bash](https://www.gnu.org/software/bash/), 4̴0̴ 4̴6̴ 33 bytes ``` echo tail: $1: file truncated>>$1 ``` [Try it online!](https://tio.run/##ZcsxCoQwEIXhfk4xiBewDRJQ0NZiW5tsnJiATpY4nj@rhSLY/fC@9zWbz5msjygmLArLSqELC6Gkna0RmrQuq3wU1nU39KhRaJOTwCeuBOIDz3AsAL8UWBwWLbmYSI1cwPm7PTz7wiM3Tii9dP4D "Bash – Try It Online") Thanks @DigitalTrauma for `-7` bytes! [Answer] # Pyth - 33 bytes ``` .w%"\ntail: %s: file truncated"QQ ``` [Answer] # Python 3, 61 bytes ``` f=input();open(f,"a").write("\ntail: %s: file truncated\n"%f) ``` ~~Can't really try it online...~~ [Try it online!](https://tio.run/##fY7BCsIwEETv@YolUEhQevFW6UEP/YpcUrtpA3Fb0i3Fr69RqtaD7mEYhmXmDTfuejosDkrwNEystBBPk4Jgr3VjC3BCzJ476Ack5fYg553UYEeoCgHpqnyOnlHJOtgO3mKoDviwWzGEbTtK/VW5LRuiJ1byjK6PWKTHT1jlEW2jtF5cucIeVyZppX5RGGLrQwHZmNB9QOA40cUyNoZk5vTyf9nQyTHGX9OdvwM) [Answer] ## Batch, 47 bytes ``` @echo(>>%1 @echo tail: %~1: file truncated>>%1 ``` Assuming DOS newlines are acceptable on Windows... ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- This question does not appear to be about code golf or coding challenges within the scope defined in the [help center](https://codegolf.stackexchange.com/help/on-topic). Closed 1 year ago. [Improve this question](/posts/52287/edit) Given a natural number c as input, our task is finding the fastest way to calculate one -atleast- availabe integer solution (a,b) of [pell equation](https://en.wikipedia.org/wiki/Pell's_equation) **c=a²-b²**. Rules Built-in functions and loopholes arent given any interest. The program deals with integers (signed), the input is not supposed to abuse this range. Output can be formatted in any form. Your submission is scored by sum of milliseconds elapsed with these inputs: ``` 6 17 489 1270453 5609331 92 3343 74721 3920. ``` Lowest time wins. [Answer] **nasm x64 i7 - 2 - 5 milliseconds** ``` extern printf section .bss section .data fmt: db "%i - %i", 10, 0 NumberToTestF dq 5609331.0 ; put the number to test in floating NumberToTestI dq 0 ; format, ie not 489, but 489.0 Counter dq 0 OutsideLoop dq 0 Divide1 dq 2 Divide2 dq 1.7 section .text global main main: push rbp mov rbp, rsp sub rsp, 32 ; convert from float to int for faster cmp fld qword [NumberToTestF] movq xmm0, qword [NumberToTestF] cvttsd2si rax, xmm0 mov [NumberToTestI], rax ; Make 1st counter convert result to int fdiv qword [Divide2] fstp qword [OutsideLoop] movq xmm1, [OutsideLoop] cvttsd2si rax, xmm1 mov [OutsideLoop], rax ; make counter mov r8, [Divide1] xor rdx, rdx mov rax, [NumberToTestI] idiv r8 mov [Counter], rax ; initialize locals mov dword [rbp - 8], eax mov dword [rbp - 20], edi mov qword [rbp - 32], rsi jmp .l00p .t0p: mov eax, [Counter] mov dword [rbp - 4], eax jmp .b0tt0m .inn3r: ; square & subtract each ; number mov eax, dword [rbp - 8] mov edx, eax imul edx, dword [rbp - 8] mov eax, dword [rbp - 4] imul eax, dword [rbp - 4] mov ecx, edx sub ecx, eax mov eax, ecx ; final comparison ; if cmp == true print value ; & exit, if not keep looping cmp eax, [NumberToTestI] jnz .k33p0n mov eax, fmt mov edx, dword [rbp - 4] mov ecx, dword [rbp - 8] mov esi, ecx mov rdi, rax mov eax, 0 call printf jmp .d0n3 .k33p0n: add dword [rbp - 4], 1 .b0tt0m: mov eax, [OutsideLoop] cmp dword [rbp-4], eax jle .inn3r add dword [rbp - 8], 1 .l00p: mov eax, [OutsideLoop] cmp dword [rbp-8], eax jle .t0p .d0n3: mov eax,0 leave ret Compile/link: nasm -f elf64 -o Break.o Break.asm gcc -o Break Break.o ``` [Answer] # Python, 130.0 Miliseconds ``` k=False c = q for i in range (int(c/2),int(c/1.7)): if k: break for x in range (int(c/2),int(c/1.7)): if i**2-x**2 == c: print i,x k=True break ``` [Answer] # Axiom, 0.02 sec ``` v(c)== local m if c rem 2=0 then m:INT:=c/2 if m rem 2~=0 then return [0,0] else return reverse sort [(c/4)-1,(c/4)+1] reverse sort [1+(c-1)/2, (c-1)/2] f()==for i in [6,17,489,1270453,92,3343,74721,3920] repeat output[i, v(i)] (4) -> f() [6,[0,0]] [17,[8,9]] [489,[244,245]] [1270453,[635226,635227]] [92,[22,24]] [3343,[1671,1672]] [74721,[37360,37361]] [3920,[979,981]] Type: Void Time: 0.02 (EV) = 0.02 sec ``` When integer equation b^2-a^2=c is not soluble in N+{0} return [0,0] one has to note there is no loop few remender and division so it is O(1) ``` -> v(6),v(17),v(489),v(1270453),v(92),v(3343),v(74721),v(3920) Compiling function v with type PositiveInteger -> List Fraction Integer [[0,0], [9,8], [245,244], [635227,635226], [24,22], [1672,1671], [37361,37360], [981,979]] ``` add some test ``` (13) -> r:=[6,17,489,1270453,92,3343,74721,3920,613352373758390083167447227749,5 82316870718762711394729885483949672964468220019,97658628223769028234818028188353 8549090329] (13) [6, 17, 489, 1270453, 92, 3343, 74721, 3920, 613352373758390083167447227749, 582316870718762711394729885483949672964468220019, 976586282237690282348180281883538549090329] Type: List PositiveInteger (14) -> a:=[v(i) for i in r] (14) [[0,0], [9,8], [245,244], [635227,635226], [24,22], [1672,1671], [37361,37360], [981,979], [306676186879195041583723613875,306676186879195041583723613874], [291158435359381355697364942741974836482234110010, 291158435359381355697364942741974836482234110009] , [488293141118845141174090140941769274545165, 488293141118845141174090140941769274545164] ] Type: List List Fraction Integer (15) -> [a.i.1^2-a.i.2^2-r.i for i in 1..#a] (15) [- 6,0,0,0,0,0,0,0,0,0,0] Type: List Fraction Integer ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/97013/edit). Closed 7 years ago. [Improve this question](/posts/97013/edit) Your task is to generate a random digit following these steps: First, generate 10 random digits to make a binary number, 50% 0, and 50% 1: ``` 010011001 ``` If it is all zeros, generate a new one. Convert this to decimal: ``` 153 ``` For each digit, write that amount of alternating 0s and 1s (first digit = 1s, second digit = 0s, third digit = 1s, etc.): ``` 100000111 ``` Convert this to decimal: ``` 263 ``` Take the middle digit (If there is an even number of digits, take the left middle) ``` 6 ``` Remember, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the smallest number of bytes wins. [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 19 bytes ``` To<L.RvTNèy×}JC2䬤 ``` [Try it online!](http://05ab1e.tryitonline.net/#code=VG88TC5SdlROw6h5w5d9SkMyw6TCrMKk&input=) **Explanation** `153` used as example ``` To<L # [1 ... 2^10-1] # STACK: [1 ... 1023] .R # take random number from range # STACK: 153 v } # for each digit TNè # use the digits index in the number to index into 10 y× # repeat the number that many times # STACK: 1,00000,111 J # join to string # STACK: 100000111 C # convert to decimal # STACK: 263 2ä # split in 2 # STACK: [26,3] ¬¤ # take the last digits of the first part # OUTPUT: 6 ``` [Answer] # Pyth, ~~23~~ 22 bytes *1 byte thanks to @Jakube (swap `r` operands).* ``` ehc2`ir9,R=!ZjOS1023T2 ``` [Try it online.](http://pyth.herokuapp.com/?code=ehc2%60ir9%2CR%3D%21ZjOS1023T2&test_suite=1&debug=0) > > First, generate 10 random digits to make a binary number, 50% 0, and 50% 1. > > If it is all zeros, generate a new one. > > Convert this to decimal. > > > Generate a number between 1 and 1023. `OS1023` in Pyth. Then get its digits: `j`…`T`. > > For each digit, write that amount of alternating 0s and 1s (first digit = 1s, second digit = 0s, third digit = 1s, etc.). > > > Pair each digit with an alternating `True` or `False`: `,R=!Z`. The alternating booleans come from `=!Z`, or `Z = not Z` where `Z` starts as 0. Then run-length decode: `r`…`9`. > > Convert this to decimal. > > > Parse integer as binary: `i`…`2`. > > Take the middle digit (If there is an even number of digits, take the left middle). > > > Take the string representation: ```. Split it in two, with the possible middle character going to the left: `c2`. Take the first half's last character: `eh`. [Answer] # Perl, ~~62~~ ~~61~~ ~~55~~ 53 bytes Get the digit distribution through a lookup table. Implementing the original algorithm is about 15 bytes longer. ``` perl -E 'say-(map+(--$n)x$_,unpack"W*","\x90leJZaEC_")[rand 1023]' ``` Just the code: ``` say-(map+(--$n)x$_,unpack"W*","\x90leJZaEC_")[rand 1023] ``` Works as shown,, but replace `\x90` by the literal byte to get the claimed score [Answer] # [Jelly](https://github.com/DennisMitchell/jelly) 17 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` ⁵Ḷx“ḶƇleJZaEC_‘µX ``` **[TryItOnline!](http://jelly.tryitonline.net/#code=4oG14bi2eOKAnOG4tsaHbGVKWmFFQ1_igJjCtVg&input=)** ### How? The distribution of the first step are [1,1023] with equal likelihood. Applying the transformation instructed for each of those numbers produces a distribution of: `{0: 178, 1: 144, 2: 108, 3: 101, 4: 74, 5: 90, 6: 97, 7: 69, 8: 67, 9: 95}` ``` ⁵Ḷx“ḶƇleJZaEC_‘µX - Main link: (niladic) ⁵ - literal 10 Ḷ - range -> [0,1,2,3,4,5,6,7,8,9] “ḶƇleJZaEC_‘ - code page indexes -> [178,144,108,101,74,90,97,69,67,95] x - repeat - > [178 zeros, 144 ones, 108 twos, ...] µ - monadic chain separation X - pick a random element ``` ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- This question does not appear to be about code golf or coding challenges within the scope defined in the [help center](https://codegolf.stackexchange.com/help/on-topic). Closed 7 years ago. [Improve this question](/posts/86930/edit) Your goal in this [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") is to pick a random character from a string. If a character appears X times, and there are Y characters, then the chance of that character being picked will be X/Y. ### Input The program takes a string as an input. ### Output Your program outputs a character. ### Examples * `xyz`: x, y, or z * `xxX`: x, x, or X * `}^€`: }, ^, or € * `xxx`: x * `0123456789`: random number, 0-9 [Answer] # [Pyth](https://github.com/isaacg1/pyth), 1 byte ``` O ``` [Try it online!](http://pyth.herokuapp.com/?code=O&input=%22xyz%22&debug=0) ### Explanation From the [definition](http://pyth.herokuapp.com/rev-doc.txt) of the operator `O`: ``` op. arg. func. O <col> Random element of A. ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 1 byte ``` X ``` [Try it online!](http://jelly.tryitonline.net/#code=WA&input=&args=J3h5eic) ### Explanation From the [definition](https://github.com/DennisMitchell/jelly/wiki/Atoms) of the operator `X`: > > Arity: 1 > > > Name: Random > > > Function: choose a random item from z if z is a list, or from 1 to z inclusive if z is a positive integer. If z = 0, return z. Error if z is negative or a decimal. > > > [Answer] # [CJam](https://sourceforge.net/projects/cjam/), 3 bytes ``` lmR ``` [Try it online!](http://cjam.tryitonline.net/#code=bG1S&input=eHl6) ``` lmR l read line mR random element ``` [Answer] # 05AB1E, 2 bytes ``` .R ``` from `Info.txt`: ``` .R = pop a push random_pick(a) ``` [Try it online!](http://05ab1e.tryitonline.net/#code=LlI&input=YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo&debug=on) [Answer] # C, 30 bytes This answer must run on a 32-bit platform and requires the GNU C library implementation. ``` f(s){return*(char*)strfry(s);} ``` The [`strfry`](http://www.gnu.org/software/libc/manual/html_node/strfry.html#strfry) function shuffles the characters in a string. We first shuffle the input string, then return the first character. [Answer] # [Actually](https://github.com/Mego/Seriously), 1 byte ``` J ``` [Try it online!](http://actually.tryitonline.net/#code=Sg&input=Inh5eiI) ### Explanation From the [definition](https://github.com/Mego/Seriously/blob/master/docs/commands.txt) of the operator `J`: > > `4A (J): pop a: push a random integer in [0,a) (randrange(a)); pop [a] or "a": push a random element from [a] or "a" (random.choice([a]|"a"))` > > > [Answer] # [J](http://www.jsoftware.com/), 5 bytes ``` ?@#{] ``` ## Usage ``` >> f =: ?@#{] >> f 'xyz' << x ``` ## Explanation This is a [fork](http://code.jsoftware.com/wiki/Vocabulary/fork), where `f` is `?@#`, `g` is `{`, and `h` is `]`. Therefore, `(?@#{])'xyz'`, when expanded, would become `((?@#)'xyz') ({) ((])'xyz')` The `(?@#)` is just a [composed function](http://code.jsoftware.com/wiki/Vocabulary/at), so `(?@#)'xyz'` expanded would become `?(#'xyz')`. `#'xyz'` gets the length of `'xyz'`, then `?` generates a random non-negative integer below the length. The `{` then takes the item at the corresponding index. [Answer] # Python 3.5 and Python 2.7, 26 bytes: ``` from random import*;choice ``` A function declaration. Name the function, and then call it like `print(<Function Name>(<String>))`. [Answer] # Java 8, 44 bytes ``` x->x.charAt((int)(Math.random()*x.length())) ``` [Try it online!](http://goo.gl/B1inQj) [Answer] # Javascript, 40 bytes ``` x=>x[Math.floor(x.length*Math.random())] ``` ``` f=x=>x[Math.floor(x.length*Math.random())] alert(f(prompt())) ``` [Answer] # [Perl 6](http://perl6.org), 11 bytes ``` *.comb.pick ``` ``` *.comb.roll ``` ### Explanation: * `*` starts the Whatever lambda * `.comb` splits the string into a list of grapheme clusters * `.roll`/`.pick` grabs a single element from the list at random ( so it is effectively a weighted roll ) ( There isn't a difference between `.pick` and `.roll` unless you give them an argument that is something other than `1` ) ### Usage: ``` say ( *.comb.pick )( 'xxX' ); # ⅔ chance of 「x」, ⅓ chance of 「X」 my &code = *.comb.pick; say code 'xyz'; # ⅓ chance of each of 「x」 「y」 or 「z」 say ('}^€:','0123456789').map: *.comb.pick; ``` [Answer] # q (4) Will return a random item from a list: ``` rand ``` ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- This site is for programming contests and challenges. **General programming questions** are off-topic here. You may be able to get help on [Stack Overflow](http://stackoverflow.com/about). Closed 8 years ago. [Improve this question](/posts/51722/edit) So, My friend has come up with this interestng question, that is, given two numbers `x` and `y` deciding whether their difference: `x-y`is 0 or less without using any conditionals. The code should return 0 if they are 0 or less, or the result of the subtraction otherwise. My attempt (In Pseudo-Java): ``` try { Math.log(x-y); } catch(Math.Error e) { return 0; } return x-y; ``` However, I have a feeling that Java exception handling or log method may use conditionals at some point, which in a way would be cheating. Thoughts? :D [Answer] Use something like this, assuming the integer type is signed and has 32 bits: ``` ~((x-y) >> 31) & (x - y) ``` this shifts the sign bit of the difference right by 31 places, generating either 0 if x - y is positive or -1 if the result is negative. This inverted is anded with x - y to get 0 if x - y is negative, x - y otherwise. [Answer] There is a common misconception that comparison operators (e.g., `>` or `<`) somehow involve conditionals. For most if not all architectures, this is not true. On x86, [CMP](https://en.wikibooks.org/wiki/X86_Assembly/Control_Flow#Comparison_Instructions) sets the sign flag simply to most significant bit of the difference of `x` and `y`, so no conditionals are involved. In C, Python and many other languages (but, notably, not Java), you can use ``` (x > y) * (x - y) ``` which will be **x - y = 1 \* (x - y)** if **x > y** and **0 = 0 \* (x - y)** if **x ≤ y**. ]
[Question] [ The shortest C# code that generates an uncatchable ExecutionEngineException wins. You are not allowed to call FailFast directly or indirectly. [Answer] # C# - 73 ``` ThreadPool.QueueUserWorkItem(_=>{throw new ExecutionEngineException();}); ``` Generates an `ExecutionEngineException` inside of a thread, so it can't be caught. User [CSharpie](https://codegolf.stackexchange.com/users/22846/) helped me shorten `delegate` to `_=>`. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/17844/edit). Closed 9 years ago. [Improve this question](/posts/17844/edit) Write a code that will display the remainder of a division. Code with shortest byte wins. # Rules: * No arithmetic operation whatsoever should be in your code * No use of functions or methods * If you are using a function or method, it has to be written by you also # Samples: ``` Sample1: 9/3 Result1: 0 ``` ``` Sample2: 7/2 Result2: 1 ``` [Answer] ## J (23) ``` f=:4 :'##~,-.(-y)>\x#1' ``` e.g. ``` f=:4 :'##~,-.(-y)>\x#1' 9 f 3 0 7 f 2 1 ``` How it works: * `x#1`: make a list of `1`s as long as the left argument (`x`) * `(-y)>\`: divide the list into a `y`-row (right arg) matrix, padding with zeroes. * `-.`: negate the list (so the padding is `1`) * `,`: flatten the matrix * `#~`: replicate each number by itself (so all the zeroes disappear and all the ones remain) * `#`: count how long the list is now. [Answer] # CMD - 48 chars ``` start "" "http://google.com/search?q=%1 %%25 %2" ``` This program leverages the power of the mighty Google to calculate the result. Very rule bendy... [Answer] ## Perl, 46 chars The challenge is kind of vague, but if string manipulation and regexps are allowed, this should work: ``` ($_,$x)=map$"x$_,split"/",<>;s/$x//g;say y///c ``` This code reads a line of the form `7/3` from stdin, and outputs the remainder of the division (in this case `1`). Needs Perl 5.10+ and the `-M5.010` (or `-E`) switch for the `say` feature. [Answer] # PHP, 38 chars ``` function m($a,$b){return fmod($a,$b);} ``` [Answer] # Python 2.7 - 67 chars ``` n,d=raw_input().split('/') d=-int(d) print range(int(n))[d::d][-1] ``` Old answer 87: Takes a string input and aside from converting it to numbers does no numeric manipulation. The asterisk *looks* like a multiplication sign, but its actually repeated string concatenation ;) ``` n,d=raw_input().split('/') x="."*int(n) d=int(d) while len(x)>d: x=x[d:] print len(x) ``` ]
[Question] [ You are given an array of strings , you have to construct a single array containing all of them so that the same array of strings can be reconstructed from the large array. The strings may contain any ASCII character. How to determine length of the single large array? Example= let `a = ["asd";"dfg";"rew"]`. Problem is to combine them in a single string in such a way that it can reconstructed. How to figure out the size of the string which will store the concatenation ? [Answer] This was a very common in style in Apple ][ binaries. The high bit of the first character of each word was set. You know you can do this since ASCII was specifically mentioned and the high bit is *never* set for ASCII. This technique relies on strings that know their own length. We can assume this is the case, since the strings can "contain any ASCII" characters, so C style (null terminated) strings can't work. For your example, using Python ``` >>> a = ["asd", "dfg", "rew"] >>> ''.join(chr((ord(s[0])) | 128) + s[1:] for s in a) '\xe1sd\xe4fg\xf2ew' ``` converting back to the original list ``` >>> (''.join('\x80'+chr((ord(c)) & 127) if c>'\x7f' else c for c in '\xe1sd\xe4fg\xf2ew')).split('\x80')[1:] ['asd', 'dfg', 'rew'] ``` [Answer] # JavaScript, 6 This evaluates to a function. Works in Firefox. ``` uneval ``` ]
[Question] [ ## Challenge Implement a program that given three strings `a`, `b`, and `c`, substitutes all instances of the substring `b` in `a` with `c`. In other words, implement Ruby's `String#gsub` with strings instead of regexes (`a.gsub b, c`). ## Rules * Standard loopholes apply. * You may not use a builtin that performs this exact task. * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest answer wins. ## Dupe alert Not a duplicate of [this challenge](https://codegolf.stackexchange.com/questions/77719/subsequence-substitution). ## Test case ``` sub("test 1 test 1 test 1", "1", "what") --> "test what test what test what" ``` [Answer] ## JavaScript (ES6), 27 bytes ``` (a,b,c)=>a.split(b).join(c) ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` œṣj⁵ ``` [Try it online!](http://jelly.tryitonline.net/#code=xZPhuaNq4oG1&input=&args=ImNsYXNzaWMgYXNzYXNzaW5hdGlvbiI+ImFzcyI+ImJ1dHQi) ### How it works ``` œṣj⁵ Main link. Arguments: x, y, z (strings) œṣ Split x around occurrences of y. j⁵ Join the resulting string array with separator z. ``` [Answer] ## Haskell, 44 bytes ``` import Data.Lists (.splitOn).(.).intercalate ``` Argument order is `c` `b` `a`. Usage example: `( (.splitOn).(.).intercalate ) "ww" "ee" "aeedwwfeegeh"` -> `"awwdwwfwwgeh"`. Just some library functions to split the input string at every `b` and rejoin the parts with `c` in-between. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/15952/edit). Closed 10 years ago. [Improve this question](/posts/15952/edit) Your job is to write a program that determines if [Goldbach's conjecture](http://en.wikipedia.org/wiki/Goldbach%27s_conjecture) is true. The requirements are this: * If it is true: Print nothing. Run forever. * If it is false: Print the *first* counterexample. Halt. Shortest code wins, but show why it works. **Don't use any Prime built-in functions.** **Edit:** If you want, include another version that just adds a line that prints what even number you've found a solution to help explain your answer. (It should print 2,4,6,...). **Note:** If the conjecture get proven or disproven conclusively, then this will become irrelevant, and I might change it to some other similar [open problem](http://en.wikipedia.org/wiki/List_of_unsolved_problems_in_mathematics). [Answer] # Ruby, 94 ``` require'Prime' (4..1/0.0).step(2){|x|p=Prime.take x p x if p.product(p).all?{|y|y[0]+y[1]!=x}} ``` VERY VERY slow and inefficient. Finds all possible sums of primes less than the number, *and* recalculates the primes each iteration! :D Change `.all?` to `.any?` to see all non-counter-examples (?), which is all even numbers > 2 :P [Answer] ## Ruby, 85 (incomplete) I submit this as a partial answer to the question. The following program will run until it determines that Goldbach's conjecture is solved. It will then exit and print nothing. I have not yet coded the counterexample-printing in the case of falseness. ``` require'open-uri' while/Goldbach's conjecture/=~open('http://goo.gl/fuJLr1').read;end ``` Please enjoy. **:-)** [Answer] # Befunge - 0 Works up until the [4 \* 1018 iteration](http://en.m.wikipedia.org/wiki/Goldbach%27s_conjecture "Values for which the conjecture is known to be true") of the loop; after that, I am not sure: Okay, okay; here is a valid **Python** solution (236 chars): ``` import sys def p(a): for i in g(): if a%i!=0:return 0 return 1 def g():x=2;while 1:x+=1;yield x for i in g(): for x in g(): for y in g(): if y+x>i:break;if p(x)*p(y):x=i+1 if x-i:print i;sys.exit() if x>=i:break; ``` ]
[Question] [ **Closed**. This question needs to be more [focused](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Update the question so it focuses on one problem only by [editing this post](/posts/187338/edit). Closed 4 years ago. [Improve this question](/posts/187338/edit) Write a sorting algorithm for a list of integers that has an average performance of O(n^2). This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins. **RULES:** * The characters wasted for the declaration of the list are not counted (e.g. `var c = new List<int>() { 4, 2, 1, 3 };` is not counted) * Builtins to sort a list are not allowed. The best I did in C# is **82** ('c' is the list to be sorted): ``` var n=c.ToList();for(int i=0;i<n.Count;i++){int x=c.Min();c.Remove(x);n[i]=x;}c=n; ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes ``` ṭ@Ṣ¥/ ``` [Try it online!](https://tio.run/##y0rNyan8///hzrUOD3cuOrRU/////9HGOoY6JkBsqmOpY6RjFgsA "Jelly – Try It Online") Jelly's sort builtin `Ṣ` is too fast, so we had to slow it down a bit, via using it as part of a slower sorting algorithm rather than using it directly. (This algorithm doesn't sort the original list with a builtin, which is what the question banned at the time this answer was written.) ## Explanation ``` ṭ@Ṣ¥/ / One element at a time, ṭ@ append that element to the list so far ¥ and Ṣ sort the resulting list ``` Jelly's sort algorithm (which, behind the scenes, is Python's sort algorithm) is O(*n*) on lists that have only one element out of place, thus this implements an O(n²) sorting algorithm (specifically insertion sort). ]
[Question] [ From [the wikipedia](https://en.wikipedia.org/wiki/Net_neutrality): > > Net neutrality is the principle that Internet service providers and governments regulating the Internet should treat all data on the Internet the same, not discriminating or charging differentially by user, content, website, platform, application, type of attached equipment, or mode of communication. > > > Your task is to find if your internet connection is being throttled by your ISP or if the net is neutral. ## What you actually have to do Your program or function will be run twice. It needs to have some form of memory or storage between its two calls, like writing to a file, a `static` var in C++, setting a property on a function in JS, or just a global variable. The first time it is run, it must connect to google.com (a fairly popular site), and a *different* website with an [Alexa rank](http://www.alexa.com/siteinfo) of **greater than** 1 million, like [unlicense.org](http://www.alexa.com/siteinfo/unlicense.org). It must record the time it took google.com to respond\*, and the time it took the other website to respond\*. The second time it is run, it must do the above, and print a truthy value if these are both true: 1. The response time between google.com the first and second time varied by less than 5%. (Google paid ISP to not throttle) 2. The response time between the other site the first and second time **increased** by more than 50%. (Other site didn't) Shortest code wins! --- \* The time it to get the response body, headers, or just connect with the server. You choose. [Answer] # [Python 3](https://docs.python.org/3/) + requests, 185 bytes ``` lambda t=[]:t.append([g("http://google.com"),g("http://a.co")])or len(t)>1and abs(1-t[0][0]/t[1][0])<.05<1.5<t[1][1]/t[0][1] g=lambda s:get(s).elapsed.microseconds from requests import* ``` Unfortunately `requests` doesn't work with TIO, so I'll have to post a link on another service later. Uses <http://a.co> as the website with a [ranking greater than 1 million](http://www.alexa.com/siteinfo/a.co). ## 207 bytes, if time is required for the full body ``` f=lambda t=[]:t.append([g("http://google.com"),g("http://a.co")])or len(t)>1and abs(1-t[0][0]/t[1][0])<.05<1.5<t[1][1]/t[0][1] def g(s):t=time();get(s);return time()-t from requests import* from time import* ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/116592/edit). Closed 6 years ago. [Improve this question](/posts/116592/edit) Recently, I have found my reputation changing time to time. I would like to know my reputation changing real-time. --- # The job Given an id of a user on PPCG (ex.64499), Print the user's reputation every 10 seconds. You may ignore the daily quota. --- # Examples ``` 64499 3808 40695 ``` --- # Possible output format ``` 12345 12,345 ``` [Answer] # [Bash](https://www.gnu.org/software/bash/) + coreutils + w3m, ~~90~~ ~~71~~ ~~69~~ 67 bytes ``` watch -tn10 w3m codegolf.stackexchange.com/u/$1\|grep -Pom1 ^[,-9]+ ``` Takes the user ID as a command line argument and displays the reputation of the corresponding user (e.g., `135,249`) in the upper left corner of the terminal. ### Alternate version, 57 bytes, invalid? ``` watch -tn10 w3m codegolf.stackexchange.com/u/$1\|sed 44!d ``` This displays `135,249 reputation` instead of `135,249`. ]
[Question] [ **This question already has answers here**: [The alphabet in programming languages](/questions/2078/the-alphabet-in-programming-languages) (156 answers) Closed 7 years ago. The challenge: Write a script to print the alphabet, but you can't use any ASCII strings in your program. Unicode escape characters are allowed (if thats what you call them). External libraries are allowed, as long as a link to the documentation is provided, and an online example if possible. As this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the answer with the shortest byte count will win! [Answer] ## [Neoscript](https://github.com/tuxcrafting/neoscript), 27 bytes ``` {|65:[]:90:map(chr):fuse()} ``` Lambda returning the alphabet. [Answer] # [Silicon](http://github.com/m654z/Silicon), 1 byte ``` A ``` `A` is preinitialized to the alphabet. Output is implicit. ]
[Question] [ **This question already has answers here**: [1/N probability](/questions/66922/1-n-probability) (49 answers) Closed 8 years ago. If you're not familiar, [Diceware](https://en.wikipedia.org/wiki/Diceware) is a method for creating passwords using an ordinary die from a pair of dice as a hardware random number generator. For the sake of fun, let's ignore anything about the security of computer's random number generators. Write a function or program that prints or returns a single five-character string containing a random selection of the numbers 1 through 6. These should be chosen with equal probability. Example valid outputs: ``` 21321 14654 53552 63641 ``` No standard loopholes! This is code-golf, so shortest code in bytes wins. [Answer] # Dyalog APL, 7 bytes ``` 10⊥?5⍴6 ``` Try it online on [TryAPL](http://tryapl.org/?a=10%u22A5%3F5%u23746&run). ### How it works ``` 5⍴6 Yield (6 6 6 6) ? Roll; turn each 6 into a random integer between 1 and 6. 10⊥ Decode with base 10. ``` [Answer] # Julia, 24 bytes ``` print(join(rand(1:6,5))) ``` We use `rand` to get an array of length five consisting of elements randomly chosen from the range 1:6. We join it into a string using `join` then print it to STDOUT using `print`. [Answer] ## J, 11 bytes ``` a.{~49+?5$6 ``` Explanation: ``` 5$6 NB. repeat 6 five times output: 6 6 6 6 6 ?5$6 NB. 5 random integers < 6 output: 4 5 1 0 2 49+?5$6 NB. add 49 ('1') to them output: 53 54 50 49 51 a.{~49+?5$6 NB. convert them to ASCII output: 56213 ``` [Answer] # Pyth, ~~9~~ 8 bytes ``` jkO^S6 5 ``` [Try it online.](http://pyth.herokuapp.com/?code=jkO%5ES6+5&debug=0) Get list of numbers 1 to 6, Cartesian 5th power, pick random element, join by empty string. [Answer] ## CJam, 8 bytes ``` {6mr)}5* ``` [Test it here.](http://cjam.aditsu.net/#code=%7B6mr)%7D5*) ### Explanation ``` { e# Run this block 5 times. 6mr e# Get a random integer in [0,5] with uniform distribution. ) e# Increment. }5* ``` [Answer] # Mathematica, 36 bytes ``` ""<>ToString/@{1,6}~RandomInteger~5& ``` *cough cough* string formatting *cough cough* [Answer] # MATLAB / Octave, 12 bytes ``` [49+6*rand(1,6),''] ans = 153361 ``` `rand(x,y)` creates a random array with dimensions `(x-by-y)` with numbers between `0` and `1`. Multiply this by 6 to get values between 0 and 6. Add `49` to get a value `49 < n < 55` (the random number will never be exactly 0 or 1). `[...,'']` converts this to strings with the floored values of n (integers `[49 54]` corresponding to `[1 6]` in ASCII. [Answer] # [TeaScript](http://github.com/vihanb/teascript), 11 bytes ``` r6)ΣN6))j(u ``` [Try it online](http://vihan.org/p/TeaScript/#?code=%22r6)%CE%A3N6))j(u%22&inputs=%5B%22%22%5D&opts=%7B%22int%22:false,%22ar%22:false,%22debug%22:true%7D) ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win. Closed 9 years ago. [Improve this question](/posts/41776/edit) A perfect square is a number that is the square of an integer. However, let's define something called a **Magical Square**, which is a perfect square with the following restriction: The perfect square must be the sum of the numbers 1...N for some natural number N. Write a program that calculates the first X magical squares: The first magical square is 1 (not 0, since N >= 1). The values of X are: 1 <= X <= 15. The program should be efficient and your score is the time taken to calculate the magical squares in seconds. The winner is the program that runs in the least amount of time. Please also include the generated numbers. You can't hard-code the values, or read them from a file, etc. They *MUST* be calculated by the program. Some examples: 1, 36, 1225, ... [Answer] # CJam, 1 ms ``` UXD{_34*2$m2+}*]1>N* ``` This uses the following [known recurrence relation](http://en.wikipedia.org/wiki/Square_triangular_number#Recurrence_relations): ``` N[k] = 34 * N[k-1] - N[k-2] + 2 ``` ### Timing/Output ``` $ cjam <(echo 'es:T; UXD{_34*2$m2+}*]1>N* esT-`p'); echo "1" 1 36 1225 41616 1413721 48024900 1631432881 55420693056 1882672131025 63955431761796 2172602007770041 73804512832419600 2507180834294496361 85170343853180456676 ``` [Answer] # Java 7, 467945 ns = .467945 ms Using sudo's formula: ``` import java.math.BigInteger; import java.io.*; public class SquareTriangle{ public static void main(String[] args){ PrintStream out = new PrintStream(System.out, false); long startTime = System.nanoTime(); for (int i = 0; i < 100000; i++){ BigInteger a = 0; BigInteger b = 1; BigInteger c; for (int i = 0; i < 15; i++){ out.println(b); c = b; b = c.multiply(BigInteger.valueOf(34)).subtract(a) .add(BigInteger.valueOf(2)); a = c; } } long endTime = System.nanoTime(); out.flush(); System.out.println((endTime - startTime)/100000 + " ns"); } } ``` Takes an average of 467945 ns per run on my very slow computer. Here are the numbers: ``` 1 36 1225 41616 1413721 48024900 1631432881 55420693056 1882672131025 63955431761796 2172602007770041 73804512832419600 2507180834294496361 85170343853180456676 2893284510173841030625 ``` **Edit:** Now flushes the output stream *after* it is timed, not during. ]
[Question] [ **This question already has answers here**: [Code golf edit distance 2](/questions/202974/code-golf-edit-distance-2) (4 answers) Closed 2 years ago. The **edit distance** between two strings is the minimum number of single character insertions, deletions and substitutions needed to transform one string into the other. This task is simply to write code that determines if two strings have edit distance at most 3 from each other. The twist is that your code must run in **linear time**. That is if the sum of the lengths of the two strings is `n` then your code should run in `O(n)` time. # Example of strings with edit distance 2. ``` elephant elepanto elephant elephapntv elephant elephapntt elephant lephapnt elephant blemphant elephant lmphant elephant velepphant ``` # Example of strings with edit distance 3. ``` elephant eletlapt elephant eletpaet elephant hephtant elephant leehanp elephant eelhethant ``` # Examples where the edit distance is more than 3. The last number in each row is the edit distance. ``` elephant leowan 4 elephant leowanb 4 elephant mleowanb 4 elephant leowanb 4 elephant leolanb 4 elephant lgeolanb 5 elephant lgeodanb 5 elephant lgeodawb 6 elephant mgeodawb 6 elephant mgeodawb 6 elephant mgeodawm 6 elephant mygeodawm 7 elephant myeodawm 6 elephant myeodapwm 7 elephant myeoapwm 7 elephant myoapwm 8 ``` You can assume the input strings have only lower case ASCII letters (a-z). Your code should output something Truthy if the edit distance is at most 3 and Falsey otherwise. If you are not sure if your code is linear time, try timing it with pairs of strings of increasing length where the first is all 0s and the second string is two shorter with one of the 0s changed to a 1. These all have edit distance 3. This is not a good test of correctness of course but a quadratic time solution will timeout for strings of length 100,000 or more where a linear time solution should still be fast. (This question is based on this [older one](https://codegolf.stackexchange.com/questions/202974/code-golf-edit-distance-2)) [Answer] # [Haskell](https://www.haskell.org/), ~~93~~ 90 bytes ``` x%y=[0,0,0]>=x#y u@(a:b)#v@(c:d)|a==c=b#d|k<-zipWith(+)=0:k(d#u)(k(b#v)$b#d) a#b=a++b>>[0] ``` [Try it online!](https://tio.run/##fZBda4MwFIbv8yskVkxwLfZWFikMdjWYsIsNxIsTk9bgJ/WjdfS3z@lcqa6yBHKS533hvCcRlLFMkq47Gy3z7Yd@By476y2qdwQcTvVmR0JH0AswFjKui0v8uP5UxbuqImJRZjsxEXpNSUy43tBV76AIdM7Asrjr@nbQpZC1ryXzt5vN1v5ZgeviHCOUgsqYyJGmFXX1Vh1fMg17UJaydPAAjyqrVhh4KLCB@1NOKF@kMpFFBFnVK81wHx@LepL@J8r8NBd/U8ihTGiP4A8ajXBDxOSmY4amM/4ENcaKZnM/g0pmY9@nURP1vu/Uf5C5gBNfiGCKawzLwnt8zdJ9hfsEDmW3/njyvG8 "Haskell – Try It Online") This is taken from [this previous answer of mine](https://codegolf.stackexchange.com/a/202980) with basically no modification. ## How it works: We start by looking at a naive version of edit distance: ``` lDistance :: ( Eq a ) => [a] -> [a] -> Int lDistance [] t = length t -- If s is empty the distance is the number of characters in t lDistance s [] = length s -- If t is empty the distance is the number of characters in s lDistance (a:s') (b:t') = if a == b then lDistance s' t' -- If the first characters are the same they can be ignored else 1 + minimum -- Otherwise try all three possible actions and select the best one [ lDistance (a:s') t' -- Character is inserted (b inserted) , lDistance s' (b:t') -- Character is deleted (a deleted) , lDistance s' t' -- Character is replaced (a replaced with b) ] ``` (I wrote this program for Wikipedia [here](https://en.wikipedia.org/wiki/Levenshtein_distance#Recursive)) This is pretty bad because every time it finds a discrepancy between the two strings it branches into 3 options (insert, delete or replace) so in the worst case it will have the time complexity of \$O(3^n)\$. The thing to notice though is that whenever we branch we increase the total distance by 1. So if we are on a particular search path that has already branched 3 times and we would branch another time. So we can just stop there and say return `False` for this branch since it can never find the result. Now there is a hard limit on the number of branches that can occur, \$3^3 = 27\$, so our computation is \$O(n)\$. In general this strategy has a complexity of \$O(3^mn)\$ where \$m\$ is the limiting distance. [Answer] # [Prolog (SWI)](http://www.swi-prolog.org), 120 bytes ``` _+[]+[]. N+[A|B]+[A|C]:-!,N+B+C. N+[_|B]+C:-N>0,N-1+B+C. N+B+[_|C]:-N>0,N-1+B+C. N+[_|B]+[_|C]:-N>0,N-1+B+C. B*C:-3+B+C. ``` [Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/P147OhaI9Lj8tKMda5xiQaRzrJWuoo6ftpO2M1g8HiTubKXrZ2eg46drCBN3AsmA1KKJQ9Rjk3PSAppiDGb/t9JViDbSgUFDHaNYrWhDHRCE8fX@cwEA "Prolog (SWI) – Try It Online") This is the same basic algorithm as [my Haskell answer](https://codegolf.stackexchange.com/a/233905/56656), but it implements it using Prolog's built in search. We have to add a cut on the second case ``` N+[A|B]+[A|C]:-!,N+B+C. ``` If we don't the will try to branch even when the first two characters are the same. This will cause exponential branching with respect to the length of the string. The cut here ensures that if the first two characters are the same we don't backtrack. The Haskell answer doesn't have this issue because Haskell will eagerly follow the first path of execution. [Answer] # [Prolog (SWI)](http://www.swi-prolog.org), 109 bytes ``` _+[]+[]. N+[A|B]+[A|C]:-!,N+B+C. \N+B+C:-B=[_|X],N+X+C;C=[_|Y],N+B+Y;B=[_|X],C=[_|Y],N+X+Y. B*C:- \ \ \a+B+C. ``` [Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/P147OhaI9Lj8tKMda5xiQaRzrJWuoo6ftpO2sx5XDJi20nWyjY6viYgFCkdoO1s7g3iRsWBFkdYwOYRohHakHpeTFlCfQgwIJoIN@/8/2kgHBg11jGK1og11QBDG1@PiAgA "Prolog (SWI) – Try It Online") This is a golf of [Wheat Wizard's answer](https://codegolf.stackexchange.com/a/235192/20059). The key modification I made was that instead of using Prolog's built in numbers and arithmetic to keep track of the the current edit distance, I instead used nested compound terms, built using the unary operator `\`. Thus instead of having to check if `N` is greater than zero and then use subtraction, I can roll both of those steps into a single pattern match by matching the current remaining edit distance to `\N`. This left me with the following program (111 bytes): ``` _+[]+[]. N+[A|B]+[A|C]:-!,N+B+C. \N+[_|B]+C:-N+B+C. \N+B+[_|C]:-N+B+C. \N+[_|B]+[_|C]:-N+B+C. B*C:- \ \ \a+B+C. ``` I managed to save a couple more bytes by merging the latter three rules for the `+` predicate into a single rule, as described [here](https://codegolf.stackexchange.com/a/67032/20059). ]
[Question] [ **This question already has answers here**: [Determine the depth of an array](/questions/71476/determine-the-depth-of-an-array) (53 answers) Closed 7 years ago. Find out the dimension of a simple nested list: ``` [] -> 1 [[]] -> 2 [[[]]] -> 3 ... ``` List taken as input, dimension as output. No counting length of strings - list manipulation and loops only. i.e. no getting the length of the input and dividing by 2. Any language is permitted. Get golfing! [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 2 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` ŒḊ ``` **[TryItOnline](http://jelly.tryitonline.net/#code=xZLhuIo&input=&args=W1tbW11dXV0)** It's a single atom, the depth monad. [Answer] # Brain-Flak, ~~44~~ ~~36~~ ~~32~~ 26 + 3 = 29 bytes [Try it online](http://brain-flak.tryitonline.net/#code=KFtdKSh7PCh7fVsoKSgpXSk-KCl9e308Pik&input=W1tbW11dXV0&args=LWE&debug=on) ``` ([])({<({}[()()])>()}{}<>) ``` +3 bytes from the `-a` flag. ## Explanation ``` ([]) #Push the stack height {<({}[()()])>()}{} #For loop decrement by 2 ( <>) #Push number of runs to the offstack ``` [Answer] # Retina, ~~2~~ 1 byte~~s~~ ``` ] ``` Just Regex. One byte to Martin Ender. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/187752/edit). Closed 4 years ago. [Improve this question](/posts/187752/edit) This challenge is quite simple to conceptualise, but likely a lot harder to execute. In this challenge, the program will have to detect the number N of its characters that have been randomly changed (at least half of the program will always remain). Then, it will have to output the Nth prime number. A 'change' can only be the replacement of a character. You can assume it will always be replaced by something within your own language's alphabet. # Rules * Only half of your program (rounded down to fewer changes, if necessary) will ever be hit by radiation. * Standard output formats apply. * The prime number must always be correct. Regarding the 'Nth' prime, N can be 1- or 0-indexed. * 1 is not a prime number! * If nothing (or only 1 character, if you choose to make N 1-indexed) is changed, output 0/null/any falsey value. * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins. * Standard loopholes apply. [Answer] # [Unary](https://esolangs.org/wiki/Unary), 0 bytes Outputs nothing as a falsey value for no change. Note that Unary only has one symbol in its alphabet, so any program outputting a falsey value would be valid, since there are no possible changes to be made. [Answer] # GolfScript, ~~1~~ 0 bytes Rule 1 + Rule 5. Thanks to @Jo King for mentioning that empty string is falsey value. [Try it online!](https://tio.run/##S8/PSStOLsosKPkPBAA "GolfScript – Try It Online") # GolfScript, 1 byte 0-indexed version which actually outputs a prime number (0th). It is also JS and Python solution if we run it in interactive shell. ``` 2 ``` [Try it online!](https://tio.run/##S8/PSStOLsosKPn/3@j/fwA "GolfScript – Try It Online") [Answer] # Brainfuck, 1 byte Outputs zero byte. Zero byte is falsey in Brainfuck. ``` . ``` [Try it online!](https://tio.run/##SypKzMxLK03O/v9f7/9/AA "brainfuck – Try It Online") ]
[Question] [ John has made an array of numbers which are important to him. Unfortunately, John lost the array. Luckily, he knows some details about the array. You will receive each of these sets of details (which are lists of 3 integers). Each detail is the sum of a section of the list. Each has the numbers `a`, the starting index of the sum, `b`, the ending index of the array's sum, and `c`, which is 1 if the sum is positive and -1 if the sum is negative. Your job is to find an array that matches the given details and to print them out, or to print `-1` if no such array exists. Example Input: (0-indexed and inclusive) ``` [0, 1, 1] [1, 2, -1] ``` Output: ``` [-1, 2, -3] ``` The details here require that the sum from `0` to `1` is positive, and from `1` to `2` is negative. You can output any array that matches. You can take the input in any reasonable format. Whoever writes the shortest program wins! This is a code golf problem. [Answer] # Perl, 101 bytes Includes `+7` for `-0pF\n` `lost_array.pl`: ``` #!/usr/bin/perl -0pF\n $_="@G"x!grep{$a=!/ \d+ /;grep{$_+=$`if$`^$a<=>0}grep{$a+=$_;1}@G[$&+0..$']}@F until$n{"@G"}++ ``` Input triples on seperate lines on STDIN in the order `sign from to` Outputs either a valid assignment or nothing. `don't care` positions in the output array are left empty (noticable as consecutive spaces). So for example: ``` (echo 1 0 1; echo -1 1 2) | lost_array.pl; echo ``` outputs ``` 1 0 -1 ``` This is way too long and I'm not even sure it is correct, but it's the best I could immediately think of. For all given ranges it calculates the sum and if the sign isn't right adds the sign to all values in the range to make the sum better. It stops as soon as it detects that the array of values is repeated. If no value update was done during the last loop this is a solution and it is printed. Otherwise no solution is possible and nothing gets printed ]
[Question] [ **This question already has answers here**: [What do you get when you multiply 6 by 9? (42)](/questions/124242/what-do-you-get-when-you-multiply-6-by-9-42) (87 answers) Closed 6 years ago. Thank you for you help fixing my [calculator](https://codegolf.stackexchange.com/q/124242/61474)'s multiply function, but I've found another critical error all calculators seem to share. None of them understand that 2+2=fish. So now I need code to properly add 2 numbers. Challenge * Take 2 numbers as input (Type doesn't matter, but only 2 items will be passed. This is addition, so order obviously doesn't matter.) * Output sum of both numbers except if they are both 2, then output `fish` (case insensitive) + PS. I never was really good with counting, so I think only Integers from 0 to 99 are real numbers (Type used doesn't matter) * Fewest bytes per language wins! (NOTE: The key difference between this challenge and the previous, is that order is now irrelevant, and the return type is not restricted to int, which has major implications for type safe languages like Java. You can also see in the answers already here that in non type strict languages like Python, this rule set can dramatically change the answer code.) [Answer] # [Python 2](https://docs.python.org/2/), 33 bytes ``` lambda x,y:x==y==2and"fish"or x+y ``` [Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaFCp9Kqwta20tbWKDEvRSktszhDKb9IoUK78n9BUWZeiUaahpGOkaYmF4xnqGOuqfkfAA) [Answer] # [C (gcc)](https://gcc.gnu.org/), 30 bytes ``` f(x,y){x=x^y&&x^2?x+y:"fish";} ``` [Try it online!](https://tio.run/##S9ZNT07@/z9No0KnUrO6wrYirlJNrSLOyL5Cu9JKKS2zOEPJuvZ/bmJmnoYmVzWXAhAUFGXmlaRpKBkpaCsYK9gqqKbE5CnpKKRpGBroGGlqWqMoMgcqMrRAVmWuY2iBrgpklBFIUTFIUZqGEcSg2v//ktNyEtOL/@vm5AIA "C (gcc) – Try It Online") ]
[Question] [ I work from Monday to Friday. I start my day at `8:12` and have lunch from `12:00` to `12:42`. My workday ends at `16:30`. If you are wondering why 8:12 and 12:42: * `8:00` is the goal, but I never actually make it * `12:42` because I take 45 minute breaks, but this works better for the challenge spec --- ### Challenge Write a function or full program that returns the smallest fraction of time I have worked and still need to work for the current week. The interval you must use is 6 min. Each day has 76 six-minute intervals --- ### Examples ``` Monday 02:00 -> 0/1 Monday 08:24 -> 1/190 Monday 18:00 -> 1/5 Saturday xx:xx -> 1/1 Monday 08:17 -> 0/1 Monday 08:18 - Monday 08:23 -> 1/380 ``` --- ### Scoring Shortest code win but golfing languages get a \*3 multiplier. * Pyth * CJam * GolfScript (note to self: add more) --- **Edit:** I've lowered the modifier, but I will not remove it. Some languages have some overhead like variable declaration and other long keywords; `function` ,`return`, etc. I don't want to discourage someone from writing the skeleton of a method in their chosen language because it's longer than a complete CJam answer. [Answer] # C++: 204 bytes **g++ 4.9.2** ``` int f(char*a){int d=380,n=*a-'M'?*a-'W'?*a-'F'?*a-'S'?a[1]-'u'?3:1:5:4:2:0,m,h;sscanf(a,"%*s%d:%d",&h,&m);h=(m=h*10+m/6-82)<38?m:m>83?76:m-7;n=min(d,n*76+max(h,0));m=__gcd(n,d);printf("%d/%d\n",n/m,d/m);} ``` [Live demo](http://ideone.com/OpbxUb) Same as old answer, just replaced 5 ternary conditions of form `a==b?c:d` with `a-b?d:c` to save 1 byte each condition. Rest of the explanation remains same. --- Old answer: # ~~C++: 210 bytes~~ ~~int f(char\*a){int d=380, n=\*a=='M'?0:\*a=='W'?2:\*a=='F'?4:\*a=='S'?5:a[1]=='u'?1:3,m,h;sscanf(a,"%\*s%d:%d",&h,&m);h=(m=h\*10+m/6-82)83?76:m-7;n=min(d,n\*76+max(h,0));m=\_\_gcd(n,d);printf("%d/%d\n",n/m,d/m);}~~ [~~Live demo~~](http://ideone.com/gAuqc3) # Explanations ``` int f(char* a) { // Function name. Returning int instead of void to save one char int d=380; // denominator int n= *a == 'M' ? // Number of days 0 : // Monday *a == 'W' ? 2 : // Wednesday *a == 'F' ? 4 : // Friday *a == 'S' ? 5 : // Saturday or Sunday a[1] == 'u' ? 1 : // Tuesday 3; // Thurdays int m, h; // Minutes and hours sscanf(a, "%*s%d:%d", &h, &m); // %*s - Skip day, %d:%d - Read hour and min h= ( m=h*10+m/6-82 // Calculate (h * 60 + m) / 6 - (8 * 60 + 12) / 6 ) < 38 ? m // Before lunch : m>83 ? 76 // If it is past end of day 76) clamp to 76 :m-7; // After lunch, subtract lunch time n = min(d, // numerator (n) can not be more than denominator n * 76 + max(h,0) ); // Number of day * units (6 min) per day + units of current day (from time) clamped to 0 if negative m=__gcd(n, d); // Find gcd to get normalized form of rational number printf("%d/%d\n", n/m, d/m); // Print the result } // Function ends ``` [Answer] # Python - 195 bytes Very simple, uses fractions library for simplest terms. Had a Pyth solution, but the `*4.5` was too much. ``` from fractions import* z=raw_input() Q=input() n=("SMTWTF".index(z[0])-1if z[0]!='T'else"uh".index(z[1])*2+1)*76 Q=max(Q[0]*10+Q[1]/6-82,0) print Fraction(n+(min(Q, 38)if Q<45 else min(Q-7,76)),380) ``` Takes input in two lines, the time as a tuple, since no input format was specified. [Answer] ## PHP, 254 bytes This is just a port of my JavaScript answer. Due to PHP's odd behaviour with ternary operators, parentheses are necessary. ``` function z($a,$b){return$b?z($b,$a%$b):$a;}function f($q){preg_match('/(\w+) (\d+):(\d+)/',$q,$i);$t=$i[3]/6+$i[2]*10-82;$t=$i[0][0]=='S'?380:strpos('neduit',$i[1][2])*76+($t<0?0:($t>82?76:($t>45?$t-7:($t>38?38:$t))));$g=z($t,380);return$t/$g.'/'.(380/$g);} ``` [Answer] ## JavaScript (ES6), ~~201~~ 191 bytes ``` f=i=>{z=(a,b)=>b?z(b,a%b):a,i=/(\w+) (\d+):(\d+)/.exec(i),t=+i[3]/6+i[2]*10-82;t=i[0][0]=='S'?380:'neduit'.indexOf(i[1][2])*76+(t<0?0:t>82?76:t>45?t-7:t>38?38:t);g=z(t,380);return+t/g+'/'+380/g} ``` ### ECMAScript 5: ~~223~~ 214 bytes ``` function f(i){z=function(a,b){return!b?a:z(b,a%b)},i=/(\w+) (\d+):(\d+)/.exec(i),t=+i[3]/6+i[2]*10-82;t=i[0][0]=='S'?380:'neduit'.indexOf(i[1][2])*76+(t<0?0:t>82?76:t>45?t-7:t>38?38:t);g=z(t,380);return+t/g+'/'+380/g} ``` Ungolfed ``` function f(input) { var greatestCommonDivisor = function (a, b) { // From https://stackoverflow.com/a/17445304/404623 return !b ? a : greatestCommonDivisor(b, a % b); }; // Get input from string var input = /(\w+) (\d+):(\d+)/.exec(input); // Parse time relative to day var t = Number(input[3]) / 6 + Number(input[2]) * 10 - 82; var m, g, divisor; if (input[0][0] == 'S') { // Weekend - week is over m = 380; } else { if (t < 0) { // Before start of work day m = 0; } else if (t > 82) { // After end of work day m = 76; } else if (t > 45) { // After lunch m = t - 7; } else if (t > 38) { // During lunch m = 38; } else { m = t; } // Indices correspond to third letter of day of week m += 'neduit'.indexOf(input[1][2]) * 76; } // Find common divisor divisor = greatestCommonDivisor(m, 380); // Return value return m / divisor + '/' + 380 / divisor; } ``` ``` function f(i) { z = function(a, b) { return !b ? a : z(b, a % b) }, i = /(\w+) (\d+):(\d+)/.exec(i), t = +i[3] / 6 + i[2] * 10 - 82; t = i[0][0] == 'S' ? 380 : 'neduit'.indexOf(i[1][2]) * 76 + (t < 0 ? 0 : t > 82 ? 76 : t > 45 ? t - 7 : t > 38 ? 38 : t); g = z(t, 380); return t / g + '/' + 380 / g } ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'].forEach(function(d) { var str; for (var h = 8; h < 17; h++) { for (var m = 0; m < 60; m += 6) { str = d + ' ' + (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m); document.body.innerHTML += str + ' -> ' + f(str) + '<br>'; } } }); ``` Assumes that Sunday is the last day of the week. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/25274/edit). Closed 9 years ago. [Improve this question](/posts/25274/edit) Write a code in your favorite language which reduces words To **`first three characters`**. ``` Input : One word Output : First three letters ``` For example ``` INPUT : ProGramming OUTPUT : Pro INPUT : puZZles OUTPUT : puZ INPUT : BoWling OUTPUT : BoW ``` **`Output needs to be case sensitive`** **Rule-1** All statements should be meaningful and useful. For example the C++ snippet below surely increases the score but is unnecessary. **`The similar code snippets below is banned.`** ``` std::cout<<"abcabc"; std::cout<<"\b\b\b\b\b\b"; ``` **Rule-2** Do not use infinite add-subtract or multiplication-division (or any other kind of) infinite progressions to increase the score. For example **`The similar code snippets below is banned.`** ``` if(strcmp(str,"monday")==0) //The function strcmp() returns 0 if both //strings are same (including NULL character) cout<<110+1-1+1-1+1-1....inf //110 is ASCII value of 'm' ``` **Winner** Winner will be chosen on the basis of score (Most score wins) after 4 days from now. If there is a tie then the one who submitted the answer first is the winner [Answer] # Befunge 98, 6 bytes ``` ~~~,,, ``` Any other statements would be *meaningless and useless*. I could possibly do this though (**18 bytes**): ``` 3^,< @ w~^ 0 : ``` But everything but the `,` and the `~` are *meaningless and useless* because it could be done so much simpler. ]
[Question] [ **This question already has answers here**: [Obfuscated Hello World](/questions/307/obfuscated-hello-world) (145 answers) Closed 5 years ago. This challenge is pretty simple: you need to alert / print / show to the user the text "beep boop bop" (or "beep\nboop\nbop", with newlines), but it needs to be obfuscated. (where you couldn't see anything saying "beep", "boop", or "bop"). Points are calculated where your point value is in **characters** (**not** bytes) [Answer] Bash, 16 bytes ``` echo b{ee,oo,o}p ``` [Answer] # [Perl 6](https://github.com/nxadm/rakudo-pkg), 21 bytes ``` put <bee boo bo>X~'p' ``` [Try it online!](https://tio.run/##K0gtyjH7/7@gtETBJik1VSEpPx@I7SLq1AvU//8HAA "Perl 6 – Try It Online") Prints all the words on one line by joining all the prefixes with the last letter `p` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/176247/edit). Closed 5 years ago. [Improve this question](/posts/176247/edit) You have been given the charge to calculate the current balance as of the day that you perform the calculation for 330,000 individuals who worked for an average of 30 years spanning 300 years where the initial principal was `1` with an addition of `1` per day and interest rate set at `3%`. You initially tried to use online compound interest with additions calculators to compute the sum. But all 10 calculators you tried had different results due to rounding errors. You decide to compose your own code which will assist in completing your charge. ## Input Your task is write a function `f` which takes as input * *`p`* Principal. A positive integer or decimal reflecting initial deposit. * *`r`* Rate. A positive decimal reflecting the annual interest rate. * *`t`* Time. An positive integer reflecting years to compute the compounding interest with additions. * *`n`* Periods. A positive integer reflecting the number of periods per year to compound interest. * *`a`* Addition. A positive integer or decimal which will be added to the current principal at the end of each period. Any number of additions can be deposited during *`t`*; for example, `10` additions of `20` can be deposited in a single day, or no deposits can be made during a period. For this question *`a`* will be a constant value, to avoid confusing users who expect output to be a single, consistent value. ## Output The output can be an array of \$n\$ arrays of numbers, where each element is `[year, day, days, principal]` as follows: * *`year`* The year as a positive integer within *`t`* years. * *`doy`* (day of year): The day number within a year; \$0 \le\$ day \$\le 360\$ e.g. `days = 460` implies `year = 2` and `doy = 100$`. * *`days`* The number of days since the initial deposit *`p`* was made. * *`balance`* The current balance. Other acceptable output formats: * The above, but with elements of each array in a different (consistent) order; * List of comma or space-delimited strings; * The above, joined by newlines or tabs; * `JSON` string representation of an array of objects; * Spreadsheet; * Any other formats permitted by default. ## Important * Interest is compounded at the **end** of each period, which produces a new principal beginning at the next period. The addition, if any, is added to the new principal after interest is applied at the end of the period. * "Leap day" and "leap years" are irrelevant to the question. The requirement for this question is to use the constant banker's year consisting of `360` days. ## Example **Input** ``` p=1,r=0.03,t=1,n=12,a=10 ``` **Output** (truncated, see stacksnippet). You need not output the labels "year", "day", etc. ``` [ { "year": 1, "doy": 0, "days": 0, "balance": 1, "rate": 0.03, "addition": 0 }, { "year": 1, "doy": 30, "days": 30, "balance": 11.0025, "rate": 0.03, "addition": 10 },... { "year": 1, "doy": 180, "days": 180, "balance": 61.391346409181246, "rate": 0.03, "addition": 10 },... { "year": 1, "doy": 360, "days": 360, "balance": 122.69424361094278, "rate": 0.03, "addition": 10 } ] ``` ``` [ { "year": 1, "DOY": 0, "days": 0, "balance": 1, "rate": 0.03, "addition": 0 }, { "year": 1, "DOY": 30, "days": 30, "balance": 11.0025, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 60, "days": 60, "balance": 21.03000625, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 90, "days": 90, "balance": 31.082581265625, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 120, "days": 120, "balance": 41.160287718789064, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 150, "days": 150, "balance": 51.26318843808603, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 180, "days": 180, "balance": 61.391346409181246, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 210, "days": 210, "balance": 71.5448247752042, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 240, "days": 240, "balance": 81.72368683714221, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 270, "days": 270, "balance": 91.92799605423507, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 300, "days": 300, "balance": 102.15781604437065, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 330, "days": 330, "balance": 112.41321058448158, "rate": 0.03, "addition": 10 }, { "year": 1, "DOY": 360, "days": 360, "balance": 122.69424361094278, "rate": 0.03, "addition": 10 } ] ``` ## Formula You can use the formula at [Saving and Investing](http://www.math.fsu.edu/~blackw/mgf1107fa06/Saving.pdf) > > If **D** represents the amount of a regular deposit, **r** the annual > interest rate expressed as a decimal, **m** the number of equal > compounding period (in a year), and **t** time in years, then the > future value, **F**, of the account, is: > > > [![enter image description here](https://i.stack.imgur.com/UpJFw.png)](https://i.stack.imgur.com/UpJFw.png) > > > or any comparable formula which determines a future value that you decide or is available at the language that you use, for example the formulas located at * [Continually Compounded Interest + Addition to Principal](https://math.stackexchange.com/q/118616/138305) * [Compound Interest Formula adding annual contributions](https://math.stackexchange.com/q/1698578/138305) ## Winning criteria Shortest code in bytes. [Answer] ## Haskell, ~~115~~ 112 bytes ``` d=360 (r#t)n a=zipWith(\y x->(max(ceiling$y/d)1,until(<=d)(-d+)$y*d/n,y*d/n,x))[0..t*n].iterate(\x->x+(x*r)/n+a) ``` Function `#` takes the parameters in order r, t, n, a, p and returns a list of 4-tuples (year, day, days, principal). [Try it online!](https://tio.run/##JYzBasMwEAXv/YoH8WFly7bcQE91/yDnHJJSlko0S@2tUFSQ8/OuoJeZyzA3vn@HZdl3Px9f3BOlQzYKnh8Sz5JvdN1Q@jdaudBnkEX0q9lGbyb7q1kWep29od53ptlaP6r9ZzHm4oYht/o@SA6Jc6Br3ZSOSpvMqB2bfWVRzFg5nj4Qk2hGAzoYuMEdMWF6xuSqgb5H5MRrqCv8JF8pdySLbKEWbBFrtf8B "Haskell – Try It Online") ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/111032/edit). Closed 6 years ago. [Improve this question](/posts/111032/edit) ## Intro When you search in google, it always shows you a result with a sample text from the found webpage. For example if you search for "Madonna greatest vinyl", google will show you one line link, and below a short excerpt from that found webpage: **Madonna Greatest Hits Records, LPs, Vinyl and CDs** *Madonna* - *Greatest* Hits Volume 2, Madonna, Greatest Hits ... *vinyl* Is Fully Restored To As Near New Condition As Possible. Shipping & Multiple Order D.. ## Task Imagine yourself you work for google and you have to write a program/function which takes in: * a string containing many words (the webpage content) * list of searched words (at least 3) and returns the shortest excerpt of given string (webpage) containing all searched words. ### Example Given this webpage content: ``` This document describes Session Initiation Protocol (SIP), an application-layer control (signaling) protocol for creating, modifying, and terminating sessions with one or more participants. These sessions include Internet telephone calls, multimedia distribution, and multimedia conferences. ``` and these searched words: ``` calls, sessions, internet ``` the program should return: ``` sessions include Internet telephone calls ``` , as this is the shortest substring containing all 3 searched words. Note that one more substring contains these 3 words, it is "sessions with one or more participants. These sessions include Internet telephone calls", but it is longer, so it was discarded. ## Rules * If the string is empty, return empty string * If all searched words are not found in given string, return empty string * Search is ignoring letters case * At least 3 words need to be specified for searching * The returned string may contain the searched words in different order than specified ### Challenge Write the fastest code. It's for google, right? Remember that repeatable strings comparison is very expensive. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 13 bytes ``` Œévyl²l#åPiyq ``` Explanation: ``` Œé # Get substrings sorted by shortest first vyl # For each substring (in lowercase)... ²l# # Split the searched text (in lowercase)on spaces åP # Check if each word of the searched text is in the substring iyq # If so, print the substring and terminate the program ``` [Try it online!](https://tio.run/nexus/05ab1e#TU87TsNAEO05xXQmkonEMdIZJR1Ksdkd2yONZ5edMcjXyB0oaDkCEecya4cIuie9//x9vny8Tvz1yZf35vGJppd5PvSkEKIfBxSDgOoznVBhj6oUBXZCRs4W2ORo0UeG@/2u2dTgBFxKTH6lH9hNmMFHsbxolDpxTNJtIN2MbSyCjEUvXQ1DDNROK3QSwDAPJCsHem1XeCPrIQpCcQ4xIySXjTwlJ6ZbOPSo@Kcm8TwGLKNLmKCVTMbUL37vmLV0jmw0YCAHgdTK13EZf13wjyw3WswoHnV791yt7qqG6la1YPptqY4/) It will only work for one line of input. ]
[Question] [ [ed](https://en.wikipedia.org/wiki/Ed_(text_editor)) is the standard text editor on Unix systems. Your goal is to write an ed clone. ## Task Write a program that reads an input stream and for every received end of line character, print `?` followed by a end of line character. * The communication has to interactive. Means the program needs to output as soon as possible and has to accept more input after that. * There are no input lines that are longer than 105 characters + end of line character * You can choose which character or sequence you use as end of line character, as long as it does not contain any alphanumerical characters nor the `?` character. * The program should not output anything else. Shortest code wins. ## Example Python Script ``` #/usr/bin/env python3 import sys for line in sys.stdin: print("?") ``` [Answer] # [Nibbles](http://golfscript.com/nibbles), 2 bytes ``` @"?" ``` That's 4 nibbles at half a byte each in the binary form. @ is the first line of input but auto maps all lines if there's more input after the first line. Despite the simplicity of this problem I must thank it for making me make sure Nibbles is properly lazy enough to do interactive IO right. There was an issue in that it adds a newline at termination unless your last character was a newline (to not double print newlines), but that wasn't being done lazy enough and so it wasn't interactive enough to satisfy this question. But I've fixed it in latest commit (you'll need latest unstable version of nibbles). [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 5 bytes ``` ?WSD⎚ ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvREPJXknTmqs8IzMnVUHDM6@gtCS4BCiRrqGpqeBSmlugAZR1zklNLAIyyNHD9V@3LAcA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: ``` ? ``` Write a `?` to the canvas, but don't print anything yet. ``` WS ``` Repeatedly input lines until there is nothing left to input... ``` D ``` ... dump the canvas with a trailing newline. ``` ⎚ ``` Clear the canvas so that nothing gets output at the end. [Answer] # [Perl 5.28.1 (webperl)](https://www.perl.org/) + `-pl`, 6 bytes ``` $_="?" ``` [Try it online!](https://dom111.github.io/code-sandbox/#eyJsYW5nIjoid2VicGVybC01LjI4LjEiLCJjb2RlIjoiJF89XCI/XCIiLCJhcmdzIjoiLXBsIiwiaW5wdXQiOiJhYWFhXG5iYmJiYmJiXG5jXG5kZGRkZGRcbiJ9) [Answer] # [Ruby](https://www.ruby-lang.org/) + `-pl`, 5 bytes ``` $_=?? ``` [Try it online!](https://tio.run/##KypNqvz/XyXe1t7@//9EriQY4EoGAq6UlH/5BSWZ@XnF/3ULcgA "Ruby – Try It Online") [Answer] # [Python 3](https://docs.python.org/3/), ~~40~~ 27 bytes ``` for i in open(0):print("?") ``` [Try it online!](https://tio.run/##K6gsycjPM/7/Py2/SCFTITNPIb8gNU/DQNOqoCgzr0RDyV5J8///cq4iLiAGAA "Python 3 – Try It Online") -13 thanks to @ovs ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win. Closed 7 years ago. [Improve this question](/posts/101121/edit) You will write a simple program that prints *exactly* `1 2 3 4 5 6 7 8 9 10` to STDOUT, Console, or your language's closest output method. No other visible output should be seen. Any other code executed must be back-end only. This is [answer-chaining](/questions/tagged/answer-chaining "show questions tagged 'answer-chaining'"), so the catch is that you **must include the previous answer's source code in your code** ("included code"), comments and all. I have started the first answer down below. Included code must be an exact replica of the previous code, unchanged and whole. To keep this challenge fair, the included code must not be in a comment. No language may be used twice. You may use languages created after this contest, but it must not be made for this challenge specifically. Please do not use any libraries or frameworks made for this challenge specifically, either. This is a [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'"), so most vote score wins! Please vote on creativeness of code inclusion, which means that if someone who puts included code in a string and throws it away should not score very high. To make sure everyone gets a chance, discourage answers that do not follow the rules. Also, if you give an answer, please do not downvote other answers if they do not deserve it. Please use the following draft for your answer: ``` #Answer Number: (your number in the chain) ##Language: (programming language used, hyperlinked to official website of language or hyperlink to download compiler) **Previous Answer:** (prev answer language) (link to prev answer) code Any additional info. Try it on web and an explanation are highly encouraged. Bytes Added: (optional, just for my musings. how many bytes you added to previous person's code) ``` [Answer] # Answer Number: 4 # Language: CSS [Previous answer](https://codegolf.stackexchange.com/a/101125/38505) ``` body:before{content:"0 1 2 3 4 5 6 7 8 9 10";}TLðý?0i<?php echo implode(" ",range(1,10)); die;?> var textToPrint = ''; for (var i = 1; i < 11; i++) { textToPrint += i; if (i != 10) textToPrint += " "; } console.log(textToPrint); ``` <https://jsfiddle.net/3tLpp4r2/> [Answer] # Answer Number: 1 ## Language: Javascript **Previous Answer:** First Answer, NA ``` var textToPrint = ''; for (var i = 1; i < 11; i++) { textToPrint += i; if (i != 10) textToPrint += " "; } console.log(textToPrint); ``` Bytes Added: 139 [Answer] # Answer Number: 2 ## Language: PHP **Previous answer:** <https://codegolf.stackexchange.com/a/101123/38505> ``` <?php echo implode(" ",range(1,10)); die;?> var textToPrint = ''; for (var i = 1; i < 11; i++) { textToPrint += i; if (i != 10) textToPrint += " "; } console.log(textToPrint); ``` <https://eval.in/685567> I'm unsure if I'm doing this right for the tag [answer-chaining](/questions/tagged/answer-chaining "show questions tagged 'answer-chaining'"). Prints the desired output, then dies. [Answer] # Answer Number: 3 # Language [05AB1E](http://github.com/Adriandmen/05AB1E) [Previous answer](https://codegolf.stackexchange.com/a/101124/47066) ``` TLðý?0i<?php echo implode(" ",range(1,10)); die;?> var textToPrint = ''; for (var i = 1; i < 11; i++) { textToPrint += i; if (i != 10) textToPrint += " "; } console.log(textToPrint); ``` [Try it online!](http://05ab1e.tryitonline.net/#code=VEzDsMO9PzBpPD9waHAgZWNobyBpbXBsb2RlKCIgIixyYW5nZSgxLDEwKSk7IGRpZTs_Pgp2YXIgdGV4dFRvUHJpbnQgPSAnJzsKZm9yICh2YXIgaSA9IDE7IGkgPCAxMTsgaSsrKSB7CiAgdGV4dFRvUHJpbnQgKz0gaTsKICBpZiAoaSAhPSAxMCkKICAgIHRleHRUb1ByaW50ICs9ICIgIjsKfQpjb25zb2xlLmxvZyh0ZXh0VG9QcmludCk7&input=) ]
[Question] [ Let's assume that $$ f(x) = \frac{Ax+B}{Cx+D} $$ Where, \$x\$ is a variable and \$A\$,\$B\$,\$C\$,\$D\$ are constants. Now we have to find out the inverse function of \$f(x)\$, mathematically \$f^{-1}(x)\$, To do this first we assume, $$ y = f(x) \\\rightarrow y=\frac{Ax+B}{Cx+D} \\\rightarrow Cxy+Dy=Ax+B \\\rightarrow Cxy-Ax=-Dy+B \\\rightarrow x(Cy-A)=-Dy+B \\\rightarrow x=\frac{-Dy+B}{Cy-A} $$ Then, we know that $$ y=f(x) \\\rightarrow f^{-1}(y)=x \\\rightarrow f^{-1}(y)=\frac{-Dy+B}{Cy-A} ..... (i) $$ And from \$(i)\$ equation, we can write \$x\$ instead of \$y\$ $$ \\\rightarrow f^{-1}(x)=\frac{-Dx+B}{Cx-A} $$ So, \$\frac{-Dx+B}{Cx-A}\$ is the inverse function of \$f(x)\$ This is a very long official mathematical solution, but we have a "cool" shortcut to do this: 1. Swap the position of the first and last constant diagonally, in this example \$A\$ and \$D\$ will be swapped, so it becomes: $$ \frac{Dx+B}{Cx+A} $$ 2. Reverse the sign of the replaced constants, in this example \$A\$ is positive (\$+A\$) so it will be negative \$-A\$, \$D\$ is positive (\$+D\$) so it will be negative \$-D\$ $$ \frac{-Dx+B}{Cx-A} $$ And VOILA!! We got the inverse function \$\frac{Ax+B}{Cx+D}\$ in just two steps!! --- # Challenge **(Input of \$\frac{Ax+B}{Cx+D}\$ is given like `Ax+B/Cx+D`)** Now, let's go back to the challenge. Input of a string representation of a function of \$\frac{Ax+B}{Cx+D}\$ size, and output its inverse function in string representation. I have just shown two ways to that (Second one will be easier for programs), there may be other ways to do this, good luck! # Test cases **(Input of \$\frac{Ax+B}{Cx+D}\$ is given like `Ax+B/Cx+D`)** ``` 4x+6/8x+7 -> -7x+6/8x-4 2x+3/2x-1 -> x+3/2x-2 -4x+6/8x+7 -> -7x+6/8x+4 2x+3/2x+1 -> x+3/2x+2 ``` **Or you can give it using list of A,B,C,D** ``` 4,6,8,7 -> -7x+6/8x-4 ``` Or you can output `-7,6,8,-4` # Rules * **Input is always in \$\frac{Ax+B}{Cx+D}\$ size, and is guaranteed to be valid.** * [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden. * Trailing/Leading whitespace in output is allowed. * If possible, please link to an online interpreter (e.g. [TIO](https://tio.run)) to run your program on. * Please explain your answer. This is not necessary, but it makes it easier for others to understand. * Languages newer than the question are allowed. This means you could create your own language where the empty program calculates this number, but don't expect any upvotes. * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code in bytes wins! (Some terminology might be incorrect, feel free ask me if you have problems) [Answer] # [Perl 5](https://www.perl.org/), 27 bytes ``` sub{@_[0,3]=map-$_,@_[3,0]} ``` [Try it online!](https://tio.run/##K0gtyjH9r5Jm@7@4NKnaIT7aQMc41jY3sUBXJV4HyDXWMYit/W@tkqZrp@HgpmmtEm@blZ@Zp6SjpOPg9t9Ex0zHQsecy0jHWMdIR9eQSxdVxPBffkFJZn5e8X/dnAI3HQA "Perl 5 – Try It Online") [Answer] # [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 48 bytes ``` ^- + ^\d -$& (.\d+)(.*)([-+].+) $3$2$1 ^- ^\+ - ``` [Try it online!](https://tio.run/##ZcoxDkAwGAbQ/TtHSevL36YluIFDqIaEwWIQQ29fduvLu4/nvLZS6WktSUCkuENUDW3jTqNtY/QsXCwNVKuC8vjatwgppcvs3Zg5IGS2LmTxkB/Svw "Retina 0.8.2 – Try It Online") Link includes test cases. Assumes that `1x` is always written as such. Explanation: ``` ^- + ^\d -$& ``` Negate and enforce the sign on `A`. ``` (.\d+)(.*)([-+].+) $3$2$1 ``` Swap `A` and `D`. ``` ^- ^\+ - ``` Negate `D`, removing the sign if it was negative. [Answer] # [Vyxal](https://github.com/Lyxal/Vyxal), 9 bytes ``` ÷↭⫙'N^N^W ``` [Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C3%B7%E2%86%AD%E2%AB%99%27N%5EN%5EW&inputs=%5B2%2C%203%2C%202%2C%20-1%5D&header=&footer=) ## Explained ``` ÷↭⫙'N^N^W ÷ # Push every item of the input onto the stack ↭ # And rotate the top three items: [a, b, c, d] → [a, d, b, c] ⫙' # Rotate the entire stack left N^N^W # Negate the top and bottom of the stack and wrap into a list ``` [Answer] # [brainfuck](https://github.com/TryItOnline/brainfuck), ~~31~~ 29 bytes ``` ,[-<->],>,>,[->-<]>.<<<.>.<<. ``` Commented: ``` , #input A into cell 0 [-<->] #decrement cells 0 and -1 until cell 0 contains 0 and cell -1 contains -A ,>,>, #input B,C,D into cells 0,1,2 [->-<] #decrement cells 2 and 3 until cell 2 contains 0 and cell 3 contains -D >.<<<.>.<<. #output -D,B,C and -A ``` [Try it online!](https://tio.run/##SypKzMxLK03O/v9fJ1rXRtcuVscOCKN17XRtYu30bGxs9ECk3v//jk7OLgA "brainfuck – Try It Online") Very rarely, a challenge comes along where Brainfuck is somewhat competitive. Takes 4 bytes as input, gives 4 bytes as output. The normal form of interface for Brainfuck is an ASCII terminal, so the input `ABCD` in the TIO link is intrepreted as `[65,66,67,68]`. Outputs are per the table below. Note that signed negative numbers are treated as their unsigned 8 bit counterparts, and give extended ASCII output in the range 128-255, in accordance with <https://en.wikipedia.org/wiki/Extended_ASCII#/media/File:Table_ascii_extended.png> ``` Input Signed Output Unsigned equivalent ASCII output A=65 -65 191 ¿ B=66 66 66 B C=67 67 67 C D=68 -68 188 ¼ ``` After swapping A and D, we arrive at the required output `[-68,66,67,-65]`, which in ASCII looks like `¼BC¿` [Answer] # [Keg](https://github.com/JonoCode9374/Keg), ~~7~~ 6 bytes [(SBCS)](https://github.com/Lyxal/Keg/blob/master/Codepage.txt) Input as a list. Outputs by values on the stack. Footer outputs entire stack joined by newlines. ``` ÷±'±$" ``` [Try it online!](https://tio.run/##y05N////8PZDG9UPbVRR@h/3qGOinqGlts7/aBMdMx0LHfNYAA "Keg – Try It Online") ## Explanation ``` # Input as a list (e.g. [4, 6, 8, 7]) ÷ # Dump it onto stack (Stack = [ 4, 6, 8, 7]) ± # Negate TOS (Stack = [ 4, 6, 8,-7]) ' # Shift left (Stack = [ 6, 8,-7, 4]) ± # Negate TOS (Stack = [ 6, 8,-7,-4]) $ # Exchange TOS (Stack = [ 6, 8,-4,-7]) " # Shift right (Stack = [-7, 6, 8,-4]) ``` ### Footer explanation ``` ^ # Reverse the stack (So that the first item of TOS is outputted first) ∑ # Apply to entire stack: . # Output TOS as integer 19+, # Print a trailing newline ``` ## Credits * Saved 1 byte thanks to @Lyxal [Answer] # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 43 bytes Takes input as and outputs as an array. ``` $n=$args;-1,1,2,-4|%{$n[$_]*(2*($_-gt0)-1)} ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XyXPViWxKL3YWtdQx1DHSEfXpEa1WiUvWiU@VkvDSEtDJV43vcRAU9dQs/b///@G/43@G/83AQA "PowerShell – Try It Online") ### Less Fun [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 31 bytes ``` param($a,$b,$c,$d)-$d,$b,$c,-$a ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVRRyVJRyVZRyVFU1clBcrRVUn8//@/4X@j/8b/TQA "PowerShell – Try It Online") ### Most Unfun [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 30 bytes ``` -$args[3],$args[1,2],-$args[0] ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X1clsSi9ONo4VgfCMNQxitWBChrE/v//3/C/0X/j/yYA "PowerShell – Try It Online") ### Least Useful [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 26 bytes ``` "-{3},{1},{2},-{0}"-f$args ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X0m32rhWp9oQiI1qdXSrDWqVdNNUEovSi////2/43@i/8X8TAA "PowerShell – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes ``` À`(s()Á ``` [Try it online!](https://tio.run/##yy9OTMpM/f//cEOCRrGG5uHG//@jTXTMdCx0zGMB "05AB1E – Try It Online") ``` # implicit input [A, B, C, D] À # rotate the input left [B, C, D, A] ` # dump all values on the stack B, C, D, A ( # negate top of stack B, C, D, -A s # swap top two values B, C, -A, D ( # negate top of stack B, C, -A, -D ) # collect all values in a list [B, C, -A, -D] Á # rotate the list right [-D, B, C, -A] ``` [Answer] # [APL(Dyalog Unicode)](https://dyalog.com), ~~9~~ 7 bytes [SBCS](https://github.com/abrudz/SBCS) ``` -∘⌽@1 4 ``` [Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=033UMeNRz14HQwUTAA&f=S1MwUTBTsFAwBwA&i=AwA&r=tryAPL&l=apl-dyalog&m=train&n=f) A function submission which accepts an array. -2 bytes from rak1507. [Answer] # [Ruby](https://www.ruby-lang.org/), 26 bytes ``` ->n{a,b,c,d=n [-d,b,c,-a]} ``` [Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOlEnSSdZJ8U2jytaNwXM1k2Mrf1foJAWHW2oY6RjrGMSG8sF5promOlY6JjHxv4HAA "Ruby – Try It Online") Shorter than my brainfuck answer by a few bytes, but not as interesting. [Answer] # [jq](https://stedolan.github.io/jq/), 22 bytes ``` [-.[3],.[1:3][],-.[0]] ``` [Try it online!](https://tio.run/##yyr8/z9aVy/aOFZHL9rQyjg2OlYHyDWIjQWKm@iY6VjomMdyRRvpGOsY6RjGAgA "jq – Try It Online") [Answer] # Java, 31 bytes ``` (a,b,c,d)->new int[]{-d,b,c,-a} ``` [Try it online!](https://tio.run/##PY/BCsIwDIbvPkWOLXQ9iQqi4MWbJ4/iIWs76aydtNlkjD377Doxhz8hJN@f1NhhUevn9G5LZxUohzHCBa2HYQUprCcTKlQGzkOqb3eIjesMSzWgmLXMqrJqvh/z2g8XCSmlrrEaXgnKrhSsfyQKhkfkP485zlAdJoaiFEpoXhy9@UD2GwqdmwWO0/4/fu0jmZdsWpLvRCTnWZ1ekS1ZJ08hYB8lNYsbq@Ry81psxE5sOecLaFyN0xc) [Answer] # [JavaScript (Node.js)](https://nodejs.org), 22 bytes ``` (a,b,c,d)=>[-d,b,c,-a] ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f9fI1EnSSdZJ0XT1i5aNwXM1k2M/f8fAA "JavaScript (Node.js) – Try It Online") [Answer] # [Dash](https://wiki.debian.org/Shell), 23 bytes ``` $((-$4)) $2 $3 $((-$1)) ``` [Try it online!](https://tio.run/##VcixCsIwEIDhPU/xDzc0ww1Jiwq@ikuaO0ihGLCCjx@Lm@P3WTna@LRtd15ejMJKxe5Y5/A3qkhBVqQiZ3ttnceQaVJZYkQyMvNjinFYf/pYuHDjGjIzGU1B/yeFLw "Dash – Try It Online") ## Usage Requires positional parameters for each of A, B, C, and D. Before evaluating the command. Also the code evaluates to just four strings, so run `echo` command with those code (may not portable when D is originally positive, as hyphen-parameter may be treated as an option). ## How it works * dollar-double-parentheses is arithmetic expansion. --- # Polyglot for Bash, OSH, bosh, Dash, ksh, yash, and Zsh, 25 bytes ``` $((- $4)) $2 $3 $((- $1)) ``` [Try it online!](https://tio.run/##VckxCoQwFADRPqeY4hemSJEouuBVtonJh4hiYBX2@FHYast5s52lfcu6Kx@NmchCIs/kyqkXziERWZCEPKypVN5Nuu4Zg7VIQHp@7a1tuR7aBkZeTCbQE3DeuH/x5gY "ksh – Try It Online") ## Differences * A space between hyphen and dollar. This is a workaround for negative values; if one of them was expanded to `$((--1))`, for example, Dash, OSH and Bash parse as minus of minus one, but other four don't; they parse to decrement a variable named one, although one is a constant. --- # Polyglots for Bash and OSH, 19 bytes Thanks, 2x-1! ``` $[-$4] $2 $3 $[-$1] ``` [Try it online!](https://tio.run/##Vci9CoMwFIDRPU/xDXe9Q6JowUepDvm5EEEa0EIfP7Zjx3NSvGr/1P0wTouFSCJTFkrjsjeqSEQSkpFvW66NtctTZdyQgAz84Lde2sv6yMSD2QUGAuqd/o93Nw "Bash – Try It Online") ## What the heck `$[ ... ]` is historically equivalent to `$(( ... ))`, which is [not adopted for POSIX](https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_06_04). OBTW adding a space betwee hyphen and dollar (which is +2 bytes), the code would be polyglot for Zsh, too. [Answer] # [convey](http://xn--wxa.land/convey/), 16 + 6 = 22 or 53 bytes Version 1: 16 (but takes extra input) ``` {?>>>>*} >>>>>^ ``` After the four numbers, also input -1 1 1 -1 (+6 bytes). I can't figure out how to do it shortly any other way. [Try it online!](https://xn--wxa.land/convey/run.html#eyJjIjoiez8+Pj4+Kn1cbiA+Pj4+Pl4iLCJ2IjoxLCJpIjoiMSAyIDMgNCAtMSAxIDEgLTEifQ==) Version 2, 53 bytes ``` {?>*}v<0 v ^<<^-1 ?>>*} v< ^v<1 v 0>^v v1-^<< >>*} ``` It's complicated. Multiplies the first and last numbers by -1. I'm a noob at convey and wait was crashing the program. [Try it online!](https://xn--wxa.land/convey/run.html#eyJjIjoiez8+Kn12PDBcbiB2IF48PF4tMVxuID8+Pip9XG52PCAgXnY8MVxudiAwPl52XG52MS1ePDxcbj4+Kn0iLCJ2IjoxLCJpIjoiMSAyIDMgNCJ9) [Answer] # [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 19 bytes ``` 0?0r-sbscsd-lcldlbf ``` [Try it online!](https://tio.run/##S0n@/9/A3qBItzipOLk4RTcnOSclJynt/38TBTMFCwVzAA "dc – Try It Online") ## Explanation ``` # Say the input is 4 6 8 7. # Effect: 0 # [0] ? # [0, 4, 6, 8, 7] 0r- # [0, 4, 6, 8,-7] sbscsd # [0, 4] (B=-7, C=8, D=4) - # [-4] (B=-7, C=8, D=4) lcldlb # [-4, 8, 4, -7] f # Output in reverse (i.e. -7 6 8 -4) ``` [Answer] # MMIX, 44 bytes (11 instrs) Inverts `mobius *a` into `mobius *b`. This is with `typedef double mobius[4];`. Note that NaNs and zeroes have the sign negated; to not do so would cost an extra instruction (zeroing out `$2` at start and replacing `INCL $255,#8000` with `FSUB $255,$2,$255`). (jxd) ``` 00000000: 8fff0018 e4ff8000 afff0100 8fff0010 Ɓ”¡ðỵ”⁰¡Ḥ”¢¡Ɓ”¡Ñ 00000010: afff0108 8fff0008 afff0110 8fff0000 Ḥ”¢®Ɓ”¡®Ḥ”¢ÑƁ”¡¡ 00000020: e4ff8000 afff0118 f8000000 ỵ”⁰¡Ḥ”¢ðẏ¡¡¡ ``` Disassembled: ``` invmob LDOU $255,$0,24 INCH $255,#8000 STOU $255,$1 LDOU $255,$0,16 STOU $255,$1,8 LDOU $255,$0,8 STOU $255,$1,16 LDOU $255,$0 INCH $255,#8000 STOU $255,$1,24 POP 0,0 ``` [Answer] # [Python 3](https://docs.python.org/3/), 26 bytes ``` lambda a,b,c,d:[-d,b,c,-a] ``` [Try it online!](https://tio.run/##K6gsycjPM/7/PycxNyklUSFRJ0knWSfFKlo3BczSTYz9/x8A "Python 3 – Try It Online") 4 input. Output is list. ]
[Question] [ **Closed**. This question is [opinion-based](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Update the question so it can be answered with facts and citations by [editing this post](/posts/62529/edit). Closed 8 years ago. [Improve this question](/posts/62529/edit) Is this Q too easy to ask, or has it just never been thought of? > > Generate a random number, either 0 or 1 using a program > > > You may use a pre-defined function. The code must be executable. (It can't be just a function that requires more code to execute.) Randomness of the output will be verified by showing that it is not possible for a human/computer today to predict the output of the next execution (unless the exact algorithm is revealed), even when given an infinite set of outputs on previous executions of the code. I'm looking for the most interesting code (never mind if it's lengthy). *Note:* I had initially asked for the shortest code. The answer to *that* is 2 bytes long. It's `O2` in Pyth, according to @Dennis [Answer] # Pyth, 2 bytes ``` O2 ``` [Try it online.](https://pyth.herokuapp.com/?code=O2) [Answer] # [Labyrinth](https://github.com/mbuettner/labyrinth), 7 bytes I think this is also the shortest answer in Labyrinth... and I think it's fairly interesting. ``` v ) "!@ ``` Labyrinth does have built-in random behaviour but it's normally very hard to access. The conditions are as follows: * The instruction pointer (IP) needs to be on a cell with two neighbours in opposite directions. * The IP must not be pointing at either of the neighbours. * The value on top of the main stack must be zero. If all of those conditions are met, the IP will choose a uniformly random direction towards one of the two neighbours. In larger programs, this is incredibly tricky to setup, because normally there is no way to make the IP move such that it faces a wall if there isn't another neighbour at its back. The only way to set this up is by using the source-manipulation commands `<^>v`. These cyclically shift a row or a column of the source code. If the shifted row or column is the one the IP is one, the IP will be shifted along without changing its orientation. This way we can move the IP into position. Now let's look at the code. The IP starts out on the first cell, pointing *right*. The `v` shifts the first column down one cell, taking the IP with it: ``` " v )!@ ``` Now the IP points East, has a neighbour North and South, and the main stack still has only zeroes on it, so all conditions are met. What are the options now? If the IP decides to move South, `)` increments the zero on top of the stack to `1` and `!` prints it. `@` terminates the program. If the IP decides to move North, `"` is a no-op. The IP hits a dead end and turns around. Now it hits the `v` again. So we shift one further: ``` ) " v!@ ``` Now the IP is in a corner and follows the path around the bend. `!` prints the zero on top of the stack, and `@` terminates the program. [Answer] ## [><>](https://esolangs.org/wiki/Fish), 5 bytes ``` lxn;n ``` ><> is a 2D language, and `x` is "random direction" (up/down/left/right) in ><>. Since ><> is toroidal, up and down do nothing, as this is a one-liner and wrapping around makes us end up in the same spot. Thus, only moving left or right at the `x` do anything in this program. The initial `l` pushes the length of the stack, 0. At the `x`, moving right makes us print the top of the stack with `n`, then halt with `;`. Otherwise, moving left executes `l` again, pushing 1 before we wrap around, print and halt. --- And for the popcon, we have: ``` 0 > xxxxx aa*(n; ^+1 <<<<< ``` This is "The Ledge: ><> plays Pokemon version". The instruction pointer needs to get past the row of `x`s, with falling off the ledge (random up/down) moving us back to the start, incrementing a failure counter. It's a race against time, with the program printing 1 if the IP makes it to the end whilst falling off at most 99 times, else 0. [Answer] # AppleScript/osascript, 17 Bytes AppleScript is really a passive-aggressive teenager. o-o ``` some item of{1,0} ``` Or, 18 bytes: ``` random number of 1 ``` This is kinda the cheaty way to do it. `some item` will grab a random item of a list. If I wanted a random item of a series, I would use: ``` random number from 0 to 100 ``` For a random integer in the set [0, 100]. [Answer] # [Vitsy](https://github.com/VTCAKAVSMoACE/Vitsy/tree/31086c59e256d4e1d0d95bb96c5c7d22ba52b1a6) I'm changing my answer to fit the popcon description. ``` 2R(10r68*+DD:::?? WHY WOULD YOU WRITE LIKE THIS? 2R Random float in [0,2). (10 If its truncated value is 1, Push one. Then push 0. r Reverse the stack. 68*+ Add 48. DD Duplicate, duplicate. :::?? Clone the stack thrice, rotate stack position twice. WH W U D U W K H NOPs. Y Delete the current stack. O Output the top item of the stack as a truncated int character. L Get the length of the stack. Y Delete the current stack. O Output again (outputs nothing) R Random integer. I Get the input length. T Tangent of the top item. E Push the constant e to the stack. LI E T IS? Already described above... ``` [Answer] # [TeaScript](https://github.com/vihanb/TeaScript), 2 bytes ``` N¡ ``` Using some not-so-[new](https://github.com/vihanb/TeaScript/commit/bf68a3ed6b40f815c0bf1fb2f4f0ede390914464)-but-implemented-last-night features, `¡` (inverted exclamation) compiles to `()`. Because of issues with permalinks and special characters, you have to copy and paste this code into the [online interpreter](http://vihanserver.tk/p/TeaScript/) [Answer] # [Simplex v.0.7](http://conorobrien-foxx.github.io/Simplex/), 2 bytes ``` IX I ~~ increment byte X ~~ set byte to a random number from 0 to the current byte value ``` The byte is valued `0` by default; incrementing it by `1` then applying the random function makes it a random value from `0` to `1` inclusive. [Answer] # Microscript, 2 bytes ``` r2 ``` # Microscript II, also 2 bytes ``` 2R ``` [Answer] # Python 3, 22 bytes ``` print((hash(id)>>9)&1) ``` In python 3, the output for the `hash` function was randomized per run by default. This was because in older versions, [you could make an attack on the dictionary object](http://bugs.python.org/issue13703) if you could insert arbitrary objects (such as strings for usernames or integers for uuids). You could exploit the way the dict object was implemented so you could make retrieving objects from the dictionary take much much longer than normal. Because of this, `hash` became randomised. I'm exploiting this for the challenge so I don't need to import the random module. I'm doing `>>9` because although randomised, during the tests I ran, the last several bits never changed although this bit sometimes did. On my computer, it outputs `0` most of the time but sometimes outputs a `1`. [Answer] # CJam, 3 bytes ``` 2mr ``` [Try it here.](http://cjam.aditsu.net/#code=2mr) [Answer] # Befunge, 6 bytes ``` [[email protected]](/cdn-cgi/l/email-protection) ``` The PC starts at the top-left corner, moving right. When it runs into `?`, it will either * Move up or down, in which case it wraps vertically back to the very same `?` * Move left, wrapping around and executing `0`, `.` and `@`: this prints a zero and halts the program * Move right, executing `1`, `.`, and `@`, which prints a one and halts the program. Works for both Befunge-93 and Befunge-98. [Answer] # Ruby, 8 bytes ``` p rand 2 ``` Probably the shortest it gets in Ruby. [Answer] # Python 2, 16 bytes This one is pretty fun: ``` print id('')/3&1 ``` In CPython, at least, `id('')` is different every time, because the string literal `''` is at a different position in memory each time the interpreter is ran. We can't directly take the least-significant bit, because it's obviously aligned to a valid address. However, dividing by three first works fine. [Answer] # Mathematica ``` Boole[OddQ[ToExpression[StringSplit[ToString[s = SiderealTime[][[1, 3]]], "."][[-1]]]]] ``` --- **Explanation** `SiderealTime[]` gives the present sidereal time. ``` s = SiderealTime[] ``` [![time](https://i.stack.imgur.com/gNwuG.png)](https://i.stack.imgur.com/gNwuG.png) --- The code for the above time is revealed by its `LongForm`. ``` LongForm[s] ``` > > Quantity[MixedRadix[14, 10, 33.3553], MixedRadix["HoursOfRightAscension", "MinutesOfRightAscension", "SecondsOfRightAscension"]] > > > --- ``` s[[3,1]] ``` The element at position `{3,1}` in the expression is > > 33.3553 > > > --- `ToString[%]` converts this to a string. > > "33.3553" > > > --- ``` StringSplit["33.3553", "."] ``` breaks the string at the decimal point. > > {"33","3553"} > > > --- ``` {"33","3553"}[[-1]] ``` returns the last element, namely, `"3553"` --- ``` ToExpression["3553"] ``` converts this to an integer. > > 3553 > > > --- `OddQ[3553]` returns > > True > > > because `3553` is odd. --- `Boole[True]` returns `1` for True. `Boole[False]` would have returned `0`. [Answer] ## Perl, 28 bytes ``` my $rand=int(rand(2)); print $rand, "\n"; ``` Golfed version, just in case it changes back again (I'm scoring in the headline by this): ``` my $a=int(rand(2));print $a; ``` [Answer] # Java, 88 Bytes ``` class A{public static void main(String[]a){System.out.println((int)(Math.random()*2));}} ``` Readable version: ``` class A{ public static void main(String[]a) { System.out.println((int)(Math.random()*2)); // Get a random float from [0, 2) and truncate it to an integer. } } ``` [Answer] # GolfScript, 5 bytes ``` 2rand ``` Basically exactly like the CJam answer, but with a longer keyword. [Answer] # Ruby, *who cares* bytes Seems this isn't a code-golf challenge anymore? Here's some multithreading for ya. ``` [0,1].map{|i|Thread.new{$n=i}}.map{|t|t.join} p $n ``` [Answer] # gs2, 2 bytes In CP437: ``` ↕% ``` Hex dump: ``` 12 25 ``` Pushes `2`, then calls `random`, generating a random number between 0 and 1. [Answer] ## Perl, 14 bytes ``` print 0|rand 2 ``` Example: ``` $ perl -e 'print 0|rand 2' 1 $ perl -e 'print 0|rand 2' 1 $ perl -e 'print 0|rand 2' 0 $ ``` [Answer] ## bash, 19 bytes ``` echo $(($RANDOM%2)) ``` [Answer] # Javascript ES6, 22 bytes Quite simple. ``` alert(0|Math.random()+.5) ``` [Answer] # PHP "The Lottery" In Germany we have a very popular lottery called "*6 aus 49*" ("*6 from 49*"). You tip 6 numbers out of the range 1 to 49. If you have selected at least 2 numbers that also the "Lottofee" ("Lottery Fairy") has picked, you win.1 The code below has a player against the lottery. If the player loses it will output `0`, if the player wins it outputs `1`. As the distribution of a lose to win was still 1:5 I changed the rule, that at least one number must be picked by both the player and the lottery for a win. This results in an almost even distribution with slightly more wins. ``` function pick() { $numbers = []; for ($i = 0; $i < 6; ++$i) { $pick = mt_rand(1, 49); while(in_array($pick, $numbers)) { $pick = mt_rand(1, 49); } $numbers[] = $pick; } return $numbers; } $player = pick(); $lottery = pick(); print ( count(array_intersect($player, $lottery)) > 0 ? 1 : 0 ) . "\n"; ``` That's a bit simplified, but the general idea. [Answer] # Lua,   ~~30~~   18 bytes This answer is based on the same idea as [muddyfish's answer](https://codegolf.stackexchange.com/a/62553/7313). In Lua order of elements in a table depends on hash, which is randomized per run. We simply printing the first key in a table consisting of just '0' and '1': ``` $ lua -e "print(next{['0']='',['1']=''})" ``` --- **EDIT**: Another version (length mod 2 of some unpredictably chosen global variable's name): ``` $ lua -e "print(#next(_G)%2)" ``` ]
[Question] [ In Javascript you can recover the complete language using only the symbols `()[]!+`. [Here's the basics](http://www.jsfuck.com/): ``` false => ![] true => !![] undefined => [][[]] NaN => +[![]] 0 => +[] 1 => +!+[] 2 => !+[]+!+[] 10 => [+!+[]]+[+[]] Array => [] Number => +[] String => []+[] Boolean => ![] Function => []["filter"] eval => []["filter"]["constructor"]( CODE )() window => []["filter"]["constructor"]("return this")() ``` That's great and all, but where did they get those first 6 characters from? I think it's best we help them out. --- Simply write a program or function that outputs (at least) the 6 characters `[]()!+` in any order you want, as many times as you want, with as many other characters in between as you want. Shortest code wins. Gold star if you use less than 6 unique characters to do so. [Answer] # Bash + iw, ~~6~~ 4 bytes ``` iw w ``` Prints those six characters (and a lot more). ### Output ``` Usage: iw [options] command Options: --debug enable netlink debugging --version show version (3.11) Commands: help [command] Print usage for all or a specific command, e.g. "help wowlan" or "help wowlan enable". event [-t] [-r] [-f] Monitor events from the kernel. -t - print timestamp -r - print relative timstamp -f - print full frame for auth/assoc etc. features commands list all known commands and their decimal & hex value phy list List all wireless devices and their capabilities. phy <phyname> info Show capabilities for the specified wireless device. dev List all network interfaces for wireless hardware. dev <devname> info Show information for this interface. dev <devname> del Remove this virtual interface dev <devname> interface add <name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] phy <phyname> interface add <name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] Add a new virtual interface with the given configuration. Valid interface types are: managed, ibss, monitor, mesh, wds. The flags are only used for monitor interfaces, valid flags are: none: no special flags fcsfail: show frames with FCS errors control: show control frames otherbss: show frames from other BSSes cook: use cooked mode active: use active mode (ACK incoming unicast packets) The mesh_id is used only for mesh mode. dev <devname> ibss join <SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>] [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] [key d:0:abcde] Join the IBSS cell with the given SSID, if it doesn't exist create it on the given frequency. When fixed frequency is requested, don't join/create a cell on a different frequency. When a fixed BSSID is requested use that BSSID and do not adopt another cell's BSSID even if it has higher TSF and the same SSID. If an IBSS is created, create it with the specified basic-rates, multicast-rate and beacon-interval. dev <devname> ibss leave Leave the current IBSS cell. dev <devname> station dump List all stations known, e.g. the AP on managed interfaces dev <devname> station set <MAC address> mesh_power_mode <active|light|deep> Set link-specific mesh power mode for this station dev <devname> station set <MAC address> vlan <ifindex> Set an AP VLAN for this station. dev <devname> station set <MAC address> plink_action <open|block> Set mesh peer link action for this station (peer). dev <devname> station del <MAC address> Remove the given station entry (use with caution!) dev <devname> station get <MAC address> Get information for a specific station. dev <devname> survey dump List all gathered channel survey data dev <devname> mesh leave Leave a mesh. dev <devname> mesh join <mesh ID> [mcast-rate <rate in Mbps>] [beacon-interval <time in TUs>] [dtim-period <value>] [vendor_sync on|off] [<param>=<value>]* Join a mesh with the given mesh ID with mcast-rate and mesh parameters. dev <devname> mpath dump List known mesh paths. dev <devname> mpath set <destination MAC address> next_hop <next hop MAC address> Set an existing mesh path's next hop. dev <devname> mpath new <destination MAC address> next_hop <next hop MAC address> Create a new mesh path (instead of relying on automatic discovery). dev <devname> mpath del <MAC address> Remove the mesh path to the given node. dev <devname> mpath get <MAC address> Get information on mesh path to the given node. dev <devname> scan [-u] [freq <freq>*] [ies <hex as 00:11:..>] [meshid <meshid>] [lowpri,flush,ap-force] [ssid <ssid>*|passive] Scan on the given frequencies and probe for the given SSIDs (or wildcard if not given) unless passive scanning is requested. If -u is specified print unknown data in the scan results. Specified (vendor) IEs must be well-formed. dev <devname> scan trigger [freq <freq>*] [ies <hex as 00:11:..>] [meshid <meshid>] [lowpri,flush,ap-force] [ssid <ssid>*|passive] Trigger a scan on the given frequencies with probing for the given SSIDs (or wildcard if not given) unless passive scanning is requested. dev <devname> scan dump [-u] Dump the current scan results. If -u is specified, print unknown data in scan results. reg get Print out the kernel's current regulatory domain information. reg set <ISO/IEC 3166-1 alpha2> Notify the kernel about the current regulatory domain. dev <devname> auth <SSID> <bssid> <type:open|shared> <freq in MHz> [key 0:abcde d:1:6162636465] Authenticate with the given network. dev <devname> connect [-w] <SSID> [<freq in MHz>] [<bssid>] [key 0:abcde d:1:6162636465] Join the network with the given SSID (and frequency, BSSID). With -w, wait for the connect to finish or fail. dev <devname> disconnect Disconnect from the current network. dev <devname> link Print information about the current link, if any. dev <devname> offchannel <freq> <duration> Leave operating channel and go to the given channel for a while. dev <devname> cqm rssi <threshold|off> [<hysteresis>] Set connection quality monitor RSSI threshold. phy <phyname> wowlan show Show WoWLAN status. phy <phyname> wowlan disable Disable WoWLAN. phy <phyname> wowlan enable [any] [disconnect] [magic-packet] [gtk-rekey-failure] [eap-identity-request] [4way-handshake] [rfkill-release] [tcp <config-file>] [patterns [offset1+]<pattern1> ...] Enable WoWLAN with the given triggers. Each pattern is given as a bytestring with '-' in places where any byte may be present, e.g. 00:11:22:-:44 will match 00:11:22:33:44 and 00:11:22:33:ff:44 etc. Offset and pattern should be separated by '+', e.g. 18+43:34:00:12 will match '43:34:00:12' after 18 bytes of offset in Rx packet. The TCP configuration file contains: source=ip[:port] dest=ip:port@mac data=<hex data packet> data.interval=seconds [wake=<hex packet with masked out bytes indicated by '-'>] [data.seq=len,offset[,start]] [data.tok=len,offset,<token stream>] phy <phyname> coalesce show Show coalesce status. phy <phyname> coalesce disable Disable coalesce. phy <phyname> coalesce enable <config-file> Enable coalesce with given configuration. The configuration file contains coalesce rules: delay=<delay> condition=<condition> patterns=<[offset1+]<pattern1>,<[offset2+]<pattern2>,...> delay=<delay> condition=<condition> patterns=<[offset1+]<pattern1>,<[offset2+]<pattern2>,...> ... delay: maximum coalescing delay in msec. condition: 1/0 i.e. 'not match'/'match' the patterns patterns: each pattern is given as a bytestring with '-' in places where any byte may be present, e.g. 00:11:22:-:44 will match 00:11:22:33:44 and 00:11:22:33:ff:44 etc. Offset and pattern should be separated by '+', e.g. 18+43:34:00:12 will match '43:34:00:12' after 18 bytes of offset in Rx packet. dev <devname> roc start <freq> <time in ms> wdev <idx> p2p stop wdev <idx> p2p start phy <phyname> set antenna <bitmap> | all | <tx bitmap> <rx bitmap> Set a bitmap of allowed antennas to use for TX and RX. The driver may reject antenna configurations it cannot support. dev <devname> set txpower <auto|fixed|limit> [<tx power in mBm>] Specify transmit power level and setting type. phy <phyname> set txpower <auto|fixed|limit> [<tx power in mBm>] Specify transmit power level and setting type. phy <phyname> set distance <distance> Set appropriate coverage class for given link distance in meters. Valid values: 0 - 114750 phy <phyname> set coverage <coverage class> Set coverage class (1 for every 3 usec of air propagation time). Valid values: 0 - 255. phy <phyname> set netns <pid> Put this wireless device into a different network namespace phy <phyname> set rts <rts threshold|off> Set rts threshold. phy <phyname> set frag <fragmentation threshold|off> Set fragmentation threshold. dev <devname> set channel <channel> [HT20|HT40+|HT40-] phy <phyname> set channel <channel> [HT20|HT40+|HT40-] dev <devname> set freq <freq> [HT20|HT40+|HT40-] dev <devname> set freq <control freq> [20|40|80|80+80|160] [<center freq 1>] [<center freq 2>] phy <phyname> set freq <freq> [HT20|HT40+|HT40-] Set frequency/channel the hardware is using, including HT configuration. phy <phyname> set name <new name> Rename this wireless device. dev <devname> set mcast_rate <rate in Mbps> Set the multicast bitrate. dev <devname> set peer <MAC address> Set interface WDS peer. dev <devname> set noack_map <map> Set the NoAck map for the TIDs. (0x0009 = BE, 0x0006 = BK, 0x0030 = VI, 0x00C0 = VO) dev <devname> set 4addr <on|off> Set interface 4addr (WDS) mode. dev <devname> set type <type> Set interface type/mode. Valid interface types are: managed, ibss, monitor, mesh, wds. dev <devname> set meshid <meshid> dev <devname> set monitor <flag>* Set monitor flags. Valid flags are: none: no special flags fcsfail: show frames with FCS errors control: show control frames otherbss: show frames from other BSSes cook: use cooked mode active: use active mode (ACK incoming unicast packets) dev <devname> set mesh_param <param>=<value> [<param>=<value>]* Set mesh parameter (run command without any to see available ones). dev <devname> set power_save <on|off> Set power save state to on or off. dev <devname> set bitrates [legacy-<2.4|5> <legacy rate in Mbps>*] [mcs-<2.4|5> <MCS index>*] Sets up the specified rate masks. Not passing any arguments would clear the existing mask (if any). dev <devname> get mesh_param [<param>] Retrieve mesh parameter (run command without any to see available ones). dev <devname> get power_save <param> Retrieve power save state. Commands that use the netdev ('dev') can also be given the 'wdev' instead to identify the device. You can omit the 'phy' or 'dev' if the identification is unique, e.g. "iw wlan0 info" or "iw phy0 info". (Don't when scripting.) Do NOT screenscrape this tool, we don't consider its output stable. ``` [Answer] # [GS2](http://github.com/nooodl/gs2), 1 byte Code: ``` ç ``` [Try it online!](http://gs2.tryitonline.net/#code=w6c&input=) [Answer] # [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), ~~42~~ 40 + 3 = 43 bytes [Try it online](http://brain-flak.tryitonline.net/#code=KCgoKCgoKCkoKSgpKXt9KXt9KXt9KXt9KXt9KXsoKHt9KVsoKV0pfQ&input=&args=LUE&debug=on) ``` ((((((()()()){}){}){}){}){}){(({})[()])} ``` It pushes 96 and loops through pushing every number smaller than 96. This requires the `-A` flag to run. I suppose I get the "gold star" for what it's worth [Answer] # Brainfuck, 5 bytes ``` +[+.] ``` [Try it online!](http://brainfuck.tryitonline.net/#code=K1srLl0&input=) ## Explanation Increments the byte under the data pointer, then loops while the byte under the data pointer is not zero (until the value overflows and gets back to zero), incrementing and printing the value. [Answer] # [Jelly](http://github.com/DennisMitchell/jelly), 3 bytes ``` ³RỌ ``` [Try it online!](http://jelly.tryitonline.net/#code=wrNS4buM&input=) [Answer] ## [CJam](http://sourceforge.net/projects/cjam/), 3 bytes ``` '^, ``` [Try it online!](http://cjam.tryitonline.net/#code=J14s&input=) Prints all ASCII up to and including `]`. [Answer] ## Pyke, 2 bytes ``` ~a ``` [Try it here!](http://pyke.catbus.co.uk/?code=%7Ea&input=%28%29%5B%5D%21%2B) Prints every char in range(0, 255) [Answer] ## Sh, ~~16~~ 12 bytes ``` cat /dev/mem ``` Since you visited this page, `/dev/mem` must contain `[]()!+`, and anyway statistics says your RAM must contains the characters `[]()!+` [Answer] # [Perl 6](https://perl6.org), 12 bytes ``` put '!'..']' ``` ``` put '[]()!+' ``` ``` '[]()!+'.say ``` ``` say ['()!+'] ``` I think it is fairly conclusive that the minimum is 12 bytes. [Answer] ## [Y](https://github.com/tuxcrafting/y), 12 bytes ``` ∅O("[]()!+") ``` Outputs `[]()!+` [Answer] # Python 2, 13 bytes ``` print'[]()!+' ``` Prints `[]()!+` [Answer] # Powershell, 10 different chars, 15 bytes ``` [char[]](1..99) ``` Explanation: ``` [char[]](1..1000) (x .. y) #Range x y [ ] #Cast to char[] #char array #implict output(arrays are seperated by \n ``` Don't put this in a file. Because then the `implict output` doesn't work! [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 2 bytes ``` žQ ``` [Try it online!](https://tio.run/##yy9OTMpM/f//6L7A//8B "05AB1E – Try It Online") Pushes the printable ASCII stack and implicitly prints it. The printable ASCII character set includes the JSFk characters. [Answer] # [Text](https://esolangs.org/wiki/Text), 6 bytes ``` []()!+ ``` The challenge is quite uninteresting, so I made a quite uninteresting answer. ## Also works in (Try It Online) [PHP](https://tio.run/##K8go@P8/OlZDU1H7/38A), [///](https://tio.run/##K85JLM5ILf7/PzpWQ1NR@/9/AA), [ReRegex](https://tio.run/##K0otSk1Prfj/PzpWQ1NR@/9/AA), [Canvas](https://tio.run/##S07MK0ss/v8/OlZDU1H7/38A), [Chain](https://tio.run/##S85IzMz7/z86VkNTUfv/fwA), [ink](https://tio.run/##y8zL/v8/OlZDU1H7/38A), [Charcoal](https://tio.run/##S85ILErOT8z5/z86VkNTUfv/fwA), [Corea](https://tio.run/##S84vSk38/z86VkNTUfv/fwA), [M4](https://tio.run/##yzX5/z86VkNTUfv/fwA), and a lot more... ]
[Question] [ Given a unicode character `C` (or the first character of a string input), output that character's hex representation. Case does not matter. The output ranges from `\u0000` to `\u9999`. Test cases ``` A => 41 (65_10 === 41_16) ʣ => 2A3 (675_10 === 2A3_16) Ω => 3A9 (937_10 === 3A9_16) 7 => 37 (55_10 === 37_16) (null byte) => 0 (0_10 === 0_16) ``` -50% byte bonus if you output the javascript escape character `\uXXXX` of the character `C`, e.g. `g => \u0067` and `~ => \u007E` [Answer] # Jolf, 3 bytes [Try it here!](http://conorobrien-foxx.github.io/Jolf/#code=flRp) ``` ~Ti ``` Compiles to `var i=prompt("i = ");(i).charCodeAt().toString(16);` ## Bonus, 13 - 50% = 6.5 bytes [Try it here](http://conorobrien-foxx.github.io/Jolf/#code=IlxcdSUicHF-VGk0MA)! ``` "\\u%"pq~Ti40 "\\u " prefix % interpolate with ~Ti you know what this is pq 40 pad with 4 0's ``` [Answer] # Julia, 14 bytes Interestingly, this is 14 bytes with and without the bonus. No bonus: ``` c->hex(Int(c)) ``` Bonus: ``` c->"\\u"lpad(hex(Int(c)),4,0) ``` Both are lambda functions that accept `Char`s and return strings. To call a lambda, assign it to a variable. We get the code point associated with the `Char` using `Int()`, then convert to hexadecimal using `hex()`. For the bonus, we left pad to 4 characters with zeros and prepend `\\u`. The backslash needs to be escaped in the string. [Answer] # CJam, 5.5 bytes ``` "\u%04X"qe% ``` The code is **11 bytes** long and qualifies for the **-50%** bonus. Try it online in the [CJam interpreter](http://cjam.aditsu.net/#code=%22%5Cu%2504X%22qe%25&input=%CA%A3). ### How it works ``` "\u%04X" e# Push that format string, i.e., a literal "\u", followed by e# an integer in hexadecimal, 0-padded to 4 characters. q e# Read all input. e% e# Apply string formatting. ``` The online interpreter will happily treat the input string as the code point of its sole character. This does *not* work in the Java interpreter, so it might be a feature or a bug. [Answer] ## CJam, ~~5~~ ~~20~~ 18 bytes ``` {iGb{A,6,'Af++=}%} ``` `i` converts to integer, `G` pushes 16, `b` is base conversion. ... and CJam has no way to use 0-9A-Z instead of base-converting to numbers? That's not annoying at all. ``` { }% map over number-digits A, generate the digits 0-9 6,'Af+ generate the "digits" A-F + concat = array-index into the newly generated array ``` Thanks to [@MartinBüttner](https://codegolf.stackexchange.com/users/8478/martin-b%c3%bcttner) for saving 2 bytes! [Answer] # Pyth - 4 bytes ``` .HCz ``` [Test Suite](http://pyth.herokuapp.com/?code=.HCz&test_suite=1&test_suite_input=A%0A%CA%A3%0A%CE%A9%0A7&debug=0). Pyth doesn't do unicode for string conversions, instead uses ISO-8859, so cost one more byte. ``` .H Hex representation C Unicode code point z Input string ``` [Answer] # JavaScript ES6, ~~30~~ 54 / 2 = 27 bytes ``` s=>"\\u"+("000"+s.charCodeAt().toString(16)).slice(-4) ``` The bonus helped a bit [Try it online at ESFiddle](http://vihanserver.tk/p/esfiddle/?code=f%3D%20s%3D%3E%22%5C%5Cu%22%2B(%22000%22%2Bs.charCodeAt().toString(16)).slice(-4)%0Af('%C3%A5')) (all browsers work) [Answer] # Mathematica, 50 - 50% = 25 bytes ``` "\u"<>IntegerString[First@ToCharacterCode@#,16,4]& ``` Ignore the error. Mathematica does not recognize the escape code `\u`, so just escapes the `\` and gives a `Syntax:stresc` message. [Answer] # [TeaScript](http://github.com/vihanb/teascript), 5 bytes ``` xcT16 ``` I'm very sure I have a unicode shortcut for 16 [Try it online](http://vihan.org/p/TeaScript/#?code=%22xcT16%22&inputs=%5B%22%22%5D&opts=%7B%22int%22:false,%22ar%22:false,%22debug%22:false%7D) [Answer] ## Python 2, 27/2 = 13.5 bytes ``` lambda x:r'\u%04X'%(ord(x)) ``` No online link because apparently ideone's Python 2 version doesn't support Unicode string literals. [Answer] # Japt, 5 bytes ``` Uc sG ``` Very simple. [Try it online!](http://ethproductions.github.io/japt?v=master&code=VWMgc0c=&input=ImEi) ### How it works ``` Uc sG // Implicit: U = input, G = 16 Uc // Take the char code of U. sG // Turn it into a base-16 string. // Implicit: output last expression ``` ### Bonus version, 20 bytes \* 0.5 = 10 ``` "\\u{'0³+Uc sG)t0-4 ``` Not as simple. [Try it online!](http://ethproductions.github.io/japt?v=master&code=IlxcdXsnMLMrVWMgc0cpdDAtNCA=&input=ImEi) ### How it works ``` // Implicit: U = input, G = 16 "\\u{ // Take the string "\u", and add: '0³+ // Take 3 "0"s, plus Uc sG) // the hex char code of the input. t0-4 // Take the last 4 chars. // Implicit: output last expression ``` [Answer] # 𝔼𝕊𝕄𝕚𝕟, 3 chars / 8 bytes ``` ï⒞ⓧ ``` `[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter2.html?eval=false&input=%CA%A3&code=%C3%AF%E2%92%9E%E2%93%A7)` Superbly simple. Convert to charcode, then to hex. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/125947/edit). Closed 6 years ago. [Improve this question](/posts/125947/edit) ## Your Task You will write a program or function to return a truthy value if the integer inputted to it is a square repdigit, and a falsy value if it is not. A repdigit is an integer that contains only one digit (e.g. `2`, `44`, `9999`). For the purpose of this challenge, a square repdigit is a repdigit that is the square of a different repdigit. ## Input An integer, in base 10. ## Output A truthy/falsy value that reflects whether the input is a square repdigit ## Examples ``` 0 --> falsy 1 --> falsy 2 --> falsy 4 --> truthy 9 --> truthy 11 --> falsy ``` ## Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), lowest bytes wins. [Answer] # [Neim](https://github.com/okx-code/Neim), ~~6~~ ~~3~~ 2 bytes ``` +𝕚 ``` Abuses the way that Neim deals with lists. `+` pushes the numeric literal `49` to the stack. Then, `𝕚` attempts to pop a list from the stack, and Neim implicitly converts `49` to `[4 9]`. It then pops another element, which is the input, provided implicitly. Finally, it checks that the input is in the list. [Try it!](http://178.62.56.56:80/neim?code=%2B%F0%9D%95%9A&input=9) [Answer] # [Befunge](https://github.com/catseye/Befunge-93), ~~20~~ ~~17~~ 10 bytes ``` &4-:5-*!.@ ``` [Try it online!](https://tio.run/##S0pNK81LT/3/X81E18pUV0tRz@H/f0sA "Befunge – Try It Online") *Thanks @ovs for -7 bytes!* ## How? ``` &4-:5-*!.@ Initial pointer direction > (Input: 9 ) & Get input as integer (Stack: 9 ) 4- Subtract 4 (Stack: 5 ) : Duplicate (Stack: 5, 5) 5- Subtract 5 (Stack: 5, 0) * Multiply (Stack: 0 ) ! NOT (Stack: 1 ) . Print as integer (Stack: ) @ End of program ``` ## Proof that `4` and `9` are the only valid square repdigits The last two digits of any repdigit>10 squared are two different values, except `8..8`: ``` n n^2 % 100 -------------- 1..1 21 2..2 84 3..3 89 4..4 36 5..5 25 6..6 36 7..7 29 8..8 44 9..9 01 ``` `88^2 = 7744`, and the last three digits of `8..8^2` is `544`. [Answer] # Mathematica, 11 bytes ``` #==4||#==9& ``` [Answer] # C#, JavaScript, Java, 12 bytes ``` n=>n==4|n==9 ``` For Java replace `=>` with `->`. Or a version more in the spirit of the challenge, C# only, for 61 bytes: ``` g=n=>n.Replace(n[0]+"","")=="" n=>g(n)&g(System.Math.Sqrt(n)) ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes ``` e4,9 ``` [Try it online!](https://tio.run/##y0rNyan8/z/VRMfy////lgA "Jelly – Try It Online") ~~Note: if you disprove me, I'll edit. This returns a truthy result only if the input is 4 or 9.~~ [Junghuan Min ninja'd a proof...](https://codegolf.stackexchange.com/a/125973/41024) [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes ``` 49S¹å ``` [Try it online!](https://tio.run/##MzBNTDJM/f/fxDL40M7DS///twQA "05AB1E – Try It Online") [Answer] # [APL (Dyalog)](https://www.dyalog.com/), 5 bytes Just tests for membership of {4,9} ``` ∊∘4 9 ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24RHHV2POmaYKFgCuQpGXGkKJkBsCcSGhgA "APL (Dyalog Unicode) – Try It Online") [Answer] # [Braingolf](https://github.com/gunnerwolf/braingolf), 19 bytes ``` .pl3e1:0|>e1:0|<+1- ``` [Try it online!](https://tio.run/##SypKzMxLz89J@/9fryDHONXQyqDGDkzaaBvq/v//3@xrXr5ucmJyRioA "Braingolf – Try It Online") This is as far as I can tell actually the shortest way to check "is `n` 4 **or** 9?" Will output `1` if input is `4` or `9`, otherwise will output `0` ## Explanation ``` .pl3e1:0|>e1:0|<+1- Implicit input from commandline args .p Duplicate, pop duplicate, push prime factors l3e If there are exactly 3 items in stack.. (2 prime factors plus original input) 1 ..Push 1 : Else 0 ..Push 0 | Endif > Move last item to start e If 2 prime factors are equal.. 1 ..Push 1 : Else 0 ..Push 0 | Endif < Move first item to end + Sum last 2 items 1- Subtract 1 Implicit output. ``` [Answer] # [PHP](https://php.net/), 22 bytes ``` <?=$argn==4||$argn==9; ``` [Try it online!](https://tio.run/##K8go@G9jX5BRwKWSWJSeZ6tkomTNZW8HFLOFCNia1NRAWZbW//8DAA "PHP – Try It Online") [Answer] # [Python](https://www.python.org), 18 bytes ``` lambda n:n in[4,9] ``` [Try it online!](https://tio.run/##HczLCoMwFIThVzm7k6AFb21V0BexWVhKqNAeJWaRPH066eJbDPzMEf17lzbZ6ZE@6/f5WklGoU2WrhxMsrujiEVLKJguM3Fxeqes2sSroLXOQcg5V1xyDQ200MEVbnCHHobc/MOajRnpcPkn6vQD) [Answer] # [Python 3](https://www.python.org), ~~39~~ 25 bytes Solution can be shorter for sure. old: ``` n=input();print(n in ['0','1','4','9']) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/P882M6@gtERD07qgKDOvRCNPITNPIVrdQF1H3RCITYDYUj1W8/9/AA) new: ``` print(input()in['4','9']) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EIzOvoLREQzMzL1rdRF1H3VI9VvP/fwA) --- From this: "a square repdigit is a repdigit that is the square of a different repdigit." Let z='ζζζζ...' be the square repdigit. **Case 1 z<10:** ~~0² = 0~~ ~~1² = 1~~ 2² = 4 3² = 9 4² to 9² are not square repdigits. **Case z>10:** Lets assume there is an y∈ℕ with y²=z and y='xxxxx..' We have just tested all single digits, so if there is an y with y² = z, then it has to be y>10. So we can write y = x[10°+10¹] + x[10²+10³+...] Then it is: y² = x²[10°+10¹]² + r = x² [10° + 2\*10¹] + r, with r only containing summands of power >1. Comparing z='ζζζ..' with y² we get: x²=ζ and 2x²=ζ, hence x=0. ⇒ The only square repdigits are ~~0,1,~~ 4 and 9. [Answer] # Javascript, 17 bytes ``` a=>!((a-4)*(a-9)) ``` ``` f= a=>!((a-4)*(a-9)) for (i=0;i<12;i++) console.log(''+i+' -> '+f(i)) ``` [Answer] # Batch, ~~65 58 53~~ 46 bytes I have code-copying issues. ``` @if %1 neq 4 if %1 neq 9 echo 0&exit/b echo 1 ``` Return 1 for truthy value, 0 for falsely value. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/26078/edit). Closed 9 years ago. [Improve this question](/posts/26078/edit) Your mission is to write a program that prints "Hello World!". Simple? The text must be human readable and should not be "|-| € |\_ |\_ 0 // 0 |? |\_ |) \./" or something like that. The program should not contain: * Newline character * Any characters in the string "Hello World!" including whitespace (whitespace outside strings is allowed) * Graphics (it must be run on text console (or master boot record in text mode) * Number constants that represent chars (Ascii-values, Hex chars) * Any simple tricks that create above numbers (ex. 36\*2 or 176/2-1 (72, ASCII code of "H") ) * Non-ASCII chars * Web request * User input * Over 1000 chars * Random numbers It can contain: * Ascii-art * system calls that do not return letters (a-z and A-Z) * h, e, l, o, w, r, d and ! chars outside strings or equal datatypes It is possible and allowed to change line by going over line max width (program must detect that itself). Linux command ``` stty size ``` may help. Fewer chars are better. Basically, write 'Hello World' in Ascii Art. [Answer] # Mathematica `n` is an integer (in base 10). `IntegerDigits[n, 2]` is a list of digits {0,1} that, when concatenated, represent `n` in base 2. `a=ArrayReshape[ IntegerDigits[n, 2], {19, 130}]` is the same digit list rearranged as a grid of 0's and 1's with the dimensions {19, 130}. `a/. {1 -> Style["b", 0], 0 -> Style["*", 16]}` replaces each 1 with "b" of font size 0 (hence it is invisible) and replaces each 0 with "\*" of font size 16. `Grid[%, Spacings-> 0]` tightly displays the array, with replacements. (`%` stands for the line of code just preceding.) ``` n = 35001712241657190367892609813472861877431771881809334927846103886350214620897333001318391750688831360911930936377842577561578307677143958805011717980866099960819297494949545473701708671861367649525697579614849813048033148938384921009819295565066663593631828895192249784580492554132824237605034894192899878952441264004931502456152233835512128208573340080592412541607535529943162874085478980356198477815840725568296012406592398594861031009108478191718964371749381682556005188569781665817649936105396104242935885784130227679335972626450197115544027612921177483696531170727698036575934297259107966503600164537149096917592511980213534973597038276657982204662616524347887277731541480128061438343931154467720012975561086600146498015257664764847849471; Grid[ArrayReshape[ IntegerDigits[n, 2], {19, 130}] /. {1 -> " ", 0 -> Style["*", 16]}, Spacings -> 0] ``` ![image](https://i.stack.imgur.com/GX1p7.png) [Answer] # J - 59 or 84 char Two versions, depending on how you define 'human-readable'. Any modifications to the resulting ASCII art would ultimately be based on this kind of compression scheme. ``` ,.'#'#~"0#:86235578437 123845917517 91625269844 92707043917 ,._45#&'#'"0\#:36761300340830444705259651524275206394141032533795647996053048645081x ``` The first version works by taking its list of numbers, expanding them into bitvectors (`#:`), using those to select (`#~`) how many '#' to take for each point (`"0`) in the matrix, and then running the result (a 2D matrix of strings of length at most 1) into a matrix of characters (`,.`). The second does the same thing, except it's shorter—by one character, mind you!—to pack all of its bitvectors into a single extended precision number, which you then take 45 bit cuts (`_45(blah)\`) of. Here's what they look like: [screenshot of jconsole running code http://i.snag.gy/XzYYa.jpg](http://i.snag.gy/XzYYa.jpg) [Answer] # Java generating the Strings only from a 0 as integer; 391 chars ``` class A{static int a=0,b=a++,e=a++,f=a/a;static char p(String s){return(char)Byte.parseByte(s,a);}public static void main(String[]z){long x=e,y=b;String c=((Long)x).toString(),d=((Long)y).toString();char l=p(c+c+d+c+c+d+d),m=p(c+c+d+d+c+d+c),o=(char)(l+a+f),_=p(c+d+d+d+d+d),$=_++;System.out.print(new char[]{p(c+d+d+c+d+d+d),m,l,l,o,$,p(c+d+c+d+c+c+c),o,(char)(o+a+f),l,(char)(m-f),_});}} ``` in that code the only literal variable is an Integer 0, the rest is made via Wizardry and other math tricks [Answer] # Bash + tr, 82 79 bytes ``` a=({q..s});a=${a[@]};s=${a:1:1};t${a:2:1} "[$s-~]" "[u-~][$s-v]"<<<Tqxx{,c{~xp- ``` Output: ``` $ a=({q..s});a=${a[@]};s=${a:1:1};t${a:2:1} "[$s-~]" "[u-~][$s-v]"<<<Tqxx{,c{~xp- Hello World! $ ``` ]
[Question] [ This is a little codegolf challenge from codingame.com. I was wondering how much Python3 code is necessary (but of course answers are not limited to Python3). **Input** The first line contains one positive integer n. The second line contains n positive integers. Each consecutive integers on the second line are separated by one space. There is no newline at the end of the second line. **Output** One line containing the sum of the squares of the numbers on the second input line, and no white space except an optional newline at the end. Each entry must be a complete program with input and output, not only a function. Shortest code wins. For example, input: ``` 5 1 2 5 7 8 ``` and output: ``` 143 ``` [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 5 bytes Code: ``` ²ð¡nO ``` Explanation: ``` ² # Take the second input, the first input is ignored ð¡ # Split on spaces n # Square each element O # Take the sum and implicitly output it ``` Uses **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=wrLDsMKhbk8&input=NQoxIDIgNSA3IDg) [Answer] ## Python 3, 52 ``` i=input;print(sum(int(d)**2for d in i(i()).split())) ``` [Answer] # Jelly, 5 bytes ``` ṣ⁶V²S ``` [Try it online.](http://jelly.tryitonline.net/#code=4bmj4oG34bmq4bmj4oG2VsKyUw&input=&args=NQoxIDIgNSA3IDg) Input format is rather annoying.... ## Explanation ``` ṣ⁶V²S ṣ⁶ split by space V map eval over the resulting list -- the newline in the first element causes the first line to be treated as a separate link and ignored ² map square over the list S sum ``` [Answer] ## [Minkolang 0.15](https://github.com/elendiastarman/Minkolang), 9 bytes ``` n[n2;+]N. ``` [Try it here!](http://play.starmaninnovations.com/minkolang/?code=n%5Bn2%3B%2B%5DN%2E&input=5%0A1%202%205%207%208) ### Explanation ``` n Take number from input [ ] Pop top of stack and repeat that many times n Take number from input 2; Square it + Add to top of stack N. Output as number and stop. ``` [Answer] ## CJam, 10 bytes ``` l;l~]2f#1b ``` [Test it here.](http://cjam.aditsu.net/#code=l%3Bl~%5D2f%231b&input=5%0A1%202%205%207%208) ### Explanation ``` l; e# Read first line and discard. l~ e# Read second line and evaluate, dumping all integers on the stack. ] e# Wrap them in an array. 2f# e# Square each. 1b e# Sum. ``` [Answer] # Python 3, 54 bytes *-[] thanks to shooqie* ``` print(sum(int(i)**2for i in input(input()).split())) ``` Takes input as specified in the first version of the question. So to answer your question: Not a lot. [Answer] # [MATL](https://esolangs.org/wiki/MATL), 6 bytes ``` xjU2^s ``` [**Try it online!**](http://matl.tryitonline.net/#code=eGpVMl5z&input=NQoxIDIgNSA3IDg) ``` x % take first input and throw it away j % take second input as a string U % convert to array with those numbers 2^ % element-wise square s % sum of array ``` [Answer] # R, 22 bytes Nothing very flash, handles the input as specified ``` cat(sum(scan()[-1]^2)) ``` Test run ``` > cat(sum(scan()[-1]^2)) 1: 5 2: 1 2 5 7 8 7: Read 6 items 143 > ``` [Answer] ## [Pyke](https://github.com/muddyfish/PYKE), 10 bytes ``` ;\ cFE2^)s ``` Takes input as requested [Try it here](http://pyke.catbus.co.uk/?code=%3B%5C+cFE2%5E%29s&input=5%0A1+2+5+7+8) (Yay setup a try-it page!) Or 5 bytes if allowed a list of ints: ``` 2Rm^s ``` Or noncompeting (add squared node), 3 bytes ``` mXs ``` [Answer] ## Lua, ~~74~~ 62 Bytes **Edit: saved 8 bytes due to @KennyLau** It's quite straigthforward, skip the first line and iterate over the group of digits in the second. ``` i,x=io.read,0i()i():gsub("%d+",function(d)x=x+d*d end)print(x) ``` ### Ungolfed ``` x=0 i=io.read i() i():gsub("%d+",function(d) x=x+d*d end) print(x) ``` [Answer] # Octave, 45 bytes Octave is not exactly designed for accepting random input formats. For instance, input over multiple lines is impossible. Also, numbers can't be entered as a list unless you have brackets. For that reason, the input must be taken as a string. ``` input('');disp((x=str2num(input('','s')))*x') input('') % Take the first input line and discard input('','s') % Take the second input as a string x=str2num(input('','s')) % Convert the string to a list of numbers, x (x=str2num(input('','s')))*x' % Multiply x by x transposed % This is equivalent to sum(x.^2) but shorter disp((x=str2num(input('','s')))*x') % Display the result ``` Call it like this: ``` input('');disp((x=str2num(input('','s')))*x') 5 1 2 5 7 8 143 ``` [Answer] # C,65 bytes ``` j,k;main(i){for(;scanf("%d",&i)+1;j++&&(k+=i*i));printf("%d",k);} ``` [Answer] # Pyth, 10 bytes ``` sm^sd2ce.z ``` [Try it here!](http://pyth.herokuapp.com/?code=sm%5Esd2ce.z&input=5%0A1%202%205%207%208&debug=0) Takes input in the exact same format as specified in the challenge. ### Explanation ``` sm^sd2ce.z # .z = input lines e.z # only take the last line c # split on spaces m # map each number d sd # convert to integer ^ 2 # square s # sum all squares ``` ### Alterntive solutions with more generous input formats **8 bytes** if I may omit the number count: ``` sm^sd2cz ``` [Try it here!](http://pyth.herokuapp.com/?code=sm%5Esd2cz&input=1+2+5+7+8&debug=0) **4 bytes** if I may take the input as list of integers: ``` s^R2 ``` [Try it here!](http://pyth.herokuapp.com/?code=s%5ER2&input=%5B1%2C2%2C5%2C7%2C8%5D&debug=0) [Answer] ## Pyth, 9 bytes ``` s^R2re.z7 ``` [Try it here](http://pyth.herokuapp.com/?code=s%5ER2re.z7&input=1+2+5+7+8&debug=0) Or 7 bytes if allowed to omit line 1 ``` s^R2rz7 ``` [Answer] ## Haskell, 48 bytes ``` main=interact$show.sum.map((^2).read).tail.words ``` How it works: ``` interact read whole input, pass it to a function and print it's return value. The function is: words split at whitespace into words tail drop first element (the number on line #1) map( ) convert each word read to integers (^2) and square sum sum all values show convert back to string ``` [Answer] # [GS2](https://github.com/nooodl/gs2), 5 [bytes](https://en.wikipedia.org/wiki/Code_page_437) ``` W",Φd ``` [Try it online!](http://gs2.tryitonline.net/#code=VyIszqZk&input=NQoxIDIgNSA3IDg) ### How it works ``` W Find all numbers in the input; push a list. " Discard the first number. , Square. Φ Map the last instruction over the list of numbers. d Compute the sum of all squares. ``` [Answer] # [J](http://www.jsoftware.com/help/learning/contents.htm), 4 bytes + 100 ``` +/*: ``` [Try it](http://tryj.tk/). ``` +/*:1 2 5 7 8 143 ``` A +100 punishment in the byte-count to myself for not having standard input. [Answer] # Japt, 8 bytes ``` Ns1 mp x ``` Try it in the [Japt Interpreter](http://ethproductions.github.io/japt?v=master&code=TnMxIG1wIHg=&input=NQoxIDIgNSA3IDg=). ### How it works The code is parsed as ``` N.s(1).m(p).x() ``` * `N` is a variable; it contains the parsed input. * `s(1)` discards the first array element. * `m(p)` maps `p` (square) over the remaining array. * `x()` computes the sum of the array of squares. [Answer] # [Pylongolf2](https://github.com/lvivtotoro/pylongolf2), 8 bytes ``` c| n²+~ ```   ``` c - read the input | - split by space (note the 1 space after |) n - convert all of that in the list to numbers ² - Square everything in the list + - Sum everything in the list ~ - Print it ``` [Answer] ## Batch, 76 bytes ``` @set/px= @set/px= @set t=0 @for %%n in (%x%)do set/at+=%%n*%%n @echo %t% ``` [Answer] # [GolfScript](http://www.golfscript.com/golfscript/), 13 bytes Input is extremely easy for GolfScript. ``` ~](;{.*}%{+}* ``` [Try it online!](https://tio.run/##S8/PSStOLsosKPn/vy5Ww7paT6tWtVq7Vuv/f1MuQwUjBVMFcwULAA "GolfScript – Try It Online") ## Explanation ``` ~ # Take & Evaluate the input ] # Wrap the whole input into a list (; # Remove the first item {.*}% # Map with squaring {+}* # Reduce by summation ``` [Answer] # [JavaScript (V8)](https://v8.dev/), 38 bytes ``` x=>Math.hypot(...x.match(/\s\d+/g))**2 ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNEts/ifZvu/wtbON7EkQy@jsiC/RENPT69CLzexJDlDQz@mOCZFWz9dU1NLy@h/QVFmXolGmoaScUyeqYKZgrmChZKm5n8A "JavaScript (V8) – Try It Online") [Answer] # [Thunno 2](https://github.com/Thunno/Thunno2) `S`, 4 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md) ``` sON² ``` [Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faGm0UrBS7IKlpSVpuhZLi_39Dm1aUpyUXAwVWbDalMtQwUjBVMFcwQIiBAA) With normal I/O it would be **1 [byte](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)** (with `S` flag): ``` ² ``` [Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faGm0UrBS7IKlpSVpuhaLDm1aUpyUXAzlLlgfbaijYKSjYKqjYK6jYBELEQYA) #### Explanation ``` sON² # Implicit input s # Discard the first input O # Split the second input on spaces N # Convert each string to a number ² # Square each number # Implicit output of the sum ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/240282/edit). Closed 2 years ago. [Improve this question](/posts/240282/edit) The challenge is simple: Print the first and last element of a list and print them # Rules: * You will take only 1 line of input, and that is the list (e.g. `[1, 5, 6, 4, 2]`) * You are allowed to print the 2 numbers in any order with or without spaces between them * Output the 2 numbers on 1 line and the remaining list on the second line A simple example is `print(list.pop()+list.pop(0))` in Python3, since pop removes the element and returns it at the same time This is [code-golf](https://codegolf.stackexchange.com/questions/tagged/code-golf), so shortest code wins! [Answer] # [Vyxal](https://github.com/Vyxal/Vyxal) `aṠj`, 8 bytes ``` ₌₍htḢṪWṠ ``` [Try it Online!](https://vyxal.pythonanywhere.com/#WyJh4bmgaiIsIiIsIuKCjOKCjWh04bii4bmqV+G5oCIsIiIsIjFcbjJcbjNcbjRcbjUiXQ==) [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes ``` Ḣ³ṪṄṛ ``` [Try it online!](https://tio.run/##AScA2P9qZWxsef//4biiwrPhuarhuYThuZv///9bMSwgNSwgNiwgNCwgMl0 "Jelly – Try It Online") [Answer] # JavaScript (ES6), 25 bytes ``` a=>alert(a[0]+''+a.pop()) ``` ``` f= a=>alert(a[0]+''+a.pop()) console.log(f([1,2,3,4,5])) ``` [Answer] # [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 9 bytes ``` (?=,).*, ``` [Try it online!](https://tio.run/##K0otycxL/P9fw95WR1NPS4fr/39DHVMdMx0THSMA "Retina 0.8.2 – Try It Online") Explanation: Just removes the commas and anything in between. The lookahead deals with the case when there are only two elements in the list. ]
[Question] [ **This question already has answers here**: [The alphabet in programming languages](/questions/2078/the-alphabet-in-programming-languages) (156 answers) Closed 10 years ago. You have to output the alphabet (upper case) with the shortest code possible. Exact output expected : `ABCDEFGHIJKLMNOPQRSTUVWXYZ` [Answer] # APL, 2 chars ``` ⎕A ``` It's a constant string with the uppercase letters from A to Z [Answer] ## Python 35 chars ``` print("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ``` [Answer] **BASH 21 chars** ``` echo {A..Z}|tr -d " " ``` Output: ``` ~$ echo {A..Z}|tr -d " " ABCDEFGHIJKLMNOPQRSTUVWXYZ ``` [Answer] ## R, 19 ``` cat(LETTERS,sep="") ``` Output: ``` ABCDEFGHIJKLMNOPQRSTUVWXYZ ``` [Answer] **Ruby 2.0.0, bytesize: 19:** ``` => p([*'A'..'Z'].join) => "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ``` **update. this produce without quotes:** ``` => ruby -e '$><<[*?A..?Z].join' => ABCDEFGHIJKLMNOPQRSTUVWXYZ ``` [Answer] ## Delphi ### 52 bytes ``` var i:int16;begin for i:=65to 90do write(chr(i))end. ``` ### 45 bytes ``` begin write('ABCDEFGHIJKLMNOPQRSTUVWXYZ');end. ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/233591/edit). Closed 2 years ago. [Improve this question](/posts/233591/edit) I want you to make a gui window like this: [![Small window containing the text "Hello, World" and a "quit" button](https://i.stack.imgur.com/MJxJY.jpg)](https://i.stack.imgur.com/MJxJY.jpg) \* if you're thinking, the [quit] button closes the window in any language using minimum "different" characters.. AND remember that the gui window must use native widgets instead of custom icons and buttons like I have Windows 8, so my GUI window looks like this: [![Small window containing the text "Hello, World" and a "quit" button](https://i.stack.imgur.com/MJxJY.jpg)](https://i.stack.imgur.com/MJxJY.jpg) ### If you didn't understand what i mean by 'minimum "different characters"'.. I meant, like this hello world code: ``` print("Hello, World!") ``` has these characters: ``` ()",! HWdeilnoprt ``` total 17 different characters.. likewise, make a gui window with native widgets of your OS in any language using least "different" characters.. The same gui window in python (tkinter used here) will be: ``` import tkinter as tk from tkinter import ttk root = tk.Tk() label = tk.Label(root,text='Hello, World') label.pack() button = ttk.Button(root,text='quit', command= root.quit) button.pack() root.mainloop() ``` with a total of 32 different characters NOTE: case-sensative (A != a), all characters like "\n", "\t", "\b", " ", etc. are counted.. use any language... python, java, js, css, html, ts, brainfk, ada, lua, blah.. blah.. blah.. [Answer] # [Befunge-98](https://git.catseye.tc/Funge-98/blob/master/doc/funge98.markdown) + zenity, 3 unique characters (9246 characters total) ``` 111-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1--111-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1--111-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-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1-1-1--111-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1--11-11-111-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1--111--11-pp ``` [Try it online!](https://tio.run/##7dk9DoAwCIbhEzGw6XVMajfTxfNj6hk6lI837spTkP5d7X6f3uw8ItzdajymSLU6@UuCXRCkcFKlaCIYCQb/DONWa2bMWxb7TJFLXiNUaXRRmADZUJAOWiI0MAnWX8YJJmQwbE45v6WQ4XDxRYOhjKGCggcmE9vmt32Dkf9DmKGMEfEB "Befunge-98 (FBBI) – Try It Online") (won't actually show a GUI window because TIO doesn't have zenity installed) This program should be portable to any Befunge-98 installation where `=` runs shell commands (which is most of them), and where `zenity` is the shell command for running zenity (the usual configuration when you have it installed, as it's meant to be run from a shell). I didn't write this program by hand; I generated it with [this Jelly program](https://tio.run/##y0rNyan8//9RwxxD3UcNcx/u6rYGskFMkJAhkLbmOrTZP9Q62sxQxwAIzUx0gIzYw@2PmtZY64MUFxQAVf3//78qNS@zpFJBVzczLy0fSJWkVpQoKHkALcjXUSjPL8pJUVQCCudn6@YkJqXmKASWZpYAAA "Jelly – Try It Online"), which I did write by hand. ## Explanation None of the usual suspects that are Turing-complete off 1 or 2 unique characters seem to have GUI or shell support, but you can do it in three. This actually mostly isn't a translation of arbitrary Befunge into the `1-p` universal character set; `1-` let us put arbitrary data on the stack directly using arithmetic, so we use that to put the ASCII codes of the shell command to run onto the stack (with the start of the string at the top of the stack, as is the usual Befunge convention), and simply use the universal `1-p` encoding to generate a very small program `=@` that runs our shell command (`=`) and exits (`@`). (The `=@` are placed into the top-left corner of the playfield, overwriting the start of the program, and run when the pointer wraps back around. We can do this with `1-p` because `1-` are sufficient to encode any number arithmetically, as \$1-(1-1-\cdots-1)\$, and we can use those numbers as arguments to `p` to place an arbitrary character anywhere on the playfield, which will be interpreted as a command if the instruction pointer runs into it. Befunge uses reverse-polish notation, so the equations are encoded as `111-1-1-…1--`.) The zenity command used here is: ``` zenity --info --text "Hello, world!" --ok-label Quit ``` This basically just shows a simple dialog box, with the text and the button label overridden. (zenity is a program intended for showing dialog boxes, like the one the question asks for. It's designed to be run from shell scripts, but you can run it from zenity just as easily.) [Answer] # HTML, 24 unique characters, 50 bytes ``` Hello, world!<button onclick=document.write``>quit ``` I hope this counts. This isn’t a popup window, it’s a website but it’s close enough I guess. The quit button removes all text from the website. Closing the tab seems like a better idea but that takes more code (I think so, a least) I had to use JS template literals in the document.write because `document.write()` increases the unique character count because of the closing bracket. I wonder if html entities can help decrease the count. [Try it on JSFiddle](https://jsfiddle.net/uj9cs1e0/) Technically you haven’t stated that I have to use the ‘!’ in the hello world, so that would decrease both the counts by 1. Also I can change the button tag into something else like h5 because buttons aren’t the only tags where onclick events work. (But buttons are the only html tags that actually look like buttons as far I have searched) (using h5 doesn’t decrease the unique character count) [Answer] # PowerShell, 35 unique characters, 378 bytes ``` add-type -assemblyname system.windows.forms $f=new-object system.windows.forms.form $p=new-object system.windows.forms.tablelayoutpanel $f.controls.add($p) $l=new-object system.windows.forms.label $l.text="Hello, World" $p.controls.add($l,$false,$false) $b=new-object system.windows.forms.button $b.text="quit" $p.controls.add($b,$false,$true) $f.cancelbutton=$b $f.showdialog() ``` I used a table layout panel to add the button and label because positioning them manually would have required digits thus increasing the character count. Apart from newline and space, the 33 other characters required are `"$(),-.=HWabcdefghijlmnopqrstuwxy`. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/83320/edit). Closed 7 years ago. [Improve this question](/posts/83320/edit) ## Description Your task is to take a string as input, and convert the first letter of each word to uppercase, and the rest to lowercase. ## Test Cases `Input` => `Output` `ISN'T THIS A REALLY COOL TEST CASE???` => `Isn't This A Really Cool Test Case???` `tHis iS A rEALLY WeiRd SeNTEncE` => `This Is A Really Weird Sentence` `I Like This Sentence` => `I Like This Sentence` ### Edit: no built-ins allowed. --- This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so lowest byte count wins. Good luck! [Answer] # [V](https://github.com/DJMcMayhem/V), ~~14~~ 8 bytes ``` gu$ògUlW ``` [Try it online!](http://v.tryitonline.net/#code=Z3Ukw7JnVWxX&input=SVNOJ1QgVEhJUyBBIFJFQUxMWSBDT09MIFRFU1QgQ0FTRT8_Pw) Explanation: ``` gu$ #Make everything lowercase ò #Recursively gUl #Make the current character uppercase W #And move forward a word ``` Here is a 9-byte, non-competing version (the old interpreter had a bug): ``` gu$Ó¼÷/Õ° ``` This version is just a regex: ``` gu$ #Make everything lowercase Ó¼÷/Õ° #Expands into ':s/\<\w/\U\0/g` ``` [Answer] # [s-lang](http://dgrissom.com/s-lang/), 7 bytes (Non-competing) ### [Try it here!](http://dgrissom.com/s-lang/index.html?w[%20]Cc!) ``` w[ ]Cc! ``` ## Explanation: * `w[ ]` splits the input string by spaces * `C` converts the selection (which is now the split-up words) to lower-case * `c!` `c` converts the selection to upper-case, but since it uses the parameter `!`, it only converts the first letter of each range of characters in the selection (which are words since we split by spaces) [Answer] # Pyth, 6 bytes ``` ~~jdm+rhd1rtd0c~~ jdrR4c ``` [Test suite.](http://pyth.herokuapp.com/?code=jdrR4c&test_suite=1&test_suite_input=%22ISN%27T+THIS+A+REALLY+COOL+TEST+CASE%3F%3F%3F%22%0A%22tHis+iS+A+rEALLY+WeiRd+SeNTEncE%22%0A%22I+Like+This+Sentence%22&debug=0) Split into words, capitalize each, then join by space. It is not a built-in, because `capitalize` converts `test case` into `Test case` instead of `Test Case`. ### (with built-ins) ``` r5 ``` [Test suite.](http://pyth.herokuapp.com/?code=r5&test_suite=1&test_suite_input=%22ISN%27T+THIS+A+REALLY+COOL+TEST+CASE%3F%3F%3F%22%0A%22tHis+iS+A+rEALLY+WeiRd+SeNTEncE%22%0A%22I+Like+This+Sentence%22&debug=0) [Answer] # Ruby, 29 bytes ``` gets.gsub(/\S+/,&:capitalize) ``` I'm still learning ruby though >\_> [Answer] ## Pyke, 5 bytes ``` cml5J ``` [Try it here!](http://pyke.catbus.co.uk/?code=cml5J&input=SN%27T+THIS+A+REALLY+COOL+TEST+CASE%3F%3F%3F) Split, map caps, join [Answer] # Retina, 19 bytes ``` T`L`l T`l`L`(^|\s). ``` [Try it online!](http://retina.tryitonline.net/#code=VGBMYGwKVGBsYExgKF58XHMpLg&input=SVNOJ1QgVEhJUyBBIFJFQUxMWSBDT09MIFRFU1QgQ0FTRT8_Pwp0SGlzIGlTIEEgckVBTExZIFdlaVJkIFNlTlRFbmNFCkkgTGlrZSBUaGlzIFNlbnRlbmNl) [Answer] # Python, ~~51~~ bytes 3 bytes thanks to xnor. ``` ~~lambda n:' '.join(a.capitalize()for a in n.split())~~ lambda n:' '.join(map(str.capitalize,n.split())) ``` [Ideone it!](http://ideone.com/OWLkmD) ### using built-in, 28 bytes ``` from string import* capwords ``` [Ideone it!](http://ideone.com/0KuP81) ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/2752/edit). Closed 9 years ago. [Improve this question](/posts/2752/edit) Where input is binary, convert it to a decimal number (base 10), reverse the decimal number and output it. Vice versa for decimal (base 10) input: reverse it, convert it to binary and output the binary number. **Sample Input**: ``` 00000001 00000010 255 00011000 ``` **Sample Output** ``` 1 2 1000101000 42 ``` other **Sample Input** ``` 78 35 01011001 231 ``` other **Sample Output** ``` 01010111 00110101 98 10000100 ``` [Answer] ## Ruby, 68 characters ``` puts$<.map{|i|i[/[^01\s]/]?"%08b"%i.reverse: i.to_i(2).to_s.reverse} ``` Uses stdin/stdout, interprets lines that consist only of 1s, 0s and whitespace as binary numbers, everything else as decimal. [Answer] # perl - 90 89 ``` map{print reverse(/^[01]+$/?unpack"N",pack"B*",sprintf"%032d",$_:sprintf"%b",$_).$/}@ARGV ``` Any number containing only 1's and 0's is considered binary. Funny how so much more code is required for bin->dec vs. dec->bin... [Answer] ## JavaScript, ~~140~~ 199 bytes ``` (function(x){s=x.split("\n"),r=b='';for(i in s)r+='\n'+(s[i].replace(/[01]*/g,b)? (s[i].split(b).reverse().join(b)-0).toString(2):(parseInt(s[i],2)+"") .split(b).reverse().join(b));return r.trim()})('1\n10\n255\n11000') ``` Excluding input. It requires, however, that there are no numbers present in the input which are base 10 and only have `1`s / `0`s in them. [Answer] # Python - 117 characters ``` while 1: x=raw_input() if(not(False in map(lambda x:x in ("1","0"),s))):print int(x,2) else:print bin(int(x))[2:] ``` This golf relies heavily on the fact that python counts a single space as a full indentation. Note that this golf IS NOT ERROR-PROOF. While functional, it will throw an EOFError when there is no input. Protecting against this requires an extra 30 characters. # Changelog **v0** - 120 chars **v1** - 117 chars - changes "While True" to "While 1" [Answer] Quite frankly, i still don't get the testcase for `255`, i'll mend my solution when the OP corrects/expands the description. My Solution is based of *rmckenzie* ### Python - 84 bytes ``` while 1: x=raw_input() print all(i<"2"for i in x)and int(x,2)or bin(int(x))[2::] ``` [Answer] ### bash 67 ``` b(){ [[ $1 =~ ^[01]*$ ]]&& s="i"||s="o";echo $s"base=2;$1"|bc|rev;} ``` [Answer] ## J, 60 characters ``` ((1&":@#:@(10&#.@|.)`(|.@":@#.))@.(0=[:+/1<[))".;' ',.1!:1[1 ``` ]
[Question] [ Your task will be to write a Haskell function that takes a list of integers and returns a sorted version of the same list. You are to do this without the use of builtins ## What are builtins? To keep ourselves from having to navigate edge case hell we are going to limit answers to Haskell (sorry if Haskell is not your favorite language). We are going to define a builtin as any named function that is not defined in your code. We are going to say that symbolic operators, `(+)`, `(:)`, etc. are not builtin functions. This applies both to prelude and any libraries that are imported. ## What does it mean to use? Before anyone tries to get smart with me, using a function is using a function. Whether or not the function is named in your source code is irrelevant (this is not [restricted-source](/questions/tagged/restricted-source "show questions tagged 'restricted-source'")), if you make calls to the function without naming it that is also considered cheating. That being said calls to a function are not the only form of use, you shouldn't name a builtin function in your code even if you don't call it (I don't know why you would want to do that but I'm not taking any risks). ## Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so you should aim to do this in as few bytes as possible. However since different algorithms are not going to be competitive, (merge sort answers are probably going to be longer than insertion sort answers) I would like this to be considered a competition among individual algorithms, just as normal code golf is a competition among individual languages. For that reason I would like you to name your algorithm used in your header instead of the language. If you don't know the name feel free to put **Unknown**. [Answer] ## Haskell, ~~57~~ ~~56~~ ~~37~~ 33 bytes ``` f l=[y|x<-[minBound..],y<-l,y==x] ``` Feed it with `Int`s, e.g. `f [1::Int,2,3]`. A port of [my answer](https://codegolf.stackexchange.com/a/77848/34531) from the other sort without builtin challenge which supports also lists with repeated values. Edit: @Ørjan Johansen saved 4 bytes. Thanks! [Answer] # Mergesort, 110 bytes ``` x@(a:r)#y@(b:s)|a<b=a:r#y|1<3=b:x#s r#s=r++s (x:r)!(a,b)=r!(b,x:a) _!t=t s[x]=[x] s l|(a,b)<-l!([],[])=s a#s b ``` [Try it online!](https://tio.run/##HYpBCsIwEADvecWWeEjoFqy1iqEL/UcIkoCgGItke0ihf4/Bw8AwzNPz@xFjKXlW3iQtt1kFw3r3U6Aa5Lb300DBZMkiSabUtixUrmujPAZNqVEBs/Fa3JuVVsE2O6oIhrj/l6mLjbIOrdPE4CVDKB//WoDgm17LCgdgsANesMduxCPexupdP5zxdHXlBw "Haskell – Try It Online") Example usage: `s [4,1,26,-3,0,5]`. `#` takes two sorted lists and merges them. `!` splits a list in two sublists of equal length. `s` returns singleton lists unchanged because they are already sorted and sorts longer lists by splitting them in two parts, recursively sorts both and merges the resulting lists. [Answer] # Insertion Sort, 44 bytes ``` s!(a:b)|a<s=a:s!b s!x=s:x f(a:x)=a!f x f a=a ``` [Try it online!](https://tio.run/##y0gszk7Nyfn/v1hRI9EqSbMm0abYNtGqWDGJq1ixwrbYqoIrDShRoWmbqJimAOQoJNom/s9NzMyzLSjKzCtRSYu20DHTMdIxBGNjHRMdXaPY/wA "Haskell – Try It Online") Since [nimi has already outgolfed me](https://codegolf.stackexchange.com/a/131492/56656) I thought I would post the solution I came up with to my own challenge. ## Explanation Here we define a function `(!)` that takes a sorted list and inserts an element so that the list is still sorted. ``` s!(a:b)|a<s=a:s!b s!x=s:x ``` We then define a function `f` that takes sieves the elements of a list into this function. (basically the equivalent of a `foldr`). ``` f(a:x)=a!f x f a=a ``` Since the empty list is sorted, and each insertion keeps the list sorted, the end result is a sorted list with all the same items as the original. This algorithm is **O(n2)**. [Answer] ## Quicksort (sort of), 44 bytes ``` s(h:t)=s[e|e<-t,e<=h]++h:s[e|e<-t,e>h] s x=x ``` [Try it online!](https://tio.run/##y0gszk7Nyfn/v1gjw6pE07Y4OrUm1Ua3RCfVxjYjVls7wwohYpcRy1WsUGFb8T83MTNPwVahoCgzr0RBRaFYIdpExwgIDXXMdUxi/wMA "Haskell – Try It Online") How it works: ``` s(h:t)= -- let h be the head and t the rest of the input list [e|e<-t,e<=h] -- take all elements e from t that are less or equal than h s -- and sort them recursively ++ h : -- append h and append [e|e<-t,e>h] -- all elements from t greater than h s -- after sorting them s x=x -- base case: if there's no first elemet, i.e. the list -- is empty, the result is also the empty list ``` [Answer] Here's a shorter merge sort, bottom up, called `s`. `((:[])<$>)` divides up the list into singletons (turning `"Joe"` into `["J","o","e"]`). `d` merges adjacent pairs of lists, using the basic merge function `!`. `f` iterates `d` until there's only one list. # Merge sort, 99 bytes ``` s=f.((:[])<$>) a@(x:y)!b@(z:w)|x>z=z:a!w|0<1=x:y!b a!b=a++b d(x:y:z)=x!y:d z d p=p f[x]=x f x=f$d x ``` [Try it online!](https://tio.run/##FcrRCoIwFIDh@z3FGXix4QzNLBoe8T3Ei401kkwkA4/Dd19298P3P83yeoxjjAv6kxC662WdNJKZVpDeJLetCHqVOzUBgzZ83fO6wIO4ZYZbNGlqmfu/OkgkvmkHgTmYcWa@ox6JeSD0iQOKbzNMgDB/hukLCSzQleqqCpVVKlf36uisKC/qfOvjDw "Haskell – Try It Online") ]
[Question] [ This is a very simple challenge, and it is to print the numbers `-1`, `0`, and `1`. *The following paragraph is credited to [Print numbers from 1 to 10](https://codegolf.stackexchange.com/questions/86075)* Your output format can be whatever your language supports. This includes arbitrary separators (commas, semicolons, newlines, combinations of those, etc., but no digits), and prefixes and postfixes (like `[...]`). However, you may not output any other numbers than -1 through 1. Your program may not take any input. Standard loopholes are disallowed. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins. Happy golfing! [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes ``` -r1 ``` [Try it online!](https://tio.run/##y0rNyan8/1@3yPD/fwA "Jelly – Try It Online") ``` 1r- ``` [Try it online!](https://tio.run/##y0rNyan8/9@wSPf/fwA "Jelly – Try It Online") ``` -ŒR ``` [Try it online!](https://tio.run/##y0rNyan8/1/36KSg//8B "Jelly – Try It Online") ``` 1ŒR ``` [Try it online!](https://tio.run/##y0rNyan8/9/w6KSg//8B "Jelly – Try It Online") ``` Ø-Ż ``` [Try it online!](https://tio.run/##y0rNyan8///wDN2ju///BwA "Jelly – Try It Online") ``` Ø+Ż ``` [Try it online!](https://tio.run/##y0rNyan8///wDO2ju///BwA "Jelly – Try It Online") ``` -rN ``` [Try it online!](https://tio.run/##y0rNyan8/1@3yO//fwA "Jelly – Try It Online") ``` 1rN ``` [Try it online!](https://tio.run/##y0rNyan8/9@wyO//fwA "Jelly – Try It Online") ``` 2Ż’ ``` [Try it online!](https://tio.run/##y0rNyan8/9/o6O5HDTP//wcA "Jelly – Try It Online") ``` 3Ḷ’ ``` [Try it online!](https://tio.run/##y0rNyan8/9/44Y5tjxpm/v8PAA "Jelly – Try It Online") and a bonus one: # [M](https://github.com/DennisMitchell/m), 2 bytes ``` -R ``` [Try it online!](https://tio.run/##y/3/Xzfo/38A "M – Try It Online") [Answer] # [Pyt](https://github.com/mudkip201/pyt), 4 [bytes](https://github.com/mudkip201/pyt/wiki/Codepage) ``` 3ř⁻⁻ ``` [Try it online!](https://tio.run/##K6gs@f/f@OjMR427gej/fwA) Explanation: ``` 3 Push 3 ř Push [1,2,3] ⁻⁻ Decrement twice Implicit print ``` [Answer] # [R](https://www.r-project.org/), 9 bytes ``` cat(-1:1) ``` [Try it online!](https://tio.run/##K/r/PzmxREPX0MpQ8/9/AA "R – Try It Online") [Answer] # [7](https://esolangs.org/wiki/7), 11 characters, 4 bytes ``` 1**7**3**7**00**7**4023 ``` [Try it online!](https://tio.run/##M///39Dc2NzAwNzEwMj4/38A "7 – Try It Online") Hexdump to prove byte count: ``` 00000000: 3df0 3c09 =.<. ``` This challenge is very easy in most languages, so I decided to solve it in a language where it's actually an interesting problem. ## Explanation It took me ages to golf this down to 4 bytes – there are a really huge number of ways to do this with 12 characters, but reaching 11 is very difficult. The only part of the code here that actually runs (after the first cycle, which just sets up the stack to mirror the structure of the program) is **`4623`** (which is the code generated by the code `4023` in the original program; the `4023` is a literal which pushes **`4623`** to the stack; as usual, I'm using non-bold for commands that just push code to the stack and bold for the commands they push). After the first cycle, each new cycle runs the top stack element, without actually popping it from the stack. The **`4`** swaps the top two stack elements, and inserts a blank element between them (thus, *a* *b* goes to *b* *blank* *a*). Then the **`6`** analyzes the top element to determine what source code is most likely to have produced it, and appends the resulting source code to the element below it (which will be blank at this point because we just ran a **`4`**). Thus, the net effect of **`46`** is to swap the top two stack elements, and replace the top stack element with (a guess at, but the guesses are always correct for this program) the source code that produced it. **`2`** duplicates the top stack element, and **`3`** outputs the top stack element, popping both it and the element below. Thus, the net effect of **`23`** is to output and pop the top stack element, without disturbing elements below it. As such, the effect of our program **`4623`** is to pop and output the source code that produced the second stack element, whilst leaving the top stack element unchanged. The top stack element in question is the actively running program (which doesn't get popped when we start to run it), so once the program finishes running, it'll just run again, etc. – this is in effect an infinite loop which, for each element on the stack, outputs the source code that produced it (and eventually the program crashes due to stack exhaustion). As such, the data being given to the output routines is `00`, `3`, `1` (i.e. the sections of the *source code* in between **`7`**s – the source code has already run to produce runnable code by this point, but the source is reconstructed from the runnable code rather than the runnable code actually being run). The first `0` sent to the output routine selects numerical output mode. Then, `0`, `3`, `1` get output. The numerical value of a string in 7 is the total number of `1` and **`7`** characters it contains, minus the total number of `0` and **`6`** characters it contains. Thus, the values of these strings are -1, 0, and 1, as required by the question. One complication is that if we try to output an empty string, we just get no output, rather than its numerical value of 0 being output: this is a special case needed because the output command **`3`** is the primary way to pop and discard stack elements (basically, you push an empty element above the one you want to pop, output that empty element and pop the element below as a side effect). A "clean" way to output 0 thus requires outputting a string like `01` which is nonempty and has a numerical value of zero. This program uses `3`, which is shorter, but the numerical output formatter will append a comma when outputting strings ending `3` (in addition to outputting their numerical value). As a consequence, the output of the program is actually `-1 0, 1`, but this is permitted by the question. (All eight of the one-character strings either have a side effect when output via the numerical formatter, or else have a value different from zero, so outputting `-1 0 1` exactly would make the program longer.) [Answer] # JavaScript, ~~19~~ 15 bytes ~~`[-1,0,1].map(alert)`~~ `alert([-1,0,1])` [Answer] # Python - 15 bytes ``` print("-1 0 1") ``` I would say "Good luck improving this.", but past experience has taught me never to assume: though, this won't be easily beat (for i in range(3), %ding the spaces and %sing the 1s are all overweight, so you can eliminate those.) ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/117128/edit). Closed 6 years ago. [Improve this question](/posts/117128/edit) # Challenge Given a number `x`, output the first `x` powers of two, starting with 2¹ (2). ### Example ``` 2 2 4 3 2 4 8 1 2 6 2 4 8 16 32 64 ``` You may output numbers separated by non-numerical characters. You may not just output them mashed together like `248163264128`. # Rules * In your code, you may only use the number `2`. You may not use any other numbers, either as ASCII characters or numeric literals in any base. + You may not use character literals as integers to bypass this rule. * You may not use your language's built-in exponentiation function, operator, or similar. You must implement the exponent yourself. + You may not use bit shifting operators. + You may not use operations that are equivalent to bit shifting. * Standard loopholes are disallowed. * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest answer wins. However, it will not be selected. [Answer] # [Haskell](https://www.haskell.org/), 20 bytes ``` (`take`iterate(*2)2) ``` [Try it online!](https://tio.run/nexus/haskell#@59mq5FQkpidmpBZklqUWJKqoWWkaaT5PzcxM0/BVqGgKDOvREFFIU3B5L8JAA "Haskell – TIO Nexus") 3 bytes longer than the unrestricted: ``` f n=map(2^)[1..n] ``` [Answer] ## [Alice](https://github.com/m-ender/alice), 16 bytes ``` t/O<\*2Hw& k\i.@ ``` [Try it online!](https://tio.run/nexus/alice#@1@i728To2XkUa7GlR2Tqefw/78ZAA "Alice – TIO Nexus") ### Explanation This uses the `w&...k` looping technique explained in [this answer](https://codegolf.stackexchange.com/a/116972/8478). ``` t Decrement the implicit zero on top of the stack to give -1 to initialise the product for later. / Reflect to SE. Switch to Ordinal. i Read all input as a string. Bounce off bottom boundary, move NE. < Set the horizontal component of the IP direction to west, i.e. move NW. Bounce off top boundary, move SW. i Try reading more input. Just pushes an empty string. Bounce off bottom boundary, move NW. / Reflect to W. Switch to Cardinal. t Implicitly discard the empty string and convert the actual input to its numerical value N. Decrement it to get N-1. IP wraps around to the last column. &w Repeat the following bit N times. H Take the absolute value of the top of the stack. This is only relevant for the first iteration, because we initialised the product to -1 instead of 1. 2* Double the current product. \ Reflect to SW. Switch to Ordinal. . Duplicate the current product (also converts it to a string, but it will be converted back by the H). Bounce off bottom boundary, move NW. O Output the current product as a string with a trailing linefeed. Bounce off top boundary, move SW. \ Reflect to W. Switch to Cardinal. k End of loop. IP wraps around to the last column. @ Terminate the program. ``` [Answer] # [Cheddar](https://cheddar.vihan.org), 26 bytes ``` n->2/2|>n=>n->[n]*n/(*) ``` Takes n as art generated range [1, n], maps (`=>`) It over [n]\*n (array of n n times over multiplication) No TIO link because cheddar on TIO is outdated. [Answer] # [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 44 bytes ``` (([{}]){}<(()())>){({}<((({})){})>()())}{}{} ``` [Try it online!](https://tio.run/nexus/brain-flak#@6@hEV1dG6tZXWujoaGpoalpp1mtAeYASU2gsKYdWLi2Ggj//zcFAA "Brain-Flak – TIO Nexus") Explanation: ``` #Push negative(input * 2) (([{}]){} #And push a 2 underneath it <(()())> ) #While True: { #Pop the top of the stack off ({} #And double the number underneath it <((({})){})> #Then push the former top of the stack + 2 ()()) #Endwhile } #Pop two elements, implicitly display stack {}{} ``` [Answer] ## JavaScript (ES6), 35 bytes ``` x=>[...Array(x)].map(_=>p+=p,p=x/x) ``` Using no digits at all. [Answer] # Octave, 23 bytes ``` @(x)cumprod(~(2/2:x)+2) ``` [Try it online!](https://tio.run/nexus/octave#@@@gUaGZXJpbUJSfolGnYaRvZFWhqW2k@T8xr1jDUPM/AA "Octave – TIO Nexus") Returns cumulative product of repeated 2s. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), ~~5~~ 4 bytes ``` 2ṁ×\ ``` [Try it online!](https://tio.run/nexus/jelly#@2/0cGfj4ekx////NwMA "Jelly – TIO Nexus") ### How it works ``` 2ṁ×\ Main link. Argument: n 2ṁ Mold; reshape [2] as [1, ..., n], generating an array of n 2's. ×\ Take the cumulative product. ``` [Answer] # [SOGL](https://github.com/dzaima/SOGL), 6 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md) ``` 2.{t2* ``` Explanation: ``` 2 push 2 .{ repeat input times t output 2* multiply by two ``` [Answer] ## Ruby, 29 bytes ``` ->n{b=2;n.times{puts b;b*=2}} ``` [Answer] # [Python 2](https://docs.python.org/2/), 31 bytes ``` n=2 exec"print n;n*=2;"*input() ``` [Try it online!](https://tio.run/nexus/python2#@59na8SVWpGarFRQlJlXopBnnadla2StpJWZV1BaoqH5HyKcpgHla/43AQA "Python 2 – TIO Nexus") This might be the shortest way to do it, restrictions or no. Compare ``` lambda n:[2<<i for i in range(n)] # 33 bytes, ignoring restrictions ``` [Try it online](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQZxVtZGOTqZCWX6SQqZCZp1CUmJeeqpGnGfu/oCgzr0QhTSMzr6C0RENT878JAA "Python 2 – TIO Nexus") [Answer] # [CJam](https://sourceforge.net/p/cjam), 11 bytes ``` 2ri{_p2*}*; ``` [Try it online!](https://tio.run/nexus/cjam#@29UlFkdX2CkVatl/f@/BQA "CJam – TIO Nexus") [Answer] ## Batch, 80 bytes ``` @set/px= @set/ap=2/2 @for /l %%i in (%p%,%p%,%x%)do @set/ap+=p&call echo %%p%% ``` Takes input on STDIN, since `%1` would be illegal. Fully illegal version would only be 63 bytes: ``` @set/ap=1 @for /l %%i in (1,1,%1)do @set/ap+=p&call echo %%p%% ``` ]
[Question] [ Write a program, which outputs `I'm Blue,` and then `Da, Ba, Dee, Da, Ba, Die,` forever, **the words must be space-seperated in one line, and it must pause 0.4 to 0.6 seconds after printing each word.** Also, the text should be outputted in the color blue 0x0000FF or in ANSI escape code blues. So the output must be something like this: [![enter image description here](https://i.stack.imgur.com/TjfUM.png)](https://i.stack.imgur.com/TjfUM.png) You can use any programming language you want. The output can be in either text or image form (escape codes allowed!). This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest program in bytes wins! [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~46~~ 45 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` 27ç"ÿ[34mI'm"?…žå°êèÞ#5∍'—ǪÞ'‡—š',«™1úε₄;.W? ``` Uses an ANSI escape code to print in blue ([which is `rgb(0,55,218)` in Windows 10 by default](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) - see screenshot below - but could be changed to the required `rgb(0,0,255)` in the console properties itself if necessary). [Try it online](https://tio.run/##AVgAp/9vc2FiaWX//zI3w6ciw79bMzRtSSdtIj/igKbFvsOlwrDDqsOow54jNeKIjSfigJTDh8Kqw54n4oCh4oCUxaEnLMKr4oSiMcO6zrU/////LS1uby1sYXp5) (with the sleep `₄;.W` removed). *Screenshot:* [![enter image description here](https://i.stack.imgur.com/Ku9ez.png)](https://i.stack.imgur.com/Ku9ez.png) **Explanation:** ``` 27ç # Push 27, and convert it to a character with this codepoint: <ESC> "ÿ[34mI'm" # Push this string, where `ÿ` is filled with the earlier <ESC> character ? # Pop and print it (without newline) …žå°êèÞ # Push dictionary string "da ba dee" # # Split it on spaces: ["da","ba","dee"] 5∍ # Extend it to size 5: ["da","ba","dee","da","ba"] '—Ç '# Push dictionary string "die" ª # Append it to the list: ["da","ba","dee","da","ba","die"] Þ # Cycle this list indefinitely: # ["da","ba","dee","da","ba","die","da","ba","dee","da",...] '‡— '# Push dictionary string "blue" š # Prepend it in front of the infinite list ',« '# Append a comma to each string ™ # Titlecase each word 1ú # Prepend a leading space to each string ε # Foreach over the list: ₄; # Push 500 (push 1000 and halve it) .W # Pop and sleep that many millisecond ? # Print the string (without newline) ``` [See this 05AB1E tip of mine (section *How to use the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `…žå°êèÞ` is `"da ba dee"`; `'—Ç` is `"die"`; and `'‡—` is `"blue"`. [Answer] # HTML + JavaScript (All Browsers), ~~30 + 77 = 107~~ ~~24 + 90 = 114~~ 24 + 87 = 111 bytes ``` i=5 setInterval(a=>b.append("Da0Ba0Dee0Da0Ba0Die0Blue".split(0)[(i<6)+i++%6]+", "),500) ``` ``` <body id=b text=blue>I'm ``` --- +7 because the original code didn't match the spec. -3 from @jdt for using `.append(...)` instead of `.innerHTML+=...` [Answer] # HTML + JavaScript, ~~22~~ 18 + ~~90~~ ~~89~~ ~~88~~ 86 = 104 bytes ``` setInterval("b.append(`${'Da Ba Dee Da Ba Die Blue'.split` `[i++%7]}, `);i%=6",i=419) ``` ``` <a href=# id=b>I'm ``` -6 bytes: use `.append()` instead of `.before()`, use `setInterval` string eval (from [@jdt](https://codegolf.stackexchange.com/questions/251878/im-blue-da-ba-dee-da-ba-die/251997?noredirect=1#comment561319_251997)) [Answer] # [Python 3](https://docs.python.org/3/), 135 bytes ``` import time def f(l):[print(end=i+' ')==time.sleep(.5)for i in l.split()] f("\033[34mI'm Blue,") while 1:f("Da, Ba, Dee, Da, Ba, Die,") ``` Works on Windows Command Prompt [Try it online!](https://tio.run/##NYqxCsMgFEV3v@KRRaVBWmyXgEvI0m9IOxTyJA@eRoyl9OutGTqcC4d70resW7S1UkhbLlAooFjQg1eshzllikVhXBydJEjt3BGYnRGTMjfttwwEFIHNnpiK0k/hVfc4Wzvba7jLACO/se@0@KzECJeh3dOrh7ExIbb5Cx1ZrT8 "Python 3 – Try It Online") # [Python 3](https://docs.python.org/3/), 145 bytes ``` import time def f(l):[print(end=i+' ',flush=1)==time.sleep(.5)for i in l.split()] f("\033[1;34mI'm Blue,") while 1:f("Da, Ba, Dee, Da, Ba, Die,") ``` Works on MacOS iTerm [Try it online!](https://tio.run/##Ncq9CoMwFIbh3as4uJjQIJW0i5JFXHoNtkPBEzxw8oNGSq8@jUOH74UPnvhNa/A6Z3IxbAkSOawWtGAFy36OG/kk0C@GLg00yvKxr6aTxpyw3RkxivYubdiAgDxwu0emJOSrsqJ@XrWeu0Hf3KNxMPKBqpbVZyVG6PoCpreCsWxCLPkfOlnOPw "Python 3 – Try It Online") -8 thanks to 97.100.97.109 # [Python 3](https://docs.python.org/3/), 196 bytes ``` from time import*;from itertools import* p=print;s=sleep p(end="\033[1;33mI'm ",flush=1);s(.5) p(end="Blue, ",flush=1) for i in cycle(['Da','Ba','Dee','Da','Ba','Die']):s(.5);p(end=i+', ',flush=1) ``` Works on MacOS iTerm [Try it online!](https://tio.run/##TYy7CoMwFIZ3nyK4HG1DqYQuDVnEpc9gOxR7xAO5kcTBp0/RYtvlg//C55c0OStyHoMzLJFBRsa7kA5yayhhSM7puNeFVz6QTTKqqBF94Su0L1Xez0L0jRTC3MCwko96jpNqahmr06XeX62ekf@txegCI0aWDcugseqhewKHdkWHuPKXCeFRXzef/PjoCJzB15bzGw) --- Note: on TIO, colours aren't shown, and everything gets shown when the program finishes. Here is a video of this running on another editor: [![Output](https://i.stack.imgur.com/0YW8e.gif)](https://i.stack.imgur.com/0YW8e.gif) [Answer] # Python 3 + `colorama`, ~~177 176 175 167 166 162~~ 160 bytes I used `colorama` when I was interested in coloring `stdout`, and it certainly should help here! (Also used because The Thonnu's answer was really long) ``` import colorama,time;colorama.init() def m(n):[print(end=i+" ")==time.sleep(.5)for i in n.split()] m("\033[34mI'm Blue,") while 1:m("Da, Ba, Dee, Da, Ba, Die,") ``` ## How to use: As The Thonnu pointed out, this program fails on TIO, so to execute it: 1. Download IDLE (if you don't have it) 2. Open your terminal 3. Type `py -m pip install colorama` 4. Create a new file 5. Copy the code 6. Save it (here it will be `colored.py`) 7. Type `py -m colored` (or whatever you saved the file as without the `py` part) on your terminal. See [this video](https://drive.google.com/file/d/17eD0IX4a7n7kdBvdq2wSAyRqQnxLiy0C/view?usp=sharing) that shows it being done. ## Direct downloading version, 223 bytes: Will download `colorama` from pip and executes. ``` import os,time os.system("py -mpip install colorama") import colorama;colorama.init m=lambda n:print(end="\033[34m"+n)or time.sleep(.5) m("I'm ");m("Blue, ") while 1: for i in['Da','Ba','Dee','Da','Ba','Die']:m(i+", "); ``` ## Non-Windows version, 135 bytes: On windows platforms, Colorama is required for initializing the terminal. Other ones, don't think so. ``` import time def m(n):[print(end=i+' ')==time.sleep(.5)for i in n.split()] m("\033[34mI'm Blue,") while 1:m("Da, Ba, Dee, Da, Ba, Die,") ``` [Answer] ## Batch, 148 bytes ``` @set/p=␛[94mI'm <nul @call:c Blue :l @for %%i in (Da Ba Dee Da Ba Die) do @call:c %%i @goto l :c @ping 192.512 -n 1 -w 500>nul @set/p=%1, <nul ``` Note: `␛` represents the Escape character (`^[`). Explanation: ``` @set/p=␛[94mI'm <nul ``` Set the text colour to bright blue and write the initial `I'm` without starting a new line. ``` @call:c Blue ``` Start with the word `Blue`. ``` :l @for %%i in (Da Ba Dee Da Ba Die)do @call:c %%i @goto l ``` Loop over the remaining words, and then repeat indefinitely. ``` :c @ping 192.512 -n 1 -w 500>nul @set/p=%1, <nul ``` Wait `500ms`, and then output the word with a trailing `,` without starting a new line. `192.512` is a reserved IP address and it should not be possible to ping it, so the ping will time out after `0.5s` as desired. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/186820/edit). Closed 4 years ago. [Improve this question](/posts/186820/edit) Create a program that, given an integer N, outputs the number of years we have to get to N A.D. or how many years it has been since N A.D, as a string or int. For example, given 2014, the program should output 5 as it has been that many years since 2014. Input of the year in which you run the program should result in 0. Treat the input "0" however you like: as its own year, as 1 A.D. or as 1 B.C. This means that you can pretend there IS a year zero and have all BC years be off by one. Negative integers (integers with - in front of them) are treated as years B.C. For example inputting -2 would result in the program telling how many years it has been since 2 B.C. Treat improper inputs (inputs that don't only use numbers and the dash as characters (abcd), or use the dash by itself or use it wrongly (e.g. 6-)) however you want, error or exit or something else. The winning program is the program with the shortest code that does all of this. Have fun. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes ``` žgα ``` [Try it online!](https://tio.run/##yy9OTMpM/f//6L70cxv//zcyMDQBAA "05AB1E – Try It Online") **Explanation** ``` α # absolute difference between # implicit input žg # and current year ``` [Answer] # Java 8, 46 bytes ``` n->(n-=java.time.Year.now().getValue())<0?-n:n ``` [Try it online.](https://tio.run/##ZY5Bi8IwFITv/oqHpwRJ6IY9qdVfoBdhYVEPzxgltX0tzauLiL@9m8YeFvYyMDPwzRR4R1Wcb70tMQTYoKfnBMATu/aC1sF2sCkAKwYluYjJaxIlMLK3sAWCHHpSK0EqLyJRs6@c/nbYaqp/hNRXx19Ydk5IuczWiubUD5SmO5URMHLutT9DFR@IHbeervsjoHzPswssTPbxmcZHr8xfZzJj/l1LyFQP1z01HY/E3SOwq3TdsW7iGJckUj2bzg88nZG2by9H5qv/BQ) Or alternatively: ``` n->Math.abs(n-java.time.Year.now().getValue()) ``` [Try it online.](https://tio.run/##ZY7BCsIwEETvfsXiKUEaNHhS9A/qRRBEPawxamq7Lc1WEfHbaxp7ELwMzAy8mQzvmGSnW2ty9B5SdPQaADhiW5/RWFh1NgZgRKck5yF5D4J4RnYGVkCwgJaSZYp8VXj0gpIsgBW7wqqtxVpR@RBSXSxvMG@skLLtKFVzzAOg59xLd4IiPBBrrh1ddgdA@Z1n61no8WQax3uf6F@nx1r/XYvIWHfXHVUN98T107MtVNmwqsIY5yRiPRrO9jwckTJfL3vmu/0A) [Answer] # [Japt](https://github.com/ETHproductions/japt), 3 bytes ``` aKi ``` [Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=YUtp&input=MjAxNA) ``` aKi :Implicit input of year a :Absolute difference with K : Date i : Get year ``` [Answer] # [Pyth](https://github.com/isaacg1/pyth), 4 bytes ``` a.d3 ``` [Try it online!](https://tio.run/##K6gsyfj/P1Evxfj/fyMDQxMA "Pyth – Try It Online") **Explanation:** ``` a.d3Q - full program. implicit Q added. a - absolute difference of .d3 - current year and Q - implicit input ``` [Answer] # [C# (Visual C# Interactive Compiler)](https://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc) with `/u:System.Math` and `/u:System.DateTime` flags, ~~32~~ 18 bytes ``` n=>Abs(Now.Year-n) ``` [Try it online.](https://tio.run/##Sy7WTS7O/O9Wmpdsk5lXoqMAJOwU0hRs/@fZ2jkmFWv45ZfrRaYmFunmaf635govyixJ9cnMS9VI0zAyMDTR1EQV0zVCFzEyMAKJ/f@XX1CSmZ9X/F@/1Cq4srgkNVfPN7EkA4nrkliSGpKZmwoA) [Answer] # [PHP](https://php.net/), 22 bytes ``` <?=date('Y')-$argv[1]; ``` [Try it online!](https://tio.run/##K8go@P/fxt42JbEkVUM9Ul1TVyWxKL0s2jDW@v///7qmAA "PHP – Try It Online") [Answer] # [Python 3](https://docs.python.org/3/), 66 bytes ``` from datetime import* print(abs(int(input())-datetime.now().year)) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/P60oP1chJbEktSQzN1UhM7cgv6hEi6ugKDOvRCMxqVgDRGfmFZSWaGhq6sLU6eXll2to6lWmJhZpav7/b2RgaAIA "Python 3 – Try It Online") Gives 5 for 2014 because it's 2019, not 2018. [Answer] # [Red](http://www.red-lang.org), 30 bytes ``` func[y][absolute y - now/year] ``` [Try it online!](https://tio.run/##K0pN@R@UmhIdy5Vm9T@tNC85ujI2OjGpOD@ntCRVoVJBVyEvv1y/MjWxKPZ/QVFmXolCmoKRgaEJF4JjhOAY/AcA "Red – Try It Online") [Answer] # [JavaScript (Node.js)](https://nodejs.org), 33 bytes ``` a=>Math.abs(Date().split` `[3]-a) ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1s43sSRDLzGpWMMlsSRVQ1OvuCAnsyRBISHaOFY3UfN/cn5ecX5Oql5OfrpGmoaRgaGJpqY1F4aoJaaorhE2lUamQNH/AA "JavaScript (Node.js) – Try It Online") -6 bytes thanks to Luis felipe De jesus Munoz [Answer] # [C++ (gcc)](https://gcc.gnu.org/), ~~131~~ 127 bytes ``` #include<ctime> #include<cstdio> int main(){long y,t=time(0);scanf("%d",&y);y-=gmtime(&t)->tm_year+1900;printf("%d",y<0?-y:y);} ``` [Try it online!](https://tio.run/##Sy4o0E1PTv7/XzkzLzmnNCXVJrkkMzfVjgvBLy5Jycy348rMK1HITczM09CszsnPS1eo1CmxBSnVMNC0Lk5OzEvTUFJNUdJRq9S0rtS1Tc8Fy6mVaOraleTGV6YmFmkbWhoYWBcUAQ2Cqq20MbDXrbQC6qj9/9/IwNAEAA "C++ (gcc) – Try It Online") ]
[Question] [ ### The Challenge: Find if a number contains a digit. The number and the digit are to be taken as input. Output must be a boolean value. But you are not allowed to use the string representation of the number at any time. Now don't count upon a `char*` either. You must devise a mathematical way to do it. **Rules:** • You can't use a `string`/`char[]` representation of the number. Same goes for the digit. • It must be a complete program. • Input can be in any form. • Output must be a boolean value. *This is code-golf, so shortest code wins!*. **Test Cases**: ``` Input: 51, 5 Output : True ------------------------ Input: 123456789, 0 Output : False ------------------------ Input: 1111, 1 Output : True ``` *Disclaimer*: *I don't understand much Pyth/CJam/Japt and similar languages. Thus I hope everyone will be honest enough not to break the rules. Never mind, the community is always there to help me :)* [Answer] # [Perl 6](http://perl6.org), 27 bytes ``` {$^a.polymod(10 xx*)∋$^b} ``` ### Usage: ``` # make it an infix op, because I can my &infix:<contains> = {$^a.polymod(10 xx*)∋$^b} say 51 contains 5; # True say 123456789 contains 0; # False say 1111 contains 1; # True # you can use infix ops as oddly named subs as well say infix:<contains> 1230, 0; # True say map {$^a.polymod(10 xx*)∋$^b}, 10,0, 12,3, 12,2; # (True False True) ``` ``` # proof it isn't doing anything string related 'hi' contains 'h'; # Method 'polymod' not found for invocant of class 'Str' ``` ``` # Since it uses a Set operator the second argument has to be an Int # not a Str say 123 contains '1'; # False # not a Rat say 123 contains 1.0; # False # not a Num say 123 contains 1e0; # False # but an Int say 123 contains 1; # True ``` ### Explanation: `polymod` is similar to `divmod` from other languages, except it takes the number and a list of divisors. Here I give it an endless list of `10`s so that it splits it up into a list of digits. Then I see if the resulting list contains the second argument by using the *'contains as member'* ( `∋` / `(cont)` ) Set operator. [Answer] # Haskell, 42 bytes Called like `number!digitToFind`: ``` n!d|n<d=1>2|mod n 10==d=1<2|1<2=div n 10!d ``` [Answer] # [MATL](https://esolangs.org/wiki/MATL), ~~15~~ 14 bytes ``` t`10H#\t]xN$hm ``` [**Try it online!**](http://matl.tryitonline.net/#code=dGAxMEgjXHRdeE4kaG0&input=MTIzNDU2Nzg5CjA) ``` t % take 1st input (number) implicitly. Duplicate ` ] % do...while loop 10 % push number 10, to be used as divisor H#\ % divmod. Pushes remainder and then quotient t % duplicate quotient. Used as loop condition: exit if zero x % delete last quotient (which is zero) N$h % concatenate all partial results in an array = % take 2nd input (digit) implicitly. m % ismember function. True if digit is in array ``` [Answer] # Python 3, 59 It uses the same approach as every other approach. ``` def f(x,s): while x: x,r=divmod(x,10) if r==s:return 1 ``` [Answer] # [Befunge-93](http://www.quirkster.com/iano/js/befunge.html), 38 bytes ``` &&00pv >[[email protected]](/cdn-cgi/l/email-protection)< %*25:<_^#:/_ ^#\*25-g00 ``` Arguments are taken in the form `MainNum Digit`. It's the same algorithm that everyone else is doing (check if mod 10 is equal to the digit; if not, div 10 until it equals 0), since that's pretty much the optimal way to do this one. [Answer] ## JavaScript (ES6), 30 bytes ``` d=>g=n=>n%10==d||n>9&&g(n/10|0) ``` Examples: ``` f=d=>g=n=>n%10==d||n>9&&g(n/10|0) f(0)(0) -> true f(0)(10) -> true f(0)(12) -> false f(1)(12) -> true f(2)(12) -> true f(3)(12) -> false ``` [Answer] # PHP, ~~66~~ ~~65~~ ~~62~~ 47 bytes ``` in_array($d,array_map('intval',str_split($n))); ``` `$n` is the number to be searched `$d` is the digit to search for This code converts the `number` into `array[number]`, then scans the array for a matching digit. Returns `true` if any digit matches. Alternatively, if `number->string->array[string]->array[number]` is not valid (even though no operations use it *as* a string), there's this at **62 bytes**, for any `$n > 0`: ``` function f($n,$d){return$n&&($d==$n%10||f(($n-$n%10)/10,$d));} ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/240891/edit). Closed 2 years ago. The community reviewed whether to reopen this question 2 years ago and left it closed: > > Original close reason(s) were not resolved > > > [Improve this question](/posts/240891/edit) First 15 numbers of the [A046173](https://oeis.org/A046173): ``` 1, 99, 9701, 950599, 93149001, 9127651499, 894416697901, 87643708742799, 8588189040096401, 841554882220704499, 82463790268588944501, 8080609891439495856599, 791817305570802005002201, 77590015336047156994359099, 7603029685627050583442189501 ``` Your task is simple, output the first 20 numbers of this sequence on separate lines. A simple explanation to this sequence, (you can also refer to the link above), is As n increases, this sequence is approximately geometric with common ratio \$ r = \lim\_{n\to\infty} \frac{a(n)}{a(n-1)} = (\sqrt2 + \sqrt3)^4 = 49 + 20 \times \sqrt6 \$ This is [code-golf](https://codegolf.stackexchange.com/questions/tagged/code-golf), so shortest code wins! [Answer] # [Vyxal](https://github.com/Vyxal/Vyxal) `j`, 22 bytes ``` λ²`(3ṙ-x)/2`∆qt:⌊=;20ȯ ``` [Try it Online!](https://vyxal.pythonanywhere.com/#WyJqIiwiIiwizrvCsmAoM+G5mS14KS8yYOKIhnF0OuKMij07MjDIryIsIiIsIjEiXQ==) Finally a good use for symbolic algebra in a golfing language. Good luck porting this to Jelly lol. ## Explained ``` λ²`...`∆qt:⌊=;20ȯ λ # Create a lambda, that takes a single argument n and: ² # squares n `...` # pushes the string "(3x^2-x)/2" (this is the formula for pentagonal numbers - I found it on Wikipedia) ∆q # and solves that for x (as in, it uses Sympy to solve it as if it were an equation) - this will give a list of up to 2 solutions - a negative and positive solution in that order t # Push that positive solution because that's what we're interested in checking :⌊= # Does the floor of that solution equal that solution? This checks to see if it's an integer solution, as only integer solutions are plugged into the original formula anyway ; # Close the lambda 20ȯ # and push the first 20 numbers where that lambda is truthy - this times out online, but it works given infinite time and resources # The j flag joins that list on newlines - I think it's okay here because the main focus of the challenge is generating the numbers ``` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 15 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) With strict I/O as defined in the challenge description: the first 20 items newline delimited: ``` 21®1‚λ£98*s-}¦» ``` [Try it online.](https://tio.run/##ASAA3/9vc2FiaWX//zIxwq4x4oCazrvCozk4KnMtfcKmwrv//w) With default [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") I/O rules: outputs the 1-based \$n^{th}\$ term (**10 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)**): ``` ®1‚λè98*s- ``` [Try it online.](https://tio.run/##yy9OTMpM/f//0DrDRw2zzu0@vMLSQqtY9/9/Q1MA) **Explanation:** Uses the formula: \$a(n)=98\times a(n-1)-a(n-2)\$ with offset \$-1,1\$, the first formula defined on [the oeis-page](https://oeis.org/A046173). ``` λ # Start a recursive environment, 21 £ # to get the first 21 terms ®1‚ # Starting with a(0)=-1 and a(1)=1 # With every following a(n) defined as: 98* # Multiply the implicit a(n-1) by 98 s- # Subtract the implicit a(n-2) from it }¦ # After the recursive environment: remove the first -1 term » # Join the 20 terms by newlines # (after which it is output implicitly as result) λ # Start a recursive environment, è # to output the (implicit) input'th term ®1‚ # Starting with a(0)=-1 and a(1)=1 # With every following a(n) defined as: 98*s- # Same as above: 98*a(n-1)-a(n-2) # (after which the result is output implicitly) ``` [Answer] # [Pari/GP](http://pari.math.u-bordeaux.fr/), 44 bytes ``` for(i=0,19,print(([-1,1]*[0,-1;1,98]^i)[2])) ``` [Try it online!](https://tio.run/##K0gsytRNL/j/Py2/SCPT1kDH0FKnoCgzr0RDI1rXUMcwVivaQEfX0NpQx9IiNi5TM9ooVlPz/38A "Pari/GP – Try It Online") Using the formula \$a(n)=98\ a(n-1)-a(n-2)\$. [Answer] # [JavaScript (Node.js)](https://nodejs.org), 50 bytes A full program. ``` for(v=q=1n;~v%39n;v=q-98n*(q=-v))console.log(v+'') ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/Lb9Io8y20NYwz7quTNXYMs8ayNO1tMjT0ii01S3T1EzOzyvOz0nVy8lP1yjTVlfX/P8fAA "JavaScript (Node.js) – Try It Online") ]
[Question] [ **Closed**. This question needs to be more [focused](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Update the question so it focuses on one problem only by [editing this post](/posts/44810/edit). Closed 9 years ago. [Improve this question](/posts/44810/edit) I love my encryption but I need a program that is dedicated to making a caeser cipher. It will take an input string and will output a ciphered text with the number to decode it. The number can be made whatever you want The shortest code wins! [Answer] # Golfscript, 1 character ``` 0 ``` Outputs the input string rotated by 0 characters, plus the digit `0` to show how to decode it. (*sorry, I couldn't resist*) [Answer] ## Ruby - 12 This was my first idea. ``` puts gets+?0 ``` I see Doorknob posted an answer as I'm typing this, similar to my next idea: ## CJam - 4 ``` q0pp ``` Both of these shift by 0. This might not count, because I haven't actually released the interpreter yet, but my golfing language KSFTgolf can do it like this: ``` 0 ``` ~~That's zero bytes~~. It takes a byte to print the zero Here are more: ## Python 2 - 21 ``` print raw_input()+"0" ``` ## Python 3 - 18 ``` print(input()+"0") ``` ## Perl 5 - 10 ``` print<>.0; ``` ]
[Question] [ **This question already has answers here**: [The Golf (re)Sort [closed]](/questions/34898/the-golf-resort) (4 answers) Closed 9 years ago. All good coders know some good sorting algorithms like quicksort or merge sort. There is also slow sorting algorithms, e.g. bubble sort and insertion sort. But those are such easy to implement and so, so efficient. Too efficient. Your task is to create very slow sorting algorithm. Please attach the [Big O notation](http://en.wikipedia.org/wiki/Big_O_notation) of your algorithm to your post to help us rate them. Also, please describe how your sorting algorithm works. Input given trough STDIN. The first line contains number of arguments, and arguments are given after that. The arguments are integers in range from 0 to 105 and there are maximum 103 of them. Output is list sorted and printed line by line into STDOUT sorted beginning from decending order. You may not use any random numbers or any other random sources. This is [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'"). [Answer] # Mathematica, Time complexity O(n \* n!), Space complexity O(n!) ``` list = RandomInteger[10, 7] (*{5, 5, 4, 10, 5, 10, 5}*) permutations = Permutations@list; Cases[permutations, l_ /; And @@ Thread[Most[RotateLeft@l - l] >= 0]][[1]] (*{4, 5, 5, 5, 5, 10, 10}*) ``` This generates all permutations, discards all that aren't sorted, and then picks the first one. Therefore, it will use O(n!) memory and O(n!) time to generate all the permutations. Then it will use O(n!) time again, to iterate through the permutations, while needing O(n) for *each* of them to check that they are sorted. Note that this is both the worst case *and* best case complexity. [Answer] # CJam, Time complexity O(n(2n+1)\*log(n)), Space complexity O(n) ``` q~:Q,_#2#{Q$;}*Q$p ``` This sorts the array **n2n + 1** times using Merge Sort which has time complexity of **n log(n)** But really, this can be extended to any time complexity with a final output in range of Big Integer. (Don't) [try it online here](http://cjam.aditsu.net/) Input is like: ``` [1 4 2 3 1 5 6 1 2344 343 1 2 3 23 1 2 32 1 2 3 4] ``` and output is the sorted array A [graph comparing](http://www.wolframalpha.com/input/?i=plot%20x%20*%20%28%28x%20%5E%20x%29%20%5E%202%29%20*%20log%20%28x%29%20vs%20x%20*%20x!) **n \* n!** with **n2n + 1 \* log(n)** ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/15226/edit). Closed 10 years ago. [Improve this question](/posts/15226/edit) You have a [French deck](http://en.wikipedia.org/wiki/Standard_52-card_deck) of cards that **sorted** like this: 2 - 10, Princes, Queens, Kings, Aces. The deck represented with array of numbers from 1 to 52(included) Now the dealer is shuffling the deck 3 times and inserting a Joker in a random position of the deck. The joker represented with the number 0 The idea of shuffling is slicing the array in random position and moving it to the front like in the next examples: * 1,2,3,4,5,6,7,8,9,10 -> 6,7,8,9,10,1,2,3,4,5 // Sliced at 6 * 1,2,3,4,5,6,7,8,9,10 -> 8,9,10,1,2,3,4,5,6,7 // Sliced at 8 Find the joker position in the array. The challenge is doing this without iterating over the entire deck. **Winning priority:** * Best time performance * Shortest code [Answer] # polyglot, constant time, 8 characters ``` 52-a[52] ``` The trick is to realise what actually happens when you shuffle the array. Imagine the array as circular. Let us render the array starting at zero with the actual start/end signified with a bar: ``` 0 1 2 3 4 5 6 7 8 9 | ``` Now, what actually happens when you shuffle the top three cards to the bottom and re-render: ``` 7 8 9 0 1 2 3 4 5 6 | 0 1 2 3 4 5 6 | 7 8 9 ``` Let's shuffle three more cards: ``` 0 1 2 3 | 4 5 6 7 8 9 ``` The only thing shuffles do is that they rotate the whole array, but don't change the ordering up to rotation. So, if the array ends with a zero, we want to output the last index. The array has 53 elements, so the last index is 52. If the array starts with a zero, it ends with its largest value. We want to output zero in this case. Similarly, if the zero is `n` positions from the end, the last element of the array is `n`. Thus, the position of zero is the last position in the array, minus the value at the last position. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/199880/edit). Closed 3 years ago. [Improve this question](/posts/199880/edit) # Task Your task is to generate a password that is both secure and short in the fewest bytes possible given an integer seed as input. # Input No seed Or An integer seed # Output A password # Scoring Your score is how many seconds the password takes to crack on [How secure is my password](https://howsecureismypassword.net/) divided by (bytes \* password length) Scoring is unbalanced because this is for fun [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), ∞ Full program. Does not need a seed. ``` ⎕AV ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKO94P@jvqmOYSDmfwUwKAAA "APL (Dyalog Unicode) – Try It Online") `⎕AV` is the **A**tomic **V**ector, i.e. the code page: `"\u0000\b\n\r \f\u0006\u0007\u001B\t⌶ɫ%'⍺⍵_abcdefghijklmnopqrstuvwxyz\u0001\u0002¯.⍬0123456789\u0003⊢¥$£¢∆ABCDEFGHIJKLMNOPQRSTUVWXYZ\u0004\u0005ý·⍙ÁÂÃÇÈÊËÌÍÎÏÐÒÓÔÕÙÚÛÝþãìðòõ{€}⊣⌷¨ÀÄÅÆ⍨ÉÑÖØÜßàáâäåæçèéêëíîïñ[/⌿\\⍀<≤=≥>≠∨∧-+÷×?∊⍴~↑↓⍳○*⌈⌊∇∘(⊂⊃∩∪⊥⊤|;,⍱⍲⍒⍋⍉⌽⊖⍟⌹!⍕⍎⍫⍪≡≢óôöø\"#\u001E&´┘┐┌└┼─├┤┴┬│@ùúû^ü`∣¶:⍷¿¡⋄←→⍝)]\u001F §⎕⍞⍣"` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), Infinite score. Gets `Forever` on the password generator. So score is Infinite. ``` žĆ ``` [Try it online!](https://tio.run/##yy9OTMpM/f//6L4jbf//AwA "05AB1E – Try It Online") [Answer] # [JavaScript (Node.js)](https://nodejs.org), 11 bytes, score = Infinity An evil password. ``` _=>1n<<666n ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/e1s4wz8bGzMws739yfl5xfk6qXk5@ukaahqbmfwA "JavaScript (Node.js) – Try It Online") Generates: ``` 306180206916083902309240650087602475282639486413866622577088471913520022894784390350900738 050555138105234536857820245071373614031482942161565170086143298589738273508330367307539078 392896587187265470464n ``` The final '**n**' in the output is what makes *howsecureismypassword.net* believe that there are enough distinct characters for this to take forever to crack. Without it, it would take only 79,220,219,535,072,410,000,000,000,000 quinquagintillion years. :-) [Answer] # [Python 3](https://docs.python.org/3/), ~~19~~ 6 bytes, Score: Inf Whopping -13 thanks to @a'\_' ``` help() ``` [Try it online!](https://tio.run/##K6gsycjPM/7/PyM1p0BD8/9/AA "Python 3 – Try It Online") [Answer] # [SOGL V0.12](https://github.com/dzaima/SOGLOnline), 1 [byte](https://github.com/dzaima/SOGL/blob/master/chartable.md), score: Infinity Since we can't win 05AB1E, what about a shorter solution? This program basically yields the full SOGL code page. ``` █ ``` [Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JXUyNTg4,v=0.12) [Answer] # [brainfuck](https://github.com/TryItOnline/brainfuck), 5 bytes, Score = Inf ``` +[+.] ``` [Try it online!](https://tio.run/##SypKzMxLK03O/v9fO1pbL/b/fwA "brainfuck – Try It Online") [Answer] # [PHP](https://php.net/), 10 bytes -> Infinite score ``` phpinfo(); ``` [Try it online!](https://tio.run/##K8go@G9jXwAkgTgzLy1fQ9P6/38A "PHP – Try It Online") Basically a kind of port of @SurculoseSputum's python answer [Answer] # [GolfScript](http://www.golfscript.com/golfscript/), 4 bytes, score = Infinity An evil password. ``` 74,` ``` [Try it online!](https://tio.run/##S8/PSStOLsosKPn/39xEJ@H/fwA "GolfScript – Try It Online") Generates: ``` [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73] ``` The final '**`**' is what makes *howsecureismypassword.net* believe that there are enough distinct characters for this to take forever to crack. Without it, it would take only 79,220,219,535,072,370 quinquagintillion years. :-) ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/187573/edit). Closed 4 years ago. [Improve this question](/posts/187573/edit) Given two numbers, the first is greater than the second, check whether the first number is divisible by the second without a remainder. If divisible, answer `"yes"`(or any other string), otherwise `"no"(or any other string you like)`. **Conditions:** You cannot use conditional operators, loops, arrays, bitwise operations, functions and methods. You can use variables, all arithmetic integer operations (that is, integer division), even the operation of taking the remainder of a division. Numbers can range from 1 to 1,000,000. Maximum running time is 1 second. You can of course write in any language, but here is my non-golfed solution in C++: > > > ``` > int main() { > int a,b; cin >> a >> b; > int c = a%b; > int n = (c+1-(c-1)*((2*(c-1)+1)%2))/2; > int y = 121, e = 101, s = 115; > > cout << (char)(y-11*n) << (char)(e+10*n) << (char)(s-83*n) << endl; > } > ``` > > > > [Answer] # JavaScript (ES6), 17 bytes Takes input as `(a)(b)`. Returns `"Y"` for *yes* or `"undefined"` (as a string) for *no*. ``` a=>b=>"Y"[a%b]+'' ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i7J1k4pUik6UTUpVltd/X9yfl5xfk6qXk5@ukaahqGRpoaZpiYXpqippuZ/AA "JavaScript (Node.js) – Try It Online") --- # JavaScript (ES6), 50 bytes Takes input as `(a)(b)`. Returns `"yes"` or `"no"`, as per the original rules. ``` a=>b=>(22724-21872*((2*(a%b-1)+1)%2)).toString(36) ``` [Try it online!](https://tio.run/##Zcg7CoAwEAXA3nsI@5QIWb9NvIQniF8UyUoMXj/aW0wzh33sPfn9CsrJvMTVRGv60fTE3HKlWHctZ0Qfm45KI9dIGSiCDMHvbqOyQZzE3XIuxSkbraQZ1ADJf2sgvg "JavaScript (Node.js) – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 1 byte ``` Ö ``` [Try it online!](https://tio.run/##yy9OTMpM/f//8LT//425zAA "05AB1E – Try It Online") Outputs 1 if divsible 0 if not --- ### Old version with string must be Yes or No # [05AB1E](https://github.com/Adriandmen/05AB1E), ~~13~~ ~~12~~ 10 bytes ``` Ö'…Ü„nor.D ``` --- ``` Ö // Test to see if they are divisible '…Ü // The string yes „no // the string no r // reverse the stack .D // push whether they are divisible copies of "yes" // Implicitly output the result ``` [Try it online!](https://tio.run/##yy9OTMpM/f//8DT1Rw3LDs951DAvL79Iz@X/f2MuUwA "05AB1E – Try It Online") [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~17~~ 3 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set") Anonymous tacit infix function. Takes lesser and greater numbers as left and right arguments. Prints the string `"0"` if divisible and `"1"` if not. ``` 1⌊| ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///3/BRT1fN/7RHbRMe9fY96pvq6f@oq/nQeuNHbROBvOAgZyAZ4uEZ/N9YIU3BnAtEWoBJSwA "APL (Dyalog Unicode) – Try It Online") `|` division remainder when dividing right argument by left argument (gives `0` for divisible or strictly positive integer for non-divisible) `1⌊` the minimum of that and 1 (gives `0` for divisible or `1` for non-divisible) [Answer] # [Runic Enchantments](https://github.com/Draco18s/RunicEnchantments/tree/Console), 6 bytes ``` 0ii%p@ ``` [Try it online!](https://tio.run/##KyrNy0z@/98gM1O1wOH/f1MDBUMDAA "Runic Enchantments – Try It Online") Outputs 1 if divisible 0 if not. Determines 0/1-ness by raising 0 to the power of the remainder, which returns 0 for all `x` except 0 (due to the indeterminate nature of 00 having been [decided to be 1](https://stackoverflow.com/a/19955996/1663383)). ### Version with string output # [Runic Enchantments](https://github.com/Draco18s/RunicEnchantments/tree/Console), 20 bytes ``` 10ii%p-4´36*6X+d-E@ ``` [Try it online!](https://tio.run/##KyrNy0z@/9/QIDNTtUDX5NAWYzMtswjtFF1Xh///TQ0UDA0B "Runic Enchantments – Try It Online") Utilizes the [word dictionary](https://github.com/Draco18s/RunicEnchantments/blob/Console/RunicInterpreter/draco18s/util/WordDictionary.cs) to convert from a 0/1 value to the strings "yes" and "no" by multiplying the result by 436 and adding 47 (ok, it adds 60 and subtracts 13; the byte cost is ironically the same either way: `4X7++` vs. `6X+d-` vs. `4´7+`). May be invalid due to using an array? There is certainly no array *in the submission code* but rather in the the interpreter due to how `E` is executed when the top of the stack is not a string. [Answer] # [Befunge-98 (FBBI)](https://github.com/catseye/FBBI), 6 bytes ``` %1\k0. ``` Arguments should be pushed onto the stack, and requires the current IP delta to be (1,0). Prints `1` if divisible and `0` if not. [Try it online!](https://tio.run/##S0pNK81LT9W1tPj/307NSg@IlBRqlHR0FBRUDWOyDfQUFBTKuOIUsAO7RJ3//00UjLgsFcy5jBWMuQwNDBVMuSwNFQyNAQ "Befunge-98 (FBBI) – Try It Online") Link includes I/O boilerplate. ]
[Question] [ This is mostly for the memes. I regret existing. # Rules * Your code has to output, by either printing or showing in stdout, the phrase `This ain't it Chief.` in that exact format. * You can only use the characters from the phrase in either format of + UTF-8 (`Aa Cc Ee Ff Hh Ii Nn Tt Ss . '`) + or hex bytes (`41 61 20 43 63 20 45 65 20 46 66 20 48 68 20 49 69 20 4e 6e 20 54 74 20 53 73 20 2e 20 27`) * No inputs are allowed via stdin or any form of user input. * Use `JSFiddle`, `CodePen`, etc. to prove your code works (or a screenshot if needed?) # Answer Formatting ``` #Language - Code length in bytes some code #Comments, laughs, etc. ``` # Scoring * This is code golf, so shortest code in bytes wins. [Answer] # [CJam](https://sourceforge.net/p/cjam), 40 bytes ``` 'T'h'i's' 'a'i'n'''t' 'i't' 'C'h'i'e'f'. ``` [Try it online!](https://tio.run/##S85KzP3/Xz1EPUM9U71YXUE9EUjnqaurlwDZmWDSGSyXqp6mrvf/f0ZqTk4@AA "CJam – Try It Online") Explanation: 'T pushes a T to the stack, etc. CJam has an implicit output. [Answer] # [Japt](https://github.com/ETHproductions/japt), 43 bytes ``` '.ifieiiihi'CiSitiiiSiti''iniiiaiSisiiihi'T ``` [Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Jy5pZmllaWlpaGknQ2lTaXRpaWlTaXRpJydpbmlpaWFpU2lzaWlpaGknVA) > > [Draco18s](https://codegolf.stackexchange.com/questions/179332/this-aint-it-chief?rq=1#comment433131_179332): As for the challenge itself, I don't think any language can work with that instruction set except by sheer coincidence > > > This is one such coincidence; Japt's `i` method prepends its argument to the string it's applied to. [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 22 bytes A function returning the string, just for the lols. ``` 'This ain''t it Chief' ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///Xz0kI7NYITEzT129RCGzRME5IzM1Tf1/2qO2CY96@x51NT/qXfOod8uh9caP2iY@6psaHOQMJEM8PIP/pwEA "APL (Dyalog Unicode) – Try It Online") > > [Draco18s](https://codegolf.stackexchange.com/questions/179332/this-aint-it-chief?rq=1#comment433131_179332): As for the challenge itself, I don't think any language can work with that instruction set except by sheer coincidence > > > This is one such coincidence; You just need to type `''` to escape a `'` character, instead of using `\'`. [Answer] # [A](https://esolangs.org/wiki/A), 1.07e192 bytes ``` insert 1070535411808274876356555204541421987893453317986634005193363842599488570060956068723122679013084672793132737522449327487355527954547514152318677638703786440293483566302887576787267171423983556 A's here ``` Obligatory Lenguage (well this isn't Lenguage but you know what I mean) answer. [Try the brainfuck online!](https://tio.run/##TY5dCoAwDIMPVJITlF5k@KCCIIIPguev3a/Ly7b0S5ftWc/7ePfLHclEASwGqoTinaXhUChDtGnaAa33lDcYFh08W6bjVO1rDFVh4df0U2YYsxRkS0mpN/MRYDus9Gp2qeX@AQ "brainfuck – Try It Online") ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/139138/edit). Closed 6 years ago. [Improve this question](/posts/139138/edit) There's a [cool magic trick](http://www.mathmaniacs.org/lessons/01-binary/Magic_Trick/) that works using the power of binary. The effect of the trick is as follows: 1. An audience member chooses some natural number in the range of `1 to x` where x is chosen by the magician. 2. The magician hands the audience member some special cards. Each card contains some numbers from `1 to x`. 3. The audience member selects the cards which contain their number. 4. Almost instantly, the magician can determine the original number selected. --- # Specification: The numbers used for the cards are determined based on binary place value. Each card is first labeled with a power of 2. The first card becomes 1, the second becomes 2, the third becomes 4, and so on. From now on, I will refer to `card n` as the card labeled with `n`. To determine whether a number `k` is on card `n`, determine whether k in binary has at 1 at place value n. Consider the numbers `k=13` and `n=4`. K in binary is `1101`. The second digit (n=4) is 1, so `k=13, n=4` is a valid combination. # Goal: Given two natural numbers `0 < n < 128` and `0 < k < 128`, determine whether `n` appears on card `k`. Any reasonable input and output is allowed. Standard loopholes are banned. This is code-golf, so the fewest **bytes** wins. # [Test cases](http://www.mathmaniacs.org/lessons/01-binary/Magic_Trick/) [Answer] # [Pyth](https://pyth.readthedocs.io), 5 bytes ``` ._.&E ``` [Try it here.](http://pyth.herokuapp.com/?code=._.%26E&input=13%0A4&debug=0) Notice the cute face `._.` --- # How? ``` ._.&EQ - Q means input and is implicit. .& - Bitwise AND between: E - The second input and Q - The first input. ._ - Sign. 0 if it equals 0, 1 otherwise. ``` If inconsistent values are allowed: # [Pyth](https://pyth.readthedocs.io), 3 bytes No cute face this time `._.` ``` .&E ``` [Try it here.](http://pyth.herokuapp.com/?code=.%26E&input=13%0A4&debug=0) [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 1 byte ``` & ``` [Try it online!](https://tio.run/##y0rNyan8/1/t////hsb/TQA "Jelly – Try It Online") Bitwise AND Builtin [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 2 bytes ``` &Ā ``` [Try it online!](https://tio.run/##MzBNTDJM/f9f7UjD//@GxlwmAA "05AB1E – Try It Online") [Answer] # [Proton](https://github.com/alexander-liao/proton), 3 bytes ``` (&) ``` [Try it online!](https://tio.run/##KyjKL8nP@59m@19DTfN/QVFmXolGmoahsY6CiabmfwA "Proton – Try It Online") (Waiting for pull from TIO before it works on TIO but you can verify it by cloning the repository) Functional operator of the Bitwise AND operator ]
[Question] [ **This question already has answers here**: [Reversing of Words](/questions/121149/reversing-of-words) (52 answers) Closed 6 years ago. I remember this was exam question long long long time ago. There is a file say MyFile.txt, it can be any size and contains aphanumeric only your task is to revese the words example : **"Go beyond the traditional laptop with Surface Laptop. It's backed by the best of Microsoft, including Windows and Office"** It should be **"Office and Windows including Microsoft, of best the by backed It's Laptop. Surface with laptop traditional the beyond Go"** The size of the text in the file is unknown. [Answer] # Python 3, ~~77~~ ~~71~~ ~~47~~ 43 bytes ``` print(" ".join(open("f").read().split()[::-1])) ``` EDIT: Saved 6 bytes thanks to NoOneIsHere. EDIT: Saved another 24 thanks to Jonathan Allan. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/37087/edit). Closed 8 years ago. [Improve this question](/posts/37087/edit) i've been dabbling with a hypothetical language... now, i want to add a feature/mechanism that can easily format data in as few codes as possible. now, i need to compare my hypothetical language feature with how it's going to be written in other languages. in particular, would it have lesser code? so i just decided i would have a sample problem and see how this is coded in different languages. problem is, i'm only familiar with C-like languages (C/C++, Java, C#, J#,.. ), Python and some Perl. so could you guys help me out and write codes, as short as possible (no pseudo code) in different languages for the problem below. be as clever as you want and don't even think of efficiency. we're looking more of how we can describe what needs to be accomplished as short as possible. very declarative. or maybe there's already a languages that does this very well?? transform this: ``` ((a0, a1, a2), (b0, b1, b2), (c0, c1, c2)) ``` to this: ``` (a0, (b0, c0)), (a1, (b1, c1)), (a2, (b2, c2)) ``` the parenthesization just denotes nested arrays or list, whichever way you want to look at it. also, there are no types, so don't have to worry about that. [Answer] ## Python The language feature you're describing is typically known as `zip`. Assuming the array is named `a`: ``` zip(a[0],zip(*a[1:])) ``` Sample usage: ``` a = (('a0', 'a1', 'a2'), ('b0', 'b1', 'b2'), ('c0', 'c1', 'c2')) print zip(a[0],zip(*a[1:])) ``` Output: ``` [('a0', ('b0', 'c0')), ('a1', ('b1', 'c1')), ('a2', ('b2', 'c2'))] ``` If the last two values of each don't need to be in a list: ``` zip(*a) ``` would suffice. [Answer] # Python 3 I know you already have a Python answer, but here's some code that can be easily translated to other languages: ``` tup = [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] end = [] for j in range(len(tup[0])): end.append([tup[0][j]]) end[j].append([]) for i in range(1, len(tup)): end[j][1].append(tup[i][j]) ``` ...And since you've tagged this as [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") I've golfed my code from 206 characters to 157: ``` t=[[a0,a1,a2],[b0,b1,b2],[c0,c1,c2]] e=[];l=len;r=range for j in r(l(t[0])): e.append([t[0][j]]);e[j].append([]) for i in r(1,l(t)):e[j][1].append(t[i][j]) ``` ]
[Question] [ [*Abracadabra* is a magic word](https://en.wikipedia.org/wiki/Abracadabra). To make it even more magical, let's make several *alterations* to how it may be written: 1. Change the casing for any subset of characters; for example: `aBrAcAdAbRa` 2. Append an exclamation mark to it: `abracadabra!` 3. Change each occurrence of `a` into a different vowel: `ybrycydybry` 4. Change any single consonant letter into a different consonant which doesn't appear in the original word: `abracadakra` (don't change all occurrences of `b` into `k`, only one!) 5. Change the foreground colour, but not background colour 6. Change the background colour, but not foreground colour 7. Use [fullwidth characters](https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_(Unicode_block)): `abracadabra` (don't cheat by inserting spaces!) Output the variants to the screen (or printer) in 8 different lines of text. One variant (not necessarily the first one) should be "base", while all others should differ from it in a single aspect, as described above. The output may be the same each time your code is run; alternatively, it may be different each time (depending on random numbers or unpredictable values in memory). If your system can't support some of these alterations (for example, no support for colours on a black-and-white screen; no full-width characters on ASCII-only terminals), use the following replacement alterations: * Text in inverted colours * Blinking text * Different font * Different font size But please use these only if your system really doesn't support the original alterations! [Answer] # JavaScript (ES6), 114 bytes *-2 thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen) (and another -4 from there)* Includes the unprintable character `\x1b`. ``` _=>`ab* Ab* ab*! obrocodobro ak* ab* ab* abracadabra`.split`*`.join`racadabra` ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/e1i4hMUmLyxGIgbQiV35SUX5yfgqI4krM1uKSjjY2ywWpkI42gTDe7218v7fp/d5JYEYzmGxBFkzQKy7IySxJ0ErQy8rPzEsoSkxOTElMKkqUjjbITfifnJ9XnJ@TqpeTn66RpqGp@R8A "JavaScript (Node.js) – Try It Online") ### Output [![output](https://i.stack.imgur.com/Np016.png)](https://i.stack.imgur.com/Np016.png) [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 61 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` .•ÒÔt_º°•D©™®'!«®žO‡®'f1ǝ₆41‚ε®27çDr"[ÿmÿÿ[0m"«}`®Ç65248+çJ» ``` Alteration options in the same order as the challenge description. [Try it online.](https://tio.run/##AWoAlf9vc2FiaWX//y7igKLDksOUdF/CusKw4oCiRMKp4oSiwq4nIcKrwq7Fvk/DguKAocKuJ2Yxx53igoY0MeKAms61wq4yN8OnRHIiW8O/bcO/w79bMG0iwqt9YMKuw4c2NTI0OCvDp0rCu///) I misunderstood the challenge at first and thought the alternations were cumulative, which is actually shorter in 05AB1E (**52 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) - non-competing**): ``` .•ÒÔt_º°•='!«=žO‡=™='f1ǝ=Ç65248+çJ=₆41‚vy…[ÿm27çìì= ``` (Cumulative) alteration options in the order 2,3,1,4,7,5,6. [Try it online.](https://tio.run/##AVoApf9vc2FiaWX//y7igKLDksOUdF/CusKw4oCiPSchwqs9xb5Pw4LigKE94oSiPSdmMcedPcOHNjUyNDgrw6dKPeKChjQx4oCadnnigKZbw79tMjfDp8Osw6w9//8) **Explanation:** ``` .•ÒÔt_º°• # Push compressed string "abracadabra" © # Store it in variable `®` (without popping) D # Duplicate it ™ # Titlecase the copy ® # Push base-string `®` again '!« '# Append "!" ® # Push base-string `®` again žO # Push vowels builtin "aeiouy"  # Bifurcate it (short for Duplicate & Reverse copy): "yuoiea" ‡ # Transliterate all characters (so "a"s become "y"s) ® # Push base-string `®` again ǝ # Insert 'f '# an "f" 1 # at 0-based index 1 ® # Push base-string `®` again Ç # Convert it to a list of codepoint integers 65248+ # Add 65248 to each ç # Convert each integer back to a character J # Join it back together to a string ₆41‚ # Push pair [36,41] ε # Map over them: # (implicitly push the current integer) ® # Push base-string `®` again 27ç # Push 27, and convert it to a character with this codepoint (␛) Dr # Duplicate, then reverse the four items on the stack "[ÿmÿÿ[0m" # Push this string, replacing the `ÿ` one by one with the values « # Append it to the remaining ␛ }` # After the map: pop and push both strings to the stack » # Join all strings on the stack by newlines # (after which the result is output implicitly) ``` The cumulative program is pretty similar, except uses `=` (print with trailing newline without popping the string). And the `␛[0m` to reset the colors aren't necessary. [See this 05AB1E tip of mine (section *How to compress strings not part of the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `.•ÒÔt_º°•` is `"abracadabra"`. [Answer] # [Python 3.8 (pre-release)](https://docs.python.org/3.8/), ~~263~~ ~~247~~ ~~205~~ ~~202~~ ~~186~~ 165 bytes ``` p=print;p(s:='abracadabra');p(s+'!') for j in 0,1,2,3:p(''.join((chr(ord(c)+(j>2)*65248),'Dyk '[j])[c=='dac '[j]]for c in s)) for j in 3,4:p(f'\033[{j}4m{s}\033[0m') ``` [Try it online!](https://tio.run/##ZVDLbsIwELz7F7gYLmuXKKIkrRCVe@LSUw89phwSJ4GEJrZsUylCHPr4gv4P38QngOOAmqoX787MerSzsjFrUQczqU5FJYUyWDcaaZOKrcGsBX4HELrohUDJNs8zZeVC@C9GFfXq6ZlQ9DtspW7mJJm0unmQRM8ZxImKeZy2BWjLjWEIFOVC4RIXNZ54t97UC@aSAPilKGpC@FoRoVLC6ZiUj1N6c383DWfUg0WzwRCVSxpxxiCNuUPL1ou3Xpr2jAMvtKY5vE6CINqV@7Da6b0Dkwro6c/m17z2kb0o/ioz7/HbNrNJUax1Zm9xHWF4NBr1wqFeP7yAhROaRDW8Sdvi@M3lw/HwcTx8Hg8/rvly73efRIMoCKue78CubsnwP2l3QcidnYDY2Pt2/bV2S3tZnTKw2c8 "Python 3.8 (pre-release) – Try It Online") Not a very good Python solution, but worth the try. Outputs 1. base case: `abracadabra` 2. exclamation mark appended: `abracadabra!` 3. case swapped: `abracaDabra` (`d` replaced with `D`) 4. vowels replaced: `ybrycydybry` (`a` replaced with `y`) 5. single consonant replaced: `abrakadabra` (`c` replaced with `k`) 6. width filled: `abracadabra` 7. with blue foreground: `abracadabra` 8. with blue blackground: `abracadabra` **How it works?** The first line sets an alias for `print` and executes steps 1 and 2. The second line groups \$4\$ steps: 3, 4, 5 and 6. Therefore, \$0 \leq j \lt 4\$: for step 3, \$j=0\$; for step 4, \$j=1\$; and so on. Note that for steps 3, 4 and 5, a single letter is replaced by another single letter. This allows us to do ``` [c,'Dyk '[j]][c=='dac '[j]] ``` Also note that for step 6, ASCII character `a` is 65248 characters apart from `a`: ``` chr(ord(c)+65248) ``` Since they're different types of replacement, we can filter it using ``` (j>2)*65248 ``` where it'll be evaluated to 65248 only for \$j=3\$ (step 6). Since this conditional is not lazy-evaluated, we must add a space after `Dyk` and `dac` for considering the case where \$j=3\$. The third line handles the colors. **Changes** *-16 bytes* by reducing the lambdas to a curry. *-42 bytes* by assuming that "change the casing" means "change the case of any letter" as other answers did. *-3 bytes* by inlining the `j > 2` condition *-16 bytes* by using f-strings instead of `print(..., sep='')` *-21 bytes* by inlining the lambdas and using a generator comprehension [Answer] # [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 98 bytes ``` M¶M¶M!¶M¶M¶␛[5mM␛[25m¶␛[7mM␛[27m¶M M abracadabra 2=`c C T`a`y`!¶.+ 4=`c k T`l`a-r`.+$ ``` [Try it online!](https://tio.run/##K0otycxL/P@fy/fQNhBShFCHtklHm@b6SkcbmeaC2OZgtjmQ7cvly5WYVJSYnJgCoriMbBOSuZy5QhISEyoTgLr1tLlMQELZQKGchPd7G3Xf752UoKet8v8/AA "Retina 0.8.2 – Try It Online") `␛` characters above are actual ESC characters in the link, but they don't work in a post. Byte count shows as 86 bytes because link assumes SBCS but this is actually UTF-8. Fifth and sixth lines of output are blinking and inverse video. Explanation: ``` M¶M¶M!¶M¶M¶␛[5mM␛[25m¶␛[7mM␛[27m¶M M abracadabra ``` Insert the basic text, but with lines 3, 6 and 7 already altered. ``` 2=`c C ``` Uppercase a letter in line 2. ``` T`a`y`!¶.+ ``` Change the vowels in line 4. ``` 3=`c k ``` Change a consonant in line 5. ``` T`l`a-r`.+$ ``` Use full width characters in line 8. ]
[Question] [ Not to be confused with [Is my OS 32-bit or 64-bit](https://codegolf.stackexchange.com/questions/127322/is-my-os-32-bit-or-64-bit). This one is very simple, tell me whether or not my CPU supports 64-bit instructions. If my CPU supports 32-bit instructions, print '32', if my CPU supports 64 bit instructions, print '64', if my processor *naitively* supports other lengths of instructions, print 'other'. Your program must run on both 32 and 64-bit instruction modes, and if interpreted run properly on both 32 and 64-bit interpreters. Test cases: Arch: x86, i386, i686, RiscV32 Output: '32' Arch: x86-64, x64, x86\_64, RiscV64 Output: '3264' Arch: R700 Output '32other' The usual [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply. Best of luck! [Answer] # [Bash](https://www.gnu.org/software/bash/) + coreutils, ~~33~~ 25 bytes ``` lscpu|grep -Po '..(?=-b)' ``` [Don't try it online!](https://tio.run/##S0oszvj/P6c4uaC0Jr0otUBBNyBfQV1PT8PeVjdJU/3/fwA "Bash – Try It Online") Won't work because the TIO sandbox doesn't support lscpu. Edit: Saved 8 bytes thanks to @DigitalTrauma. [Answer] # [Rust](https://www.rust-lang.org/), 45 bytes ``` ||if std::usize::MAX>4294967295{3264}else{32} ``` [Try it online!](https://tio.run/##FY3BCgIhFEX3fsVrVgq1cWxCC6GNu2jbNupJwiShDkGO3266u2dxzwlLTNV6eN@dpwwyAUgYE63r6izE9FRqie6HSl3ONy24FHI6cLnPI59EwTliW6UCsCMphDRTv5@MplaBYeT7woBNahr5q39gi@w0uJGT3gL4BOfT7Dd0yGXYgqWsm@of) (Cross compile for 32-bit locally by installing a toolchain for i686. For example: `stable-i686-pc-windows-msvc`) Can't really test this on any architectures that support "other" lengths of instructions, but this can be used to check for 32-bit or 64-bit architectures. This is shorter than the built-in way using `cfg!(target_pointer_width="64")`. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/207138/edit). Closed 3 years ago. [Improve this question](/posts/207138/edit) # Background Peter's Father, the Teacher of a dance-club, asks Peter a question: Given are two [natural numbers (\$\mathbb{N}\$](https://en.wikipedia.org/wiki/Natural_number) \$x\$ and \$y\$). \$x\$ is the number of the garment types (e.g. shorts, shirts\$\dots\$) we have \$y\$ is number of colors (e.g. green, blue, \$\dots\$) of each garment we have. In the dance class, every one should be in a unique dress. # Example: [![not equals to ](https://i.stack.imgur.com/p0CEq.png)](https://i.stack.imgur.com/p0CEq.png) But: [![equals to](https://i.stack.imgur.com/0ZLAB.png)](https://i.stack.imgur.com/0ZLAB.png) Now tell me: For every given \$x\$ and \$y\$, what is the maximum number of people who an visit our class? Can you help Peter? # Challenge The input should be two natural numbers (\$\forall x,y\in\mathbb{N}\$) separated by a comma`,`. The input can also be your languages equivalent for a list which has two elements. The Output should be an Integer, the maximum number of people who can visit the dance-class. # Test cases ``` In:1,0 Out:0 In:0,0 Out:0 In:[2,2] Out:4 In:3,2 Out:9 ``` # Rules * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code wins [Answer] # [Perl 5](https://www.perl.org/) `-p`, 20 bytes ``` /,/;$_=$`*$'&&$'**$` ``` [Try it online!](https://tio.run/##K0gtyjH9/19fR99aJd5WJUFLRV1NTUVdS0sl4f9/Yx2jf/kFJZn5ecX/dQtyAA "Perl 5 – Try It Online") [Answer] Both answers don't work for 0-inputs, I'm waiting for it to be clarified. # [Husk](https://github.com/barbuz/Husk), 2 bytes Takes input as `colors, garment types` ``` Lπ ``` [Try it online!](https://tio.run/##yygtzv7/3@d8w////43@GwMA "Husk – Try It Online") ## Explanation ``` Inputs: 2, 3 π (x, y) 1..x 's cartesian power by y. [1, 2] -> [[1,1],[1,2],[2,1],[1,3],[2,2],[3,1],[2,3],[3,2],[3,3]] L (x) Length of x. -> 9 Implicit output ``` # [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes Takes input as the specified format. ``` и<²β ``` [Try it online!](https://tio.run/##yy9OTMpM/f//wg6bQ5vObfr/34jLGAA "05AB1E – Try It Online") ## Explanation ``` Example inputs: 2, 3 и Repeat: ["3", "3"] < Decrement: [2, 2] ²β From base (second input): 9 ``` ``` ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/65003/edit). Closed 8 years ago. [Improve this question](/posts/65003/edit) ## Challenge Make an error-checker in the least amount of possible bytes! If you received an HTML program as a string through standard input, your program will be able to find all the errors and return to standard output. If the program is over 2000 characters, return that as an error too. ## Errors As there has been discrepancy, I will provide the errors you can check for. Regular: * File too long * Tag not closed * Non-empty element not closed + XHTML self-closing will not give you any bonus. * Entity not closed (i.e. `&amp` vs `&amp;`) * CSS rule with no selector attached (i.e. `{color:white;}` vs `span {color:white;}` * CSS unclosed property-value pair (i.e. `color:white` vs `color:white;`) * Errors with brackets (e.g. no closing bracket, rules outside brackets, etc.) + Each different rule about brackets counts separately. * Undefined tag (worth x10) * Undefined attribute (worth x4) * Undefined CSS property (worth x10) Let me make this clear: ### You are not expected to complete all or even most of these. Completing 7 of them would be incredible, but not necessary. Please though, try as many as you can while keeping the byte count relatively low! ## Scoring * -10 bytes for every type of SyntaxError checked (e.g. undefined tag, oversized file [see above], etc.) * -30 bytes for every type of SyntaxError checked that returns a customized error message and line number. (for a total of -40 bytes per error) + You may not have a customized message less than 20char. * -100 bytes if your program can check embedded CSS in the document for at least 3 types of errors. (this includes `<element style="">` and `<style></style>`. * +100 bytes if you check only 3 or less types of errors. * ~0 bytes if your final score is negative. As this is my first code-golf challenge, please comment if you think the scores are out of range. ## Rules * You **may not** use a built-in function to check for errors. * You **must** check for at least 1 error type. No blank answers! :D * You **must** return *at minimum* the number of errors in the document. * When you post your score, you **should** use this Markdown format: Output: > > # My Language, ~~Unbonused bytes~~ Final Score > > > > ``` > code here > > ``` > > **Solves:** > > > > + First Error > + Second Error > + Et Cetera > Why/How it works > > >        Markdown: ``` # My Language, <s>Unbonused bytes</s> Final Score # code here **Solves:** * First Error * Second Error * Et Cetera Why/How it works ``` \* You **may** add additional strikethroughed numbers if you wish in between the two values. ## Winning After one week, the answer with the smallest number of bytes will win. If there is a tie, the answer with the most upvotes will win. If there is still a tie, I hold the divine power to choose. The winning answer will be accepted. After the deadline, others can still post their answers, but no reward will be given. ## Good Luck! This is my first challenge, so if anything is lacking in any way, please comment. Thank you! [Answer] # Unefunge 98, ~~15 9 - 10(1 error type)~~ 36 bytes - 40(one error with detatiled message) + 100 (only one error type) = ~~105 99~~ 96 This code only checks the file size. ``` 'Ϩ#@k~"elif rellams a edivorP<NAK>"k,1q ``` Note that the code above contains a unicode number with code point 2000 (counted as two bytes) and an unprintable character with character code 21 ([negative ackoledgement](https://en.wikipedia.org/wiki/Negative-acknowledge_character)) represented by `<NAK>`. The error message produces is "Provide a smaller file". Old 15-byte version: ``` 2aaa***#@k~1q ``` How it works: The programs `2aaa***` (in the old version) and `'Ϩ` push the number 2000 on to the stack. Then the `#` character jumps over the `@` and `k` extecutes `~`, getting a char from user input, 2000 times. If eof is read, `~` reflects the program onto the `@` terminating with a zero exit code. If no eof is encountered, `1q` exits with exit code 1, indicating that there is one error in the input (its too big). ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- **General programming questions** are off-topic here, but can be asked on [Stack Overflow](http://stackoverflow.com/about). Closed 9 years ago. [Improve this question](/posts/38680/edit) As input, you are given a positive integer *n*. Output a code in response. Each *n* should generate a unique code. There are some constraints on the code that it outputs: * The code must be 7 or more characters long in based on the input. * The code will be have only 7 characters when input string is less than 676000 and must be unique. * The code always begins with `ST` * The third and fourth characters are letters from A-Z * The remaining characters are numbers. so if 1 then STAA001 ``` 2 then STAA002 ``` upto 999 then STAA999 ``` 1K then STAB000 ``` this will continue unto 676599 then STZZ999, (still this total count is 7) so after this for 676000 then STAA0000 (count is 8) and so on. This is code golf, so the shortest entry in bytes wins. KMT's original post for reference: > > I need the generate the code using input value. The code must be 7 or > more character Consider Sample code STAA000 in which 'ST' is always > constant and next to characters changes based on the input they must > alphabets from A-Z and the remaining characters are number. > > > EX: > > > > ``` > Input Result > > 1. 100 STAA100 > 2. 2201 STAB201 > 3. 676001 STAA0001 > 4. 677111 STAA1111 > > ``` > > [Answer] ## CJam, 9 ``` "STAA00"r ``` Just prints the number back, no fancy algorithm. [Answer] # Pyth, 9 ``` p*w3"STAA ``` Examples: ``` $ pyth -c 'p*w3"STAA' <<< 0 STAA000 $ pyth -c 'p*w3"STAA' <<< 677111 STAA677111677111677111 ``` This is exactly equivalent to the following python 3 code: ``` print("STAA", end=input()*3) ``` The `*3` is necessary to guarantee the result is at least 7 characters. ]
[Question] [ **Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers. --- **General programming questions** are off-topic here, but can be asked on [Stack Overflow](http://stackoverflow.com/about). Closed 10 years ago. [Improve this question](/posts/3571/edit) Taking an array of records. For example ``` [ name: 'eventA', timestamp: '2011-08-27 15:34:00', name: 'eventB', timestamp: '2011-08-28 13:31:00', name: 'eventC', timestamp: '2011-08-29 10:34:00', name: 'eventD', timestamp: '2011-08-30 16:36:00', ] ``` How can I sort these by timestamp in a descending using a standard natural ascending sort algorithm built into most languages. E.g. E.g C#: `collection.Sort(record => record.timestamp)` Python: `sort(collection, lambda record: record.timetstamp)` You can not use the `sortByDescending` methods, of course most languages have them (or a flag to sort fn for descending) Somehow have to transform the `record.timestamp` so that it sorts descending Solution 1: Parse the date into a Date object provided by most languages and get time in milliseconds/seconds since 1970. Minus the amount from 0 to get the negated value and sort by this. Extra points for no expensive date conversions [Answer] ## Haskell ``` sortByDescending cmp = sortBy (flip cmp) ``` ### Example: ``` import Data.List import Data.Function import Data.Maybe import Data.Time.LocalTime import Data.Time.Parse -- requires module strptime data Record = Record { name :: String, timestamp :: LocalTime } deriving Show sortByDescending cmp = sortBy (flip cmp) sortByTimestampDescending :: [Record] -> [Record] sortByTimestampDescending = sortByDescending (compare `on` timestamp) parseExample :: (String, String) -> Record parseExample (n,t) = Record n (fst $ fromJust $ strptime "%Y-%m-%d %H:%M:%S" t) examples :: [Record] examples = map parseExample [("eventA", "2011-08-27 15:34:00") ,("eventB", "2011-08-28 13:31:00") ,("eventC", "2011-08-29 10:34:00") ,("eventD", "2011-08-30 16:36:00")] main = mapM_ print $ sortByTimestampDescending examples ``` ### Output: ``` Record {name = "eventD", timestamp = 2011-08-30 16:36:00} Record {name = "eventC", timestamp = 2011-08-29 10:34:00} Record {name = "eventB", timestamp = 2011-08-28 13:31:00} Record {name = "eventA", timestamp = 2011-08-27 15:34:00} ``` [Answer] ## D ``` retro(sort!"a.timestamp<b.timestamp"(array)); ``` or ``` retro(schwartzSort!"a.timestamp"(array)); ``` (you need to import std.algorithm and std.range) though honestly reversing an array without a build-in function is simple as it is ``` int i=0,j=arr.length;while(i<--j)swap(arr[i++],arr[j]); ``` or without a swap function: ``` int i=0,j=arr.length;while(i<--j){auto tmp=arr[i];arr[i++]=arr[j];arr[j]=tmp;} ``` [Answer] ### Scala: ``` val src = """name: 'eventA', timestamp: '2011-08-27 15:34:00', name: 'eventB', timestamp: '2011-08-28 13:31:00', name: 'eventC', timestamp: '2011-08-29 10:34:00', name: 'eventD', timestamp: '2011-08-30 16:36:00'""" class NT (name: String, val n: String, time: String, val ts: String) val nts = src.split ("[,:] ").sliding (4, 4).map (l => new NT (l(0), l(1), l(2), l(3))).toList nts.sortWith ((a, b) => a.ts < b.ts).reverse.foreach (k => println (k.ts + " " + k.n)) ``` Result: ``` '2011-08-30 16:36:00' 'eventD' '2011-08-29 10:34:00' 'eventC' '2011-08-28 13:31:00' 'eventB' '2011-08-27 15:34:00' 'eventA' ``` ]
[Question] [ Consider a horizontal line with vertical lines centered on the x-axis and placed at gaps of \$\sqrt{2}/2\$. For a positive integer \$n \geq 3\$, the first half of the lines have lengths \$0, \sqrt{2}, 2\sqrt{2}, 3\sqrt{2}, \dots, (n-1)\sqrt{2}\$ and then the second half have lengths \$(n-2)\sqrt{2}, (n-3)\sqrt{2}, \dots, 0\$. The goal is to find a circle center on the horizontal line so that for every pair of consecutive vertical lines, there exists a circle with that center which fits between them without touching either of them. For example, in the following illustration we can see that if we picked the origin for \$n=3\$ and the center at the origin, it is possible. [![enter image description here](https://i.stack.imgur.com/1wHMm.png)](https://i.stack.imgur.com/1wHMm.png) For \$n = 4\$, we can see that the center can't be at the origin. [![enter image description here](https://i.stack.imgur.com/W1u9W.png)](https://i.stack.imgur.com/W1u9W.png) We instead will need to move the center to the left. If we move the center to -1, then it is just possible. [![enter image description here](https://i.stack.imgur.com/Zf0Iz.png)](https://i.stack.imgur.com/Zf0Iz.png) For \$n=5\$ a center at -1 doesn't work and neither does -2. [![enter image description here](https://i.stack.imgur.com/3XzAR.png)](https://i.stack.imgur.com/3XzAR.png) For \$n=5\$ the desired output is -3. # Task Given an integer \$n \geq 3\$, output the largest integer valued circle center \$ x \leq 0\$ so that there exists a circle with that center for each pair vertical lines that goes between the vertical lines and doesn't touch them. [Answer] # [JavaScript (Node.js)](https://nodejs.org), 24 bytes ``` n=>(n*4-2-n*n)/8**.5-1|0 ``` [Try it online!](https://tio.run/##BcFbDkAwEAXQ7Uynhnolkqq9CCpE7gjiy97rnH18x3u6tvMR6LykGBLCQOBGKgHDFB1z3kr5uRT1IoTaoy@d89bCTIpbjyU/dCVkkWBM@gE "JavaScript (Node.js) – Try It Online") > > Any counterexample where the longest one isn't bottleneck? > > > Looks correct. Proof: scale the circle smaller and see how the allowed distance also get smaller [Used WolframAlpha](https://www.wolframalpha.com/input?i=%28x-1%29%5E2%2B%28n-1%29%5E2%3D%28x%29%5E2) ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/266258/edit). Closed 4 months ago. [Improve this question](/posts/266258/edit) I was seen multiple shortest "Hello World!" program, but this is the **longest** program. **The Rules** * Each submission must be a full program. * This must be non-interpreted language (for example, JavaScript, Python, HTML, etc.) * Target OS must be Windows, Mac, Linux or MS-DOS. **The challenge** * Writing a **longest** Hello World program. [Answer] # [C (gcc)](https://gcc.gnu.org/) (little-endian), 9,624,671,272,932,611,623 bytes ``` #include<string.h> main(){char x[14];long i,j;/* i++; repeated 2406167339672739884 times */ /* j++; repeated 478560413000 times */memcpy(x,&j,8);memcpy(x+5,&i,8);puts(x);} ``` [Try an equivalent version online!](https://tio.run/##PcjdCsIgGADQ@55iEAwlC51OHbZeJLoYNtwn0439gBE9u9FNl@fYs7M25yNEO@7P/rpuC0R3GW6H0EFE@G2HbinSnYmHGafoCiDeQFsJKplUnDdSVYo3WgvjW6F0LalgnFJqQh/s/EKJlJ5o/OepJiX8Yt63FSVsPjl/AQ/##VcrdCoIwGIDh867ig0D8WTnd3CaLbiQ6kDl04pboBCO69lUHBR2@L486dEqFsDdOjWurT4ufjeuO/XlnG@Pi5KH6ZobtUtCrHG@uA4MGmadgskzCrCfdeN1CSTErGCekZrzkpBaCgjdWL5Dm8NbDn6ZcVAzTgmCMf8xqq6Z7vKFoQCKR38wqFJnPmFa/xFsinyG8AA "C (gcc) – Try It Online") For some reason I can't post the full program, so it has been abbreviated in the comments. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/220031/edit). Closed 2 years ago. [Improve this question](/posts/220031/edit) your challenge is to draw this ASCII art: ``` | | |- - - - | | - - - | | | | | | | |- - -| |- - - | | | | | | | | | | | | | |- - - - |- - - |- - - - - - ``` remember this is `code golf` meaning you have to answer in the least amount of bytes possible. EDIT: spacing between letters is two spaces. the only symbols used are | and -. NO underscores. i added spaces between the dashes to make it easier to see how many there are [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 52 bytes ``` •C"¹Ò∞ʒÓŸ2ýŸ¦ÙLŒðd4Í}‡éλPÓãžãš±àýEŽª™§M₆2•… |-ÅвJ5ä» ``` [Try it online!](https://tio.run/##AWkAlv9vc2FiaWX//@KAokMiwrnDkuKInsqSw5PFuDLDvcW4wqbDmUzFksOwZDTDjX3igKHDqc67UMOTw6PFvsOjxaHCscOgw71Fxb3CquKEosKnTeKChjLigKLigKYgfC3DhdCySjXDpMK7//8 "05AB1E – Try It Online") ``` •...•… |-ÅвJ5ä» # full program » # join... J # joined... Åв # characters in... … |- # literal... Åв # with indices in digits of... •...• # 88667318995411980279046696478254356886483104218636819581201379955454517801745112819324119476267... Åв # in base length of... … |- # literal... ä # split into... 5 # literal... ä # equal sized pieces... » # by newlines # implicit output ``` [Answer] # [PHP](https://php.net/), 63 bytes ``` <?=gzinflate('«Q ÒU€@&`a^®¸J4Èt P%XÂL<*‰7‹;Ñh0'); ``` **WARNING**: this code contains many non-printable chars and a function that is disabled in most online code testers. It is either impossible to enter the correct code on their sites or run the function. Here is the php file I uploaded to gitHub so that you can test (I recommend using `<pre><code>` tags to see it as intended in a browser, because of spaces being narrower than `—`, and new lines ignored in HTML): [Try it OFFline!](https://github.com/Kaddath-R/Shared-Files/blob/main/SE-Golf/220031-ascii-hello.php) Well this is a one-time trick that is becoming recurrent, and quite boring, as all I need to do is reuse the script I made to generate the file, replace the string and run it. So this is the last time I'll use this trick, and I post it as a demonstration of why these challenges are not that much interesting IMO. EDIT: updated the answer and the file with edited question (the string is shorter, so from 94 bytes originally to 63) [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 54 bytes ``` ≔…- ⁵θ↓³↗→θ↑³Mχ¹←…- ⁷↓³↗→θM²⁰→P↑²M⁴→↑²←θ‖O↓F²«←←←θP↑⁵← ``` [Try it online!](https://tio.run/##nY7dCoIwGIaP9SqGRxsopCWBHYUdJongBciYOhhuzWVEdO1rJuLfWYff@z3vD64LiXnBtD63La0aGL8wI3HNBXQ84LggRC64o5OdStooGF34s3HB3ggJ7wiMcpHRqlYT8DsXllzMDP7OBf70u5LSwOvOI/qv8EcEpiEameTBFBXTjmCkDjMoXf4X0/rYjJSMYHXriGSFGCYZueQSwACBt20N03qH0VfXJs5ajwo3po/W2uvYFw "Charcoal – Try It Online") Link is to verbose version of code. Explanation: ``` ≔…- ⁵θ ``` Construct the string `- - -` as it gets used a lot. ``` ↓³↗→θ↑³ ``` Draw the top half of the `H`. ``` Mχ¹←…- ⁷↓³↗→θ ``` Draw the top half of the `E`. ``` M²⁰→P↑²M⁴→↑²←θ ``` Draw the top half of the `O`. ``` ‖O↓ ``` Reflect to complete the `HE O`. ``` F²«←←←θP↑⁵← ``` Draw two `L`s. Or I could just do boring string compression for 51 bytes: ``` ”~∨CθOÀ·y←B~⊟⧴n^;δS3E⊖⎇✂↶0¶KZ7≦%⊕wG4H⁻φ|ePυυ[qπ<Φ⊙› ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvREOpRgEEgGSNrgIEKkCEEDRYOCYPoVJBAU0FMl0DVAnWgTATj0rizcTiTjQaTClpWv///1@3LAcA "Charcoal – Try It Online") Link is to verbose version of code. If there were no spaces in the horizontal lines, it would be only 44 bytes: ``` ↓³↗→⁵↑³Mχ¹←⁷↓³↗→⁵M²⁴→↑²←⁴P↓³←¹‖O↓F²«←←←⁵P↑⁵← ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMPKJb88T0fBWNOayze/LFXDKrQgKDM9owTIhyoAc3UUTBEioQVIGgwNdBQMEXI@qWlAxeYIAVLMB6swMtFRsEJTA7LRCN0SE5CO0pySzAJ0m1CUgRwXlJqWk5pc4l@WWpSTWABRChROyy9S0DDSVKjm4oQ4DqQDKI7GQzHOFCyPZC3IbaYYmmr///@vW5YDAA "Charcoal – Try It Online") Link is to verbose version of code. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/95129/edit). Closed 7 years ago. [Improve this question](/posts/95129/edit) It is currently December 31, 2015, 11:59:00pm, and you must be at least 1324900 seconds old to be able to go to the New Year Celebration. Given the year, month, day, hour, minute, and second of your birth, determine if you are old enough to go. Notes: * Assume that you are in the same timezone. * Leap years are every 4 years, but if the year is a multiple of 100, it is not a leap year, unless it is a multiple of 400. Remember, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the smallest number of bytes wins. ## Leaderboards Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language. To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template: ``` # Language Name, N bytes ``` where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance: ``` # Ruby, <s>104</s> <s>101</s> 96 bytes ``` If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header: ``` # Perl, 43 + 2 (-p flag) = 45 bytes ``` You can also make the language name a link which will then show up in the leaderboard snippet: ``` # [><>](http://esolangs.org/wiki/Fish), 121 bytes ``` ``` var QUESTION_ID=95129,OVERRIDE_USER=12537;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i; ``` ``` body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px} ``` ``` <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> ``` [Answer] ## Python, 28 bytes ``` [2015,12,16,15,57,20].__le__ ``` Going [back 1324900 seconds from December 31, 2015, 11:59:00pm](https://www.wolframalpha.com/input/?i=(December%2031,%202015,%2011:59:00pm)%20minus%201324900%20seconds) gives December 16, 2015 at 3:57:20 pm. We convert this date to a list and take it's less-than-or-equals method to compare to the input list. This compares it lexicographically, so first by year, then by month, and so on. [Answer] # Mathematica, 66 bytes ``` DateObject@{2015,12,31,23,59,0}-DateObject@#>1324899~Quantity~"s"& ``` Anonymous function. Takes a list of integers as input, and returns `True` or `False` as output. ]
[Question] [ **Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers. --- **Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/195429/edit). Closed 4 years ago. [Improve this question](/posts/195429/edit) Not a new one: **Input** N, being n, 0 ≤ n ≤ 5. **Output** N times "Hello World." Example: **Input** 3 **Output** ``` Hello World. Hello World. Hello World. ``` These 2 are my best solutions: **First** ``` public class Out { public static void main(String[] a) throws Exception { java.io.OutputStream o = System.out; byte n = Byte.parseByte(new java.io.BufferedReader(new java.io.InputStreamReader(System.in)).readLine()); for(byte i = 0;i<n;i++){ o.write("Hola mundo.\n".getBytes()); } } } ``` **Second** ``` public class Out { public static void main(String[] a) throws Exception{ byte n = Byte.parseByte(new java.io.BufferedReader(new java.io.InputStreamReader(System.in)).readLine()); while(n>0){switch(n){case 0: w();break;case 1: w();break;case 2: w();break;case 3: w();break;case 4: w();break;case 5: w();break;}n--;} } static void w() throws Exception{ System.out.write("Hola mundo.\n".getBytes()); } } ``` According to the server it is being tested on ( im not an owner of that server), first attempt gives me 0.006ms and 622 KiB while second attempt gives me same time with 625 KiB. I am not able to provide the Java version being used but if you want, feel free to use the main site ( spanish language ) <https://www.aceptaelreto.com/problem/statement.php?id=116> P.S.: Some peoeple were able to get it on 0.005ms and 88KiB. edit: -this code is being benchmarked on the link used before. -The point is to get the fastest code ( and if possible, with the least amount of memory used), not the shortest one. Apparently Im not able to use comments since I do not have the required reputation score. [Answer] C++11 approach (Time: `3.6 µs` on some Intel i7, File size of `a.out`: 28K) compiled via: `clang -O3 -march=native -Ofast golf.cpp`: (Clang 6.1) ``` #include <iostream> #include <chrono> #include <sstream> int main(int argc, char** argv) { auto t1 = std::chrono::high_resolution_clock::now(); const int n = 5; if (n < 0 || n > 5) return 1; std::stringstream ss; for (size_t i = 0; i < n; i++) ss << "Hello world\n"; std::cout << ss.str(); auto t2 = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); std::cout << duration << "µs" << std::endl; return 0; } ``` [Answer] Using C (size <12 KiB, time < 0.001s) ``` $ cat >hola.c <<END_C #include<unistd.h> int main(){ int i,n; read(0,&n,1); for(i='0';i<n;++i){ write(1,"Hola mundo.\n",12); } } END_C $ gcc hola.c -o hola $ wc -c hola 11944 hola $ time ./hola <<<5 [...] real 0m0.001s user 0m0.000s sys 0m0.000s ``` ]
[Question] [ **This question already has answers here**: [We're no strangers to code golf, you know the rules, and so do I](/questions/6043/were-no-strangers-to-code-golf-you-know-the-rules-and-so-do-i) (73 answers) Closed 9 years ago. The task here is to print the text below, using **as few characters as possible** in your code. You can't use any external resource. (file, stdin, network) ``` To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream: ay, there's the rub; For in that sleep of death what dreams may come When we have shuffled off this mortal coil, Must give us pause: there's the respect That makes calamity of so long life; For who would bear the whips and scorns of time, The oppressor's wrong, the proud man's contumely, The pangs of dispriz'd love, the law's delay, The insolence of office and the spurns That patient merit of the unworthy takes, When he himself might his quietus make With a bare bodkin? Who would these fardels bear, To grunt and sweat under a weary life, But that the dread of something after death, The undiscover'd country from whose bourn No traveller returns, puzzles the will And makes us rather bear those ills we have Than fly to others that we know not of? Thus conscience does make cowards of us all; And thus the native hue of resolution Is sicklied o'er with the pale cast of thought, And enterprises of great pith and moment With this regard their currents turn away, And lose the name of action.--Soft you now! The fair Ophelia! Nymph, in thy orisons Be all my sins remember'd. ``` [Answer] ## CJam, ~~713~~ 683 characters We're counting by characters so here's the usual Unicode encoding approach. I'm sure this can be beaten, but at least it's less than half as many characters as the output. ``` "=迗拢쌜僨糌ࢬꭖ杋鏊ꦓ廃啒⼬ᏸꛒ멉尬䳉藋底淡蟖ꣃ⪖恉囻ꮠⶠ榯൨鞺㹑悩眷ဋ㟯ㅕ葡Ż㼡惽Т託⹡嫰뵴䕞凿绸䷛䴽繋㐚挻ᙶ᪻뼶䌼냞ോ貿ꐯ欲鄁卒梷몧臡ꙉꐰ臸惽ệ昣䙍樬ᓜ녖谴鈦⃇炣膊Ე戭⟣䌮ꆰ躍➥կ语鄂셸ⷽⁿ덝곋䚴䚗Ḹ硅㺁餌쀎柁ᛔ礳괰蚴變㿢䅋砤鈴綸䨜᾽㓔䘅䊶䭚⦑럜䧑䔠⳾뇾䴓ꣽ鎋੩呝䓔ᇽἰ䗚笨簛䀣䲮攌꘦↢ኲㄉ⥈䎺韧᭩滥叒㰥ꬔ懭彼垥丼됑艨ᒝ荶뵴枀膛㛏닱関㵃踫⹦瀗媂㴫꺼柝➍ꜙ纫弡ꔕ㦂蹘ꬃ粅ᛧ熄寝㎍衰飔㩏鈅廀裝굗猪맊␰例㘇ꓶ᫋⟗㟔獇⍨ꉔ뵯瓗ℎ岻摔撎偱紁꽓澤䔷刪㒰墄㰑쀨ꦞ沣뤣葇欕鎨빵ဟ赊剡篠壃ఌ忎꺉鴩绘腀뉂每倢觌びው錵ꏅ儅몧瑳갎媢㗿陣欿᫉ꋿ週䰧鉝깊屌軌먝궔꘹ҙ伔肢⨘緍㰑㐩삭善เⴹ뫑勂㣗曝㛊瘐蠚椂ỿꖴ⎫ᶬ鐸它蒗ؑ謅໐뮦ꩇℇ虇ヽ襟餰塹媬蕥偃⒭躧ꩆ꣢麡翲ⷜ緤飆㛉鴳㾂偾ᖈ欍㩻䦛ꄆꏝ꣭䠦᭳㭱囃㣝䥀鿆䴹෽蝩荲輳蓆娠啃帶ᮾᨍ쀶ѱⴣ㻝順᫰掽紈걉壬虾撆Ⅴ軚䀥ᚑF㠡㞮ᨣ溹뷝欬듺㡧玌딿섄ଷ럫㏵椉䴚ጪ⾗瞾䕼效㠐翢Տ须䈲蘸อ괟㿬む攩糼烏뼊ⷫ庁诔뀗瀦䴇鳨匿ò韑祋夯稚骪愫蕁렒蒔룳πབྷℇଉ簿ّ뺦謃刨㫳ᔥ槦ᑃ璽皩宩傜䷗᥁ꊙ庉놨ꠑᯋ撿ᰃ⧹ⷅ瓴눥᮶â䏶뒾ञ代뫵ਫ㙺Ἑధॆ偟끎녘ৈ黗돃Ὄ檮㢈괿哟繹ꈥ垌喞ᘜ齈㒹뭹ᴴ轳浬曥瑾級꫼ᡊᴮ留㝸螱Ḵ嗳汏ᔔ藁嫜≵୛掣Ẁ恪⍩슅手彶䤇萴櫹ວჲ⽢а琨늪ㇲᭈ쇰ӳ㧠㥡놀Ꙭ碐ゼ⎴릊⍢蠐贈㧑请骰곮쀕렳ಊ祟㽖葬汓䢢兘뢺韴泧馆净벏ᵢ䕋僛♃⩖䎹ᑟ㓆虑鈃ڳ눼絇移ꝴ匯䇸㓀♔⳶㓧෴較õ乛ᔫ欚嗶᥄ꈢャ✉Ꝼ拂橳˯㶲ʤ댯ᡃ볿籚䊋釗‭␶傍궔樥泤趡鮚㺅卫㲴汒穿ⵑ衙ꞅ修쉚皨ƽ┐꣚漛༻ꔤ꾰䖓澐꣗輘醵醸乯ᦳ䕴䛯词麈鏡棧ᚒ᳜朝ꙧꬫ諒㜑瑕⨱㴥뎋面ᬀ滯憮௦庰民눿隆磁꼓詮䡎䵩费㤋腔杦薎㱿ᇆ韗騏⧢盚븎"5e4b128b:c ``` For some reason I end up with a leading `a` after decoding, which I need to remove first. ]
[Question] [ **This question already has answers here**: [Binary tree fractal](/questions/105840/binary-tree-fractal) (11 answers) Closed 5 years ago. **Challenge** In this challenge you will construct trees, in the form of ASCII Art using recursion. Basically you will generate the ASCII version of the [Fractal Tree](https://codegolf.stackexchange.com/questions/18785/create-a-fractal-tree) **Input** * Number of iterations `0 < N <= 5` **Output** * The `Nth` iteration of the Fractal Tree. It must be a matrix of 63 rows and 100 columns. (i.e. 6300 printable characters) It should be composed entirely of underscores and ones. **Rules** * Tree must be Y-shaped * Input `0 < N <= 5` * It must be a matrix of `63 rows` and `100 columns` * It must be composed entirely of underscores `_` and ones `1` * Do not include any extra leading or trailing spaces. --- ## Examples **N = 1** ``` ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ _________________________________1_______________________________1__________________________________ __________________________________1_____________________________1___________________________________ ___________________________________1___________________________1____________________________________ ____________________________________1_________________________1_____________________________________ _____________________________________1_______________________1______________________________________ ______________________________________1_____________________1_______________________________________ _______________________________________1___________________1________________________________________ ________________________________________1_________________1_________________________________________ _________________________________________1_______________1__________________________________________ __________________________________________1_____________1___________________________________________ ___________________________________________1___________1____________________________________________ ____________________________________________1_________1_____________________________________________ _____________________________________________1_______1______________________________________________ ______________________________________________1_____1_______________________________________________ _______________________________________________1___1________________________________________________ ________________________________________________1_1_________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ ``` **N = 2** ``` ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ ____________________________________________________________________________________________________ _________________________1_______________1_______________1_______________1__________________________ __________________________1_____________1_________________1_____________1___________________________ ___________________________1___________1___________________1___________1____________________________ ____________________________1_________1_____________________1_________1_____________________________ _____________________________1_______1_______________________1_______1______________________________ ______________________________1_____1_________________________1_____1_______________________________ _______________________________1___1___________________________1___1________________________________ ________________________________1_1_____________________________1_1_________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ __________________________________1_____________________________1___________________________________ ___________________________________1___________________________1____________________________________ ____________________________________1_________________________1_____________________________________ _____________________________________1_______________________1______________________________________ ______________________________________1_____________________1_______________________________________ _______________________________________1___________________1________________________________________ ________________________________________1_________________1_________________________________________ _________________________________________1_______________1__________________________________________ __________________________________________1_____________1___________________________________________ ___________________________________________1___________1____________________________________________ ____________________________________________1_________1_____________________________________________ _____________________________________________1_______1______________________________________________ ______________________________________________1_____1_______________________________________________ _______________________________________________1___1________________________________________________ ________________________________________________1_1_________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ ``` **N = 5** ``` ____________________________________________________________________________________________________ __________________1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1___________________ ___________________1___1___1___1___1___1___1___1___1___1___1___1___1___1___1___1____________________ ___________________1___1___1___1___1___1___1___1___1___1___1___1___1___1___1___1____________________ ____________________1_1_____1_1_____1_1_____1_1_____1_1_____1_1_____1_1_____1_1_____________________ _____________________1_______1_______1_______1_______1_______1_______1_______1______________________ _____________________1_______1_______1_______1_______1_______1_______1_______1______________________ _____________________1_______1_______1_______1_______1_______1_______1_______1______________________ ______________________1_____1_________1_____1_________1_____1_________1_____1_______________________ _______________________1___1___________1___1___________1___1___________1___1________________________ ________________________1_1_____________1_1_____________1_1_____________1_1_________________________ _________________________1_______________1_______________1_______________1__________________________ _________________________1_______________1_______________1_______________1__________________________ _________________________1_______________1_______________1_______________1__________________________ _________________________1_______________1_______________1_______________1__________________________ _________________________1_______________1_______________1_______________1__________________________ __________________________1_____________1_________________1_____________1___________________________ ___________________________1___________1___________________1___________1____________________________ ____________________________1_________1_____________________1_________1_____________________________ _____________________________1_______1_______________________1_______1______________________________ ______________________________1_____1_________________________1_____1_______________________________ _______________________________1___1___________________________1___1________________________________ ________________________________1_1_____________________________1_1_________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ _________________________________1_______________________________1__________________________________ __________________________________1_____________________________1___________________________________ ___________________________________1___________________________1____________________________________ ____________________________________1_________________________1_____________________________________ _____________________________________1_______________________1______________________________________ ______________________________________1_____________________1_______________________________________ _______________________________________1___________________1________________________________________ ________________________________________1_________________1_________________________________________ _________________________________________1_______________1__________________________________________ __________________________________________1_____________1___________________________________________ ___________________________________________1___________1____________________________________________ ____________________________________________1_________1_____________________________________________ _____________________________________________1_______1______________________________________________ ______________________________________________1_____1_______________________________________________ _______________________________________________1___1________________________________________________ ________________________________________________1_1_________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1__________________________________________________ ``` --- This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes win. [Answer] # [Python 2](https://docs.python.org/2/), ~~902~~ ~~518~~ 472 bytes ``` u='_';n='1';c=(31,47,55,59,62)[input()-1] p=[u*100]*64+[u*18+'1_'*32+u*18]+[u*19+'1___'*15+n+u*20]*2+[u*20+'1_1_____'*8+u*16]+[u*21+(n+u*7)*8+u*15]*3+[u*22+(n+u*5+n+u*9)*4+u*14]+[u*23+('1___1'+u*11)*4+u*13]+[u*24+('1_1'+u*13)*4+u*12]+[u*25+(n+u*15)*4+u*11]*4 m=13;r=17 for x in range(26,33):p+=[u*x+n+u*m+n+u*r+n+u*m+n+u*(x+1)];m-=2;r+=2 p+=[u*33+n+u*31+n+u*34]*9 m=29 for x in range(34,49):p+=[u*x+n+u*m+n+u*(x+1)];m-=2 p+=[u*49+n+u*50]*16 print'\n'.join(p[:63-c]+p[-c:]) ``` [Try it online!](https://tio.run/##bZDJbsMgEEDv/orc2OwqMwNOiMWXuCiqoi6uZIIsW0q/3jXgQ1T1AsN7swDxZ/66B1zXxbEr64JjwLqb4wS1PtXG1MbWLYp@CHGZuWjAV9H1i4Tj0ctWqxSeFYMrk4QqHXxmNrHrRsGosHHc0jEZPCaTXLLnVNLmEgTFU@ZJFGq8pMyx8NLHCqmT1aWGFM9zgCUIu6QidZZF0a6wKFN6gtkxeKmr0QF1k4NT9XGfDo/DEA7TW/h859jWROISVXr5I99jzOv0FPOHAuG7sXHYTcphVdKJsiUom/bSboPQ/p1Butb2vxlPffeW2mZhti@FtorTEGb2GtjL930IPPaXlpqbV7Fvbhcv1pV@AQ "Python 2 – Try It Online") Needs a whole load of golfing but at least it works. ]
[Question] [ Please note that this question is different from [this question](https://codegolf.stackexchange.com/questions/3989/implement-a-graphing-calculator). This one asks for graphical output, while the other one asks for ascii art. # Objective Help! Timmy's graphing calculator broke! His calculator cannot graph anymore. However, he has found a way to add new programs and functions to his calculator. Your job is to write a program/function that graphs equations. # Rules * Your program/function should take in a string in the form of `"y = random equation involving x"` and graph it on the coordinate grid. * Timmy's calculator doesn't have that much memory, so please try to make your code as short as possible. * The operations needed are addition (`+`), subtraction (`-`), multiplication (`*`), division (`/`), exponentiation(`^`) and grouping(`()`) * Your program/function should be able to graph from `x=-5` to `x=5`, and from `y=-5` to `y=5`. * Color, axis labels, the grid, numbers, scale, and animation are optional. * The minimum size of the image should be 50x50 pixels. # Test Cases ### Input `y = x ^ 2` ### Output ![A graph of y=x^2](https://i.stack.imgur.com/YdRnZ.png) ### Input `y = 4 * x + 3` ### Output ![A graph of y=4x+3](https://i.stack.imgur.com/yDIre.png) [Standard loopholes](http://meta.codegolf.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply. You may change the operators, but it adds +10% to your byte count. [Answer] # Matlab, 35 bytes ``` ezplot(input(''));axis([-5 5 -5 5]) ``` Input is a string like `'y=2*x^2'`. [Answer] # Mathematica, ~~89~~ 77 bytes ``` Plot[ToExpression[#~StringDrop~4],{x,-5,5},PlotRange->{-5,5},AspectRatio->1]& ``` Most of it is just formatting to make it look similar to the examples. Please inform me if something isn't required. Includes axis markers, which aren't explicitly disallowed. [Answer] # [RPL/2](http://www.rpl2.net/) 15\*1.1 = 16.5 ``` STEQ .5 *S DRAW ``` Timmy must key in the equation in capitals, e.g.'Y = X ^ 3', hence the 10% penalty. The .5 is just luck: the default box is -10…10 × -10…10 with RPL/2. [Answer] # [MATL](https://esolangs.org/wiki/MATL), 40 \* 1.1 = 44 ``` K0h)5:p'(-5:.1:5)'XHYXUHUw2$XG-5,5hth1ZG ``` This works in [current version (15.0.0)](https://github.com/lmendo/MATL/releases/tag/15.0.0) of the language. *EDIT (June 15, 2017): You can try it at [**MATL Online!**](https://matl.io/?code=K0h%295%3Ap%27%28-5%3A.1%3A5%29%27XHYXUHUw2%24XG-5%2C5hth1ZG&inputs=%27y+%3D+x.%5E2%2F5+%2B+0.6.%2a%28x-1%29+-+2%2a%28x-1%29.%5E%282%2F3%29%27&version=15.0.0)* `.*`, `./` and `.^` are for multiplication, division and power (that is, add a dot in front). The following shows an example result running on Matlab. [![enter image description here](https://i.stack.imgur.com/D1Wz7.png)](https://i.stack.imgur.com/D1Wz7.png) [![enter image description here](https://i.stack.imgur.com/nWilF.png)](https://i.stack.imgur.com/nWilF.png) ]
[Question] [ **This question already has answers here**: [Multiply without multiply [closed]](/questions/655/multiply-without-multiply) (17 answers) Closed 2 years ago. Your task, is simply to multiply 2 integers given in input, separated by a ",". The catch is, you cannot use the multiplication operator "\*", even if it is being used differently, or any loops whatsoever This is [code-golf](https://codegolf.stackexchange.com/questions/tagged/code-golf), so shortest code wins! Test cases: *i dont know if you even need it! lol* 1,0 -> 0 5,6 -> 30 3920,549 -> 2152080 [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` ',¡`иO ``` [Try it online](https://tio.run/##yy9OTMpM/f9fXefQwoQLO/z//ze2NDLQMTWxBAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3lf3WdQwsTLuzw/6/z31DHgMtUx4zL2NLIQMfUxBIA). Would be 2 bytes without the restricted input-format: ``` иO ``` [Try it online](https://tio.run/##yy9OTMpM/f//wg7///@NLY0MuExNLAE) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWXC/ws7/P/r/I@ONtQxiNVRiDbVMQNRxpZGBjqmJpaxsQA). **Explanation:** ``` ',¡ '# Split the (implicit) input-string on "," ` # Pop and push both values separated to the stack и # Repeat the first value the second value amount of times as list O # Sum that list # (after which the result is output implicitly) ``` [Answer] # [Python 3](https://docs.python.org/3/), 32 bytes ``` lambda x,y:eval("x"+chr(42)+"y") ``` [Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUaFCp9IqtSwxR0OpQkk7OaNIw8RIU1upUknzf0FRZl6JRpqGmY6ppuZ/AA "Python 3 – Try It Online") ]
[Question] [ This is inspired by my [python-ideas "new module loader" prank](https://github.com/kirbyfan64/pycob). Your task is to write a cat-like program that does the following: * Read the file on disk labeled `files`. Assume it exists. No error handling necessary. * The file contains a list of files separated by newlines. The file names may contain spaces. Print the file name and the contents to the screen like so: ``` <<<<myfile.txt file contents here <<<<another file.txt those file contents here ``` Also store the file name some sort of array/list. * Pick a random file name from the array and print: ``` fatal error: ? with file myfile executing 'rm -rf /' ``` replacing `myfile` with the randomly picked file name. * Loop forever. The program flow would be something like this: ``` file = open 'files' all files = empty list for filename in file print "<<<<" + filename contents = read contents of filename print contents add filename to all files bad file = random filename in all files print "fatal error: ?" print "with file " + bad file print "executing 'rf -rf /'" while true do end ``` Shortest entry wins. [Answer] # Pyth - 77 Can probably be golfed a lot more. ``` #FN'"files"+*\>4Njb'NaYN)"fatal error: ?"+"with file "OY"executing 'rm -rf /' ``` Won't work on the online interpreter because it doesn't allow unsafe operations. ``` # Infinite loop FN For N in '"files" Read file files as list of lines + Concat *\>4 4 >'s N File name jb Join by newlines 'N Readfile as list of lines aYN Append N to empty list ) Close for loop "fatal error: ?" Print message + Concatenation "with file " Message OY Random choice of file list "executing 'rm -rf /' Message with implicit closing quote ``` ]
[Question] [ # Guidelines ### Task Given two non-negative integers, find the sum of both numbers... to the power of 4. --- ### Examples `2, 3 -> 97` (2^4 + 3^4 = 97) `14, 6 -> 39712` (14^4 + 6^4 = 39712) `0, 25 -> 390625` (0^4 + 25^4 = 390625) --- ### Rules * You will only ever receive two non-negative integers as input (bonus points if you get it to work with negative integer input). * You can take the input however you would like (arrays, list, two separate arguments, comma-separated string) * You can either output your answer as a number or a string. * As this is code golf, the shortest answer in bytes will win. [Answer] # Regex `🐇` `m` (PCRE2 v10.35 or later), 10 bytes ``` ^(?*x+){4} ``` [Attempt This Online!](https://ato.pxeger.com/run?1=hVbLbttGFF1XXzFmAHuGGqei_IgjmjZcW4AF2HKgyGgaxyVoaiQRpoYEOYwfqbb9gG676aabAvmgdNkv6Z0HKcpSUcGihnfuPfc5Z_z71zCNi1x-_UkYfr2xtuM0zFh7-8C6_TZ4NWLjiDP07nTQbfunV2dd_7rfG_o_9s6G5-ig8SriYVyMGDpURq-nR41wGmTIT29ukYcG1g8PD_d3O8VPT08fhtP9hyn-sxDj7YO_fsbH9mOTfNmda8Hf370lL3UtiuzU89Om49Yc5SKL-ER6WsiiBKQsmB2t6B01Ii5QCkvhsyxLMhwmPBdIRWnPWJ4HE0bQl1yMOp0QNNDhITJiuVRyxkexizImiowjx52vYMr3MBkxiu6SJEaJNw7iXMIqNwbupr23f-s2EHyiMcKqYP6EGQzfaGGNg3XFr0_PTwYHNjGbFOXRM0vGuAr8-1JS0yeEKC_ygxN0rJMIk0KgDqoSJTI9S5khFUEHWS-SV8aWBVbWJ26Rqh5jmJapzqQqSmPeKHgeTTgboTjhE_0IeP7AMlcVbPbkh0EcQxgmd_Pm38VJeI_skKLPSTRC9igQAdROFkkukechLHdssrnAIAa72aw60zKdmQURxwCgAkxvYBBixnFKtp1br-XqFPR0oDT0LHzcsVxYNb1U_1gEH5_Cd4OAvADEnbYvoKlgK-EnsFDQdaCIp4WQ5ioxaCGyM1a-zwIRTn2Vi71Ya7SM5UUsqG6Baw7a-97HrpKMxzmDTcgXUpiI6ZKCnXxmoQAr0wk4cKX_WRrFDJuheP9uOCBp-Dr0IVhMqMH42B1c-cPu4LLXPxl2z0px98Ow2z_rnqFfjODy-mLYu-j1uxRtqijNr4mtRRYzvZHBSJpu1M-Hehq9WjG8lfr48B4I5o-zZOangRAs4ziDue9fX1wYgLoNHGbBHgWUtVx56_YNLF5BgQyqoSwhaG1S6brJewmgXcXRLKqDbDvErSmNWCr-VyljYZHlUcLXKiq34yRDim-eq1kGDomBpLE-2hGnehqJW56Bsj3PBIFcchLe-sS3wPWz57hqS1m8llyCiee1CJKeI14wd4EATmEKpVvNnvlir4oqTXJQWPJc2nL24IM9RRyaFIgkMk7NWKKmNCbusp0kSpC-gKtOnyI1yWPUclc1wA-WodoE2g-9C3EODTVxwKZ8NpEDXy7dO2QNxg0oNZvyMpMlW1aYIwY0vy62heeZdlzzutbXfOltxmYwDjgHRVWxrcctKBv0S4UjMTSaDKucgrIUfBkYqgdKutJwlY_wFgUsKVVBlBWWJFvjs06Hq7LfQeHuXa3uSZZfjXe5D-ifX39DQJuanFV4laamuuUTqg53naegQyrllvpbMAOszWGoVU4Gr1EPW2hz03jY8AyTDQZXA79_dXkyPD0ny1WpkVPJwCIrWA1btnbJZilRk9-aG3H-XyQFpMYYXmSxSn5aoXon9ftEbwK_VtedjhsuXv0f1B_fdtp0p-Hs0v1Gi7b3Go03jR3qqKVDYYvu0j26T9_QA_pWyh2HOm1t-y8 "C++ (GCC) – Attempt This Online") - PCRE2 v10.40+ Takes its input in comma-delimited unary, as a concatenation of strings of `x` characters whose lengths represent the numbers, separated by `,` characters. (Bonus: The number of arguments is variable, not just 2.) Returns its output as the number of ways the regex can match. (The rabbit emoji indicates this output method. It can yield outputs bigger than the input, and is really good at multiplying.) `^` anchors the expression to the beginning of each line, making it process each number in the list exactly once, thanks to the `m`ultiline flag. The result of each adds to the total (instead of multiplying the total), since they are independent matches not done in concert. Non-atomic lookahead, added to PCRE2 in v10.34 as `(*napla:`...`)` and given the `(?*`...`)` synonym in v10.35, makes calculating \$n^k\$, where \$k\$ is a constant, very easy in `🐇`-regex. `(?*x+){4}` is equivalent to `(?*x+)(?*x+)(?*x+)(?*x+)`. Each `(?*x+)` essentially picks a number in \$[1,n]\$, cycling through all the values effectively independently of the others, so the number of possible choices that lead to a full match is \$n^4\$. It would not be possible to emulate this kind of solution using lookbehind with recursion to emulate variable-length-lookbehind, because that requires using lookahead nested inside lookbehind, both of which are atomic – so only one possible match would be tried. And even if it were not for that problem, the engine will complain of "nested recursion at the same subject position", which is unavoidable. # Regex `🐇` (PCRE / Raku`:P5`), 27 bytes ``` (|xxx|((||){2}||)xx?)x*x*x+ ``` [Try it online!](https://tio.run/##dVThbts2EP6vp7h4aExaTGDZbdpaUYMuy7AfWVMYKbAiDQSFpmwhMiVQ0uwk9t89wB5xDzL3SEq23KRxLFPHu@@@@45HnudHU843vySSp9VEwGnOlTiefXD4LFIQ5je3EMC48@ticX83rL4@PPx1PTtZzMiGrJbL5YqQ1Yo@Ddb4XC7P6LKHH3dDf3TvMOjlQZi7nu/sUhXlJMl0rrZJJXK6b0sytIpo/tzvg5PIEnJclqFQKlOEZ7IowXDvzUVRRFNBnzDPaMTRAU5PobbqpbELOUl9UKKslATPXzuVLJKpFBNIMzm1j0gWC6F8k23@EPIoTbOqJFqq5iW8SzN@Dz1O4cm6u@4Wto@wJjZKJEEHB/Avv8EiUiFJTo@826DvgyVkS4OcBx1yNur4uHKD3P50KDk7x@8BRXuFkMNBWEKmgzX@FBcGuw2UyLwqdbgS0FPCh7ZGKEpeKhutRFGlpV1rNeO4ECUDLA5ZTsuZ3cn@FrzM1M3w1qZC1ACsEtk8T1KBshzzEJMTyuDz@fgi/O3q@uPlJazs25fr398xOLSZ7aJJ1acWM4mBHChBG/1i0@KYYFnozaCjgQxHBRFSMuHwajKCV8U3iYethWnz1MDtjiHtXS/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nNldlyr_QqiTMQqFkudDm790CfIg5F8kUcGqOmCVFbKhOnridpEVafwZVnTVGYZC1qOasSYAdLV1sEyg-1C3AGBTV-wKZ8t5END5fmbbIG4xqE2m15lzVps76_QAw4fZ1rS8MzbbdidK2pRW02YzPoBpyBoEpYc96ErEG5lDcSQ6NJr4omKDLB68CQPBDSiYaLfIQhCqpWlRNFgiWjVsir1-Mq67eQtztHi7uS0lf9rZcB_fP7VwQcqZlYuVdKal6rH1B1tqukBAVSIXfU_5IYYGzOQiVz0nmNetBBm5vGwoZraGswuBx4F5dvj4cnZ6SelQo3FXQr0pxVsGVpazq1QE18a66_xX9xFHAaY3gZxSr3aYFyTqqXh94Eei3vNu033LL659IfP3a6dKdhv6J7jQ7t7jYarxs71FZDm8IWfUV36R59Tffpz3Ldtqnd1br_Ag "C++ (GCC) – Attempt This Online") - PCRE2 v10.40+ [Try it online!](https://tio.run/##TU/basJAEH3frxiDNLtxqtlYtTUE2weferFCWyhWxJYEt8SYZhVWkvjYD@gn9kfSiRRaBg7DOTPnzKRhFvernQ7hdnJ3PX72Yb2HkwgCGD9d3cB0lrfWw9AM73udORygGUQqUXpF7XTWKTcHZ@4z2mjqwPUh2mQQqyTUXEAOKiIacr3cg2WVfj0jfQZHftF@Wy0z3QgCF3LioI69jClWp7HachttBL171duMNxcIzqkkEOGH9ZJYMBr901wkUUCjQa7CP3qlmUq2ZNd@36ik9hJ0rw3fn1@EB4g4J229TIdgG9s44m9O0JnO5PGhHcU7vfLLkv0@XPHCGFNwXhQi90pCY0bCOFStqvKwy@QZ9pmLXo@xAeuiPLYSScIz7GEfB3iOFzUvJUrvBw "Perl 6 – Try It Online") - Raku (Perl 6) ``` ( # apply once with tail = N | xxx # apply once with tail = N-3 | ((||){2}||) # apply 3**2+2==11 times... xx? # ...with tail = N-1 or N-2 ) x*x*x+ # tail'th pentatope number ``` Although PCRE and Raku are the only regex engines currently capable of counting this regex's number of possible matches without their source code being patched, this regex itself only uses a **POSIX ERE** level of functionality, so is in theory universally compatible with all regex engines. Lacking non-atomic lookahead, the only golf-efficient way I can think of to cause the number of possible matches to be \$n^k\$, where \$k\$ is a constant, is to decompose \$n^k\$ into a sum of \$n\$-simplex numbers. \$4\$-simplex numbers have the formula \$S\_4(n)=n(n+1)(n+2)(n+3)/24\$. So what we want is to solve is: $$n^4=a⋅S\_4(n)+b⋅S\_4(n-1)+c⋅S\_4(n-2)+d⋅S\_4(n-3)$$ for \$a,b,c,d\$. The general form of this turns out to have the \$k\$th [Euler's triangle](https://en.wikipedia.org/wiki/Eulerian_number) row as its solution. In the case of \$n^4\$, this is \$1,11,11,1\$. The `🐇`-regex for \$S\_4(n)\$ is `x*x*x+`: [Try it online!](https://tio.run/##hVX9btpIEP@fp5i4urALpgWqqyKME@UIUiK1SUWJrtcUWY69hlXN2rLXJckp/94D3CPegxw3@wE4AekWMLs7M7/5Hkd53plH0fpNzBIuGHweTcb9YHRzMQ5ur6@mwe9XF9NLOGm84SJKq5jBMI8K1n@7OG1Ei7CAIL@bgQ8T57fV6sf9@@qPx8ev08WH1YKsH1r4aa/pa4rjQiv3g7zd82qwpSy4mCvc3R3P8JaFy9M9vtMGFxJy3MqAFUVWkCgTpQRtU2vJyjKcMwp/ljIeDCLkgOEQ7LXa6nsm4tSDgsmqENDznvcw1TnKYubCfZalkPlJmJYKVquxcHf9Xz/MvAbg4gkQHZ5gzixGYLmIwSEmvrejy/PJSYtaogslf2JZQraGv9vc1PgppVqLWiSDM@NElFUSBrB1lCr3HC0G2oIBOK@c18KOg1LOd@HQbTyStCoXxpNtUBrPjUqUfC5YDGkm5uYRinLFCk8HbPkYRGGaohnWd3sK7tMs@gGtyIWfGY@hFYcyxNipIKkt@D4QRWnR4x0Gtdjt9jYzXZuZZcgFQQBtYH6HhZAyQXLa6c38rmdcMNUBeeQ75GzgeLhr@7n5cyg5G@HviOJ9hYjv@4HEpKKsgp/jRkPXgbjIK6nEtWOYQmgVbHNehjJaBNqX1m5v0ApWVql0TQo821Zfrr6N9U2SlAyJ6C@6MJeLFwyt7CeLJErZTGB7bfQvc54yYoviy@fphObR2yhAYwl1Lca38eQmmI4nn66uz6fji831@Ot0fH2hzsfaJvtvLenSXQUfFViANvb1btBPy1dz3d@LRoDnULIgKbJlkIdSskKQAqv8@vbjRwtQl8HWlexBYhA3O/8Q3cKSPRT0YFuCGwi3VpfuoTp7DWBUpXzJ6yCdHvVqTDHL5f8yFSyqipJn4iCjVptkBejp8rStXJwYKQ5gYhqZC9fUHvU2Fa/TgyKii@EJZcaJZtikH/Mvei7kWYlkQ8GBHpNmp2mVqiV6KrbIc@TX63wwEOry7AAutDV/G3oUB4bo7rDMrFXqBFuZ053otXszD4fNEiNBSheaD01lGAaoROLMr8lvg8B9oXpw6IueB@02r3u8KconCmiUUkKa3wW6hKFDbl2fCXF@ieGfv/4GfLVwJJkRgobVtJleUk35srp0YdY7Co3m2BD6u6tp3Ns0Um/POIM77MLxsdVx5Nuum0xuJsH1zafz6eiSvhDU5Vdrr83EkEXFXulg@NbZk91Nf5zf1uMDk1yt58bueaixkoIxsvNvv6ENw/ZM6xPREHFmbAe28QRfHetup9/9N0rScF6uO6mW6Zz8Bw "C++ (gcc) – Try It Online") What we need to do is have it match \$1\$ time on \$n\$, \$11\$ times on \$n-1\$, \$11\$ times on \$n-2\$, and \$1\$ time on \$n-3\$. Multiplying the number of possible matches of a subexpression can be done simply by concatenating, for example, `(|||)` to multiply by \$4\$. As a standalone regex returning \$4(n+1)\$, this can simply be `|||`: [Try it online!](https://tio.run/##hVXrTttIFP6fpzi4WjKTOG1MtRWKMYgNkUBqoUqDtluKLGOPk1GdsWWPS2Hh7z5AH7EPsuyZixNDIq0Fzsy5fOd@HBfFYB7HT68SlnLB4ON4OtkLxxcnk/Dy/GwW/nl2MjuF/c4rLuKsThgcFHHJ9l4vDjvxIiohLK6uIYCp88ft7bebt/Vfd3efZ4t3twvy9PDw8ERfkh0XekUQFn3Pb2FWsuRirkDXNJ4jlUXLww25ww4XEgo8ypCVZV6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"C++ (gcc) – Try It Online") - note that this is \$4(n+1)\$ because an empty regex returns \$n+1\$ possible matches. The simplest choice for multiplying by \$11\$ would be `(||||||||||)`, but it turns out this can be optimized down to `((||){2}||)`, as \$11=3^2+2\$, where `(||){2}` is \$3^2\$ and each additional `|` adds \$1\$. Larger numbers can be additionally optimized by factorization. Additionally, there's expressions like `(|){3,5}` for \$56=2^3+2^4+2^5\$. So, `((||){2}||)xx?` is the part where it's creating \$11\$ possibilities each, `((||){2}||)`, in which the subsequent expression is evaluated on \$n-1\$ or \$n-2\$, using `xx?`. The first several n-simplex functions are as follows, in `🐇`-regex: \$S\_0(n)\$: `^` (returns \$1\$) \$S\_1(n)\$: `x` (returns \$n\$) \$S\_2(n)\$: `x+` (triangular numbers) \$S\_3(n)\$: `x*x+` (tetrahedral numbers) \$S\_4(n)\$: `x*x*x+` (pentatope numbers) \$S\_5(n)\$: `x(x*){4}` \$S\_6(n)\$: `x(x*){5}` The first several \$n^k\$ are as follows: \$n^0\$: [Try it online!](https://tio.run/##hVXrTttIFP6fpzi4WjKTON2YaisUYxAbIoHUQpUGbbeUtYw9TkZ1xpY9bgor/vYB@oj7IMueuTgxJNJa4Mycy3fux3FRDOZx/PQqYSkXDD6Mp5ODcHx1NgmvLy9m4R8XZ7NzOOy84iLO6oTBURGX7OD14rgTL6ISwuLmFgKYOr@vVl/v3tR/3t9/mi3erhbk6a8n@pLouNArgrDoe34LsZIlF3MFuaHxHKksWh5vyR13uJBQ4FGGrCzzksS5qCRod3pLVlXRnFH4u5LJaBSjBBwdgSWro6YzkWQ@lEzWpQDPf9zCVPc4T5gLd3meQR6kUVYpWG3Gwt0c/Pb21u8APjwFojMTzpnFCK0UMTjEpPZ6fH46PexRy3Sh4g8sT8na8V8bSkueUqqtqIfkcGKCiPNawgjWgVIVnqPVQHswAudF8FrZcVDL@SIcus5HmtXVwkSyTkrnsVOLis8FSyDLxdy8IlGtWOnrhC3vwzjKMnTDxm5v4V2Wx1@hF7vwLecJ9JJIRpg7lSR1hCAAojg9ur/BoBa7319XZmgrs4y4IAigHSxusBEyJkhBB95tMPRNCKY7oIgDh5yMHB9P/aAwPw4lJ2P836NIrxHxzUEosaioq@DneNDQbSAuiloqdR0YlhB6JWvuy0jGi1DH0tucDVrJqjqTrimBbyfq48XniaakacWQifFiCHO5eCbQy7@xWKKWrQROVmN/WfCMEdsUHz/MprSIX8chOkuoazE@T6ZX4WwyfX9xeTqbnDXkyafZ5PJM3fe1T/bXejKkmw7eK7EBbe7b06DfVq4VerCVjRDvkWRhWubLsIikZKUgJXb55fW7dxagrYOjK9l3iUlsTsEuvoUlWygYwboFGwi31Zfurj57CWBMZXzJ2yADj/otoYQV8n@FShbXZcVzsVNQm03zEvR2eVh3Lm6MDHcvMYPMhWt6j/pNx@vyoIoYYnoimXOiBZryY/2F50KRV8g2HNzlCekOutaoeoSncosye0G7z0cjoYgnO3Chr@X74FFcGGK4wTK7VpkTbGVuN8Lre7c@LpslZoJULnS/d5VjmKAKmbdBS3@dBB4INYNHgfB86Pd5O@KmKR8ooFPKCOl@ERgSpg6ldX@mxPklgX9@/AT8tHBkmRWCjrWsmVlSQ/m8u3RjticKneY4EPpv09N4tmWk/pZzBvdoCPv71sZeYKduOr2ahpdX709n43P6TFG3X2u8mo0hy5q9sMHwq7Olu9n@uL9txDs2uXoeO5v3rsFKS8bIJr7tgTYC6zttb0TDxJ2xXtgmEvx0PA0H3nD4b5xm0bx6GmRaaXD4Hw "C++ (gcc) – Try It Online") `^` \$n^1\$: [Try it online!](https://tio.run/##hVXrTttIFP6fpzi4WphJnDam2grFGMSGSCC1oUqDtluKLGOPk1GdsWWPy2XF332AfcR9kM2euTgxJNJa4Mycy3fux3FR9OdxvHqTsJQLBp9H0/FhOLo6H4fXk8tZ@Pvl@ewCjjpvuIizOmFwXMQlO3y7OOnEi6iEsLi5hQCmzm/39z/u3td/PD5@nS0@3C/I6mFFXxMdF7pFEBY9z28hVrLkYq4gNzSeI5VFy5MtuZMOFxIKPMqQlWV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IW@lu@DR3FhiOEGy@xaZU6wlbndCK/v3fq4bJaYCVK50L3vKscwQRUyb4OW/joJPBBqBo8C4fnQ7/N2xE1TPlJAp5QR0v0uMCRMHUrr/kyJ80sC//z1N@CnhSPLrBB0rGXNzJIaypfdpRuzPVHoNMeB0H@bnsazLSP1t5wzuEdD2N@3NvYCO3XT6dU0vLz6dDobn9MXirr9WuPVbAxZ1uyVDYZfnS3dzfbH/W0j3rHJ1fPU2bx3DVZaMkY28W0PtBFY32l7Ixom7oz1wjaR4KfjeTjwhsN/4zSL5tXzINNKg8P/AA "C++ (gcc) – Try It Online") `x?x+` (squares) \$n^3\$: [Try it online!](https://tio.run/##hVXrTttIFP6fpzi4WphJnDam2grFGMSGSCC1UKVB2y1FlrHHyajO2LLHJbDh7z7APuI@yGbPXJIYEmktcOZyzndu3zmOi6I7iePlm4SlXDD4PBgND8PB9fkwvLm6HIe/X56PL@Co9YaLOKsTBsdFXLLDt9OTVjyNSgiL2zsIYOT89vDw4/59/cfj49fx9MPDlCzJYj5fkMViQed03p53lvS1jONCuwjCouP5DQOVLLmYKAubM57jKYtmJ1tyJy0uJBS4lCEry7wkcS4qCdq79oxVVTRhFP6sZNLvxygBx8dgj9VSnzORZD6UTNalAM9/3sJU@zhPmAv3eZ5BHqRRVilYbcbC3R7@@uHObwE@PAWiExVOmMUIrRQxOMRk@mZwcTY6alN76ULFn1iekrXj71YnDXlKqbaiHpLDqQkizmsJfVgHSlV4jlYD7UEfnFfBa2XHQS3nu3DoOh9pVldTE8k6Ka3nVi0qPhEsgSwXE/OKRPXASl8nbPYYxlGWoRs2drsL77M8/gHt2IWfOU@gnUQywtypJKklBAEQddOm@xsMarE7nXVlerYys4gLggDaweIWiZAxQQra9e6Cnm9CMOyAIg4cctp3fFx1gsL8OJScDvB/j@J5jYjvD0OJRUVdBT/BhYZuAnFR1FKp68CwhNAu2Wo/i2Q8DXUs7c3aoJWsqjPpmhL4tsG@XH4b6pM0rRheYrwYwkROXwi0858slqhlK4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F8@j0e0iN/GIRpLqGsxvg9HF@F4OPp0dn48Hp4syMOv4@H5iTpva5vs21rSo6sK3iqxAG3sm92gn5av4XqwFo0Qz5FkYVrms7CIpGSlICVW@fnlx48WoCmDrSvZXGIQF7tg072FJWso6MGyBBcQbqMu3U119hrAqMr4jDdBuh71G0wJK@RvmUoW12XFc7GRUatN8xL0dLlfVi5OjAxHNjGNzIVrao/6i4rX6UER0cPwRDLnRDMs0o/5F54LRV7htbnBT0BCdro7VqlawlOxRZ6toFnn/b5QxKMNuNDR/B3wKA4M0VthmVmr1Al2a05Xwut41z4OmxlGglQu7Mx3lGEYoAovr4OG/DIIPBCqBw8C4fnQ6fCmx4uivKeARiklZOeHQJcwdMit6zMlzh8J/Pv3P4CfFo5XZoSgYQ1tppdUU76sLl2YzY5Cozk2hP6tahr3No3UXzPO4B70YHvb6tgKbNeNRhej8Pzi0/F4cEpfCOrya7TXYmLIsmavdDD86qzJrqY/zm/r8YZJrtZTa/Xc1FhpyRhZ@bfe0IZheabNiWgucWYsB7bxBD8dz72u1/svTrNoUj13My3T3f8f "C++ (gcc) – Try It Online") `x(|x{5}|x((|){3,5}|)(|xxx)|(|)((||||){2,3}|)xxx?)(x*){5}` \$n^7\$: [Try it online!](https://tio.run/##hVX9TttIEP8/TzG4OthNnF4MPYRiDOIgEkgtVGnQ9UqRZex1sqqztux1CR/59x7gHvEe5LjZjySGRLpVYu/uzPzmexwXRXccxy/vEpZyweDz6XCwG55enQ3C68uLUfjHxdnoHA5a77iIszphcFjEJdt9PzlqxZOohLC4uYUAhs7v9/c/7vbqPx8evo4m@/cT8jIjz7On/fkzvunTnrs/V@cPc/o8w5tnSvChFn3adffmZktmM3qMdC3yYW5YLANFapsi4At9q8txoV0EYdHx/IahlSy5GCtLV3c8x1sWTY/W@I5aXEgocCtDVpZ5SeJcVBK0l@0pq6pozCg8VTLp92PkgMNDsNdqq@@ZSDIfSibrUoDnz9cw1TnOE@bCXZ5nkAdplFUKVquxcDe7v@3f@i3A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iCwhSmBZfqw/d2zIsxLZmoOfioi0e21jVD7ckblFmR2v2eeDAZfE4y240FXyXXAoLgzeX2PpXSvNcXavbzfc6Tq3Li6bGWaClDa067Z0DBNUIvPWa@ivkpB4XM7goccdF7rdpBnxsikfKaBT0ghpf@cYEqYOpVV/xsT6JYJ//vob8NOSIEuvEHSsYU3PkhzKl92lGrM5Ueh0ggOh/tY9jWdTRupuOKdxD/uwu2ts7Hhm6kajq5F/efXpZHx6Tl8oqvZrjNdyY4iiYq9sMPzqbOiutz/ubxPxlk0un0Vr/d42WHHBGFnHtznQWmB1p82NqJm4M1YLW0eCn47nfs/p/xvGaTApn3up0ukd/Ac "C++ (gcc) – Try It Online") `x(|x{7}|x((||){5}||||)(|x{5})|xx(||){4}((|){4,5}|||||)(|xxx)|xxx((|){8}((|){2,5}|)|||)x?)(x*){7}` Perl 5 severely undercounts the number of possible matches ([Attempt This Online](https://ato.pxeger.com/run?1=RU-9asMwEKZrtr6BECJItZ3YnkpkxQmka6dubRCpiUGgJq7sgIqsjn2Arl0ypE-RN-nYJ-nZDpSD-_nuu7vvvk7V1ujjz9X1yxsihiOn98VGIzLlUIpstXxYzv2o3BtKahHzbM6ZQ6qEirnKqF2D8NMOc48WWtSVVg3FEQ7rw3PdwIgMoyRM2Pa1I-X_aAw4mxHJeLerhosbs9BZytxCPyZrAT5ecz9CqL-sLgBRmegJkAUBc6QASYhiiy1RTLxPaT4jhtE8d0FAijD2rPujHo97qb1SeCPhaJBO1ASj349PhCekAGILLe-lvLtfSfl9aMro9kxba21Ladsyl3rw1ubM3oAFA-N4Cac4SuMh_wM)); see below for a workaround. But Raku's Perl 5 compatibility mode (`:P5` adverb) fully evaluates every choice path (and not just due to its `:ex`haustive adverb – it does the same without it). # Regex `🐇` (Perl / PCRE / Raku`:P5`), 30 bytes ``` (|xxx|(()||||||||||)xx?)x*x*x+ ``` [Try it online!](https://tio.run/##RY9BbsIwEEX3PoVleWE3U4gDgRYTAhLddtUlkgURSKlMkiap5Cpxlz1Aj9iLpAOVqL3xvD9/5rs61jYezh@U15p2tsz2lvKxxjJZbjcvm5Unp7IWvElCvVxp2dH8hJXsqjovWsp2BdMeVYUWmzTvh6bFbgP3CpQ8vl309J@GyOWCG41TqOAWx63RVdm8FQwYINGEUp7hNvpa5sWVnvdVxxxz3Pi1lcnnWKQLXkuRpl0Q8AxCLzHxX6CbCTtHjP58fVM24hmm6zEj8d6Yp@etMYPonXO9ELK/HelcKt0d3mAYIpgQNYUZCSGKCZmTCajrUwFKMIUYZjCHB3i8cIXfjX4B "Perl 5 – Try It Online") - Perl v5.28.2 / [Attempt This Online!](https://ato.pxeger.com/run?1=RVA9bsIwFN59CsvyYDcPiBP-igkBia6dOlayaESkVAbSECRXSTr2AF27MLTX6D1Ye4SeoA-oqN9gv-_n-dN7_8iXhd0fflbPlBeaVnaTLCzlHY1tNJ7P7maThqSbQvBt5OvxRMuKZil2ssqLbF1Sdr9mukFWocVG293DtkS1gZYCJZdPRz7-R33E5YgbjVOo4BbHTdGV26wUDBggogmlPMHf6OMmW5_Q1SKvmGOOm2ZqZfTSEfGIF1LEceV5PAG_kZj4HOhiQmWb0e_XN8raPMF0NWYkTWPMze3cmM9dmbaGX6J2ztVCyPpypHOxdFdY3lm0_7sOYQAhUV3oEx-CHiEDEoI6PRUgBV3oQR8GMITrI65wBcHZ-ws "Perl - Attempt This Online") - Perl v5.36+ [Try it online!](https://tio.run/##dVTbbts4EH3XV0xcNCYtJrDiNu1aUYNuNos@ZJvCSIEu0kBQaEoWIlMCJa2dNH7tB@wn7oesOyQlW25SX6nhzJkzZzjkRXGQcL5@kUqe1VMBJwVX4nD2zuGzSEFYXN9AAJPe74vF3e2o/vv@/svV7HgxI2vyuFwuHwmhj5sXXS5P6XKAb3dNf47oMRgUQVi4nu9ss5XVNM11uq5JpTLZtaU5WkU0f@r3zkllBQUuq1AolSvCc1lWYOgP5qIso0TQb5hnPOboACcn0Fj10tiFnGY@KFHVSoLnr5xalmkixRSyXCb2J5Ll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FI9QMg5aetlMgTb2MYRf32CznQmD/fNMNrqlVcU7Ofhku@NMXvOxf43hDEjYRzKRlm2scNkF/vMxXaPsQHroDxCiSRhF3vYxwGe4XnFS4my/Q0 "Perl 6 – Try It Online") - Raku (Perl 6) The part in the 27 byte version that is undercounted by Perl is `((||){2}||)`, the expression that multiplies possibilities by 11. Perl forces *any* loop to exit after making a zero-width match (whereas PCRE only does so on loops whose quantifier has no maximum, which I think is more logical), so `(||){2}` needs to be changed to `(||)(||)`, adding 1 byte. Perl prunes a group's alternatives down to one if they are all identical, but doesn't do this if even one alternative differs from the others. So `(||)` needs to be changed to `(()||)` in both places, adding 4 bytes. After all that, it becomes `((()||)(()||)||)`. But that's longer than `(()||||||||||)`, so we use the latter instead, at just 3 bytes longer than `((||){2}||)`. # Regex `🐇` `m` (PCRE), ~~73~~ 69 bytes Without decomposing a fourth power into pentatope numbers, I'm pretty sure this is the best solution possible (it might golf down a tiny bit more than this, but not much): ``` ^(?=(x*)\1{3}(xx())?(x())?)((?=\1(x*))(x+(|||)|\3(|)|\5).*(?=\7$)){4} ``` [Try it online!](https://tio.run/##hVXrUuJIFP7PU7SZLe0OrUPA2xKj5SpVUqU4xWDt7KibiqGBlKGTymXEC3/3AfYR90HWPX1JCMLUUhA655z@zrW/9uN4e@z775@GbBRwhr6c9TtN9@z6vOPe9LoD9/fu@eACHdY@BdwP8yFDR7GfsObO5LjmT7wEufHtPXJQ3/jt6enxoZX/8fz8bTDZf5rg9z/xiYNnJrmzXltzPJthQk6wfBIMqjtLKAme1fHb2xt5u2th8dwjO6bQHvxCyOvu/J18BDYoMmPHjeuWXYkqzZKAj0VYC1kQgZR50@MVu@NawDMUwzJzWZJECfYjnmZIpmROWZp6Y0bQa5oN220fLNDREdJisZRyxoehjRKW5QlHlj1fwRTvfjRkFD1EUYgiZ@SFqYCVbjTcbXNv/96uIfgEI4Rldd0x0xiutsIKB6v23JxdnPYPTaKVFKXBC4tGuAz8cyGp2BNCpBfxwRE6UUn4UZ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) – Try It Online") - PCRE2 v10.33 / [Attempt This Online!](https://ato.pxeger.com/run?1=hVbLUuNGFF3HX9FoUtAtN8SygWEsBMWAq3AVjymPqUwGiErIbVuF3FLpMZiHt_mAbLPJJsv5ILLMl-T2Q7KMnYrLklu37z332Uf-47sfh3kqLnfk-9-vjc0w9hPW3Nwzbl977wZsGHCGPh33Ok33-PKk415ddPvuz92T_inaq70LuB_mA4b2pdHW-KDmj70EufH1LXJQz_j48HB_18p_eXz80h_vPozxX3k23Nx77fyKDx08NcmN9dya4ekUE3KI5Z1g2LqxxCbB0zp-eXkhLzctLO47ZMsUu-9_JOR5e6bA_v7hA3nrx6DIjB03rlt2Jcg0SwI-ElHOZUEEUuZNDpb0DmoBz1AMy8xlSRIl2I94miGZoTlhaeqNGEHPaTZot33QQPv7SIvFUsoZH4Q2SliWJxxZ9mwJUzz70YBRdBdFIYqcoRemAla60XDXzZ3dW7uG4BMMEZbFdkdMY7haCyscrLp1dXx61Nszid6kKA2eWDTEZeA_FZKKPiFEehEfHKFDlYQf5RlqozJRItIzpBmSEbSR8SZ5aWwYYGXccIOU9RjCpI1VJmVRarNaztNgxNkAhREfqZvH0weW2LJgk0fX98IQwtC56yf3Loz8e2T6FH2LggEyB17mQe1EkcQSOQ7CYsck63MMorHr9bIzDd2ZiRdwDAAywPgaBiFkHMdk07p1GrZKQU0Hin3HwIdtw4ZV3YnVj0Hw4TFcawTkOSC2mm4GTQVbAT-ChYSuAgU8zjNhLhODFiIzYcXzxMv8sStzMedrhZawNA8zqlpg60P6ufu1IyXDYcpgE_KFFEbZeEHBjL4xPwMr3Qk4rIX_SRyEDOuh-Pyp3yOxv-W7ECwmVGN87fQu3X6nd969OOp3Tgpx50u_c3HSOUEvWnB-ddbvnnUvOhStyyj1r46tQeYzvZbASOpuVM-HvGu9SjGcpfq48OxlzB0m0cSNvSxjCccJzP3F1dmZBqjawGHO2DSDshYrZ9W-hsVLKJBBOZQFBK1MKl01eW8BlKswmARVkE2L2BWlAYuz_1VKmJ8naRDxlYrS7TBKkOSbp3KWgUNCIHisjnbAqZpGYhdnoGjPE0EgF5yEN274Brh-cixbbkmLLcElmDhOgyDhOeA5s-cI4BSmULhV7JnO98qo4igFhQXPhS1nDy7YU8ShSV4WBdqpHktUF8bEXrQTRAnSN3Dl6ZOkJniMGvayBvjBIlSTQPuhdz5OoaE6DtgU9zqy4OLCvUVWYFyDUr0uXoSiZIsKM8SA5lfFNvc8UY4rXlf6mi08TdgExgGnoCgrtjHdgLJBv2Q4AkOhibCKKShKwReBoXqgpCoNfwMGeIMClpDKIIoKC5Kt8Fm7zWXZ76Bw97ZSdwTLL8e72Af0z2-_I6BNRc4yvFJTUd3iCZWHu8pT0CGZckN-58wAa30YKpUTwSvU_QZaX9ce1hzNZL3eZc-9uDw_6h-fksWqVMipYOAsyVkFW7R2wWYhUZ3fijfi7L9ICkiNMTzPYpn8lEL5TKrvE7UJ_Fq-7lTc8OJV_6D-fG01aatmbdPdWoM2d2q197UWteTSorBFt-kO3aXv6R79IOSWRa2msv0X "C++ (GCC) – Attempt This Online") - PCRE2 v10.40+ ``` ^ # tail = N = input number (?= (x*)\1{3} # \1 = floor(tail / 4) (()xx)?(()x)? # \3,\5 = {tail % 4} in binary: # \3 set|unset = 2's place digit 1|0 # \5 set|unset = 1's place digit 1|0 ) ( # Manipulate the number of possible matches to be exactly \1 * 4 + \2 == N (?=\1(x*)) # \7 = tail - \1 ( x+(|||) # Add \1 * 4 to the number of possibilities of this iteration | \3(|)|\5 # Add \3*2 + \5 (where set=1 and unset=0) to the number of # possibilities of this iteration ) .*(?=\7$) # tail = \7, i.e. the next multiple of \1 down from what it # was when \7 was captured above. ){4} # Iterate the above 4 times, such that after finishing, each # iteration could have been at any one of the N states. ``` This method does eventually win out against simplex decomposition: 1: `x`    `x` 2: `x?x+`    `^(?=(x*)\1(x()|))\2(x+(|)|\3).*(?=\1$)(?4)` 3: `(|xx|(|||)x)x*x+`    `^(?=(x*)\1\1(x())?(x())?)((?=\1(x*))(x+(||)|\3|\5).*(?=\7$)){3}` 4: `(|xxx|((||){2}||)xx?)x*x*x+`    `^(?=(x*)\1{3}(xx())?(x())?)((?=\1(x*))(x+(|||)|\3(|)|\5).*(?=\7$)){4}` 5: `x(|x{4}|x((||||){2}|)(|xx)|((|){6}||)xx)(x*){4}`    `^(?=(x*)\1{4}(xx())?(x())?(x())?)((?=\1(x*))(x+(||||)|\3(|)|\5|\7).*(?=\9$)){5}` 6: `x(|x{5}|x((|){3,5}|)(|xxx)|(|)((||||){2,3}|)xxx?)(x*){5}`    `^(?=(x*)\1{5}(xx())?(xx())?(x())?)((?=\1(x*))(x+(|||||)|\3(|)|\5(|)|\7).*(?=\9$)){6}` 7: `x(|x{6}|x(|){3,6}(|x{4})|xx(||)((||||||){2,3}|||||)(|xx)|xxx(|){4}((||||){2,3}|))(x*){6}`    `^(?=(x*)\1{6}(xxx())?(xx())?(x())?)((?=\1(x*))(x+(||||||)|\3(||)|\5(|)|\7).*(?=\9$)){7}` 8: `x(|x{7}|x((||){5}||||)(|x{5})|xx(||){4}((|){4,5}|||||)(|xxx)|xxx((|){8}((|){2,5}|)|||)x?)(x*){7}`    `^(?=(x*)\1{7}(x{4}())?(xx())?(x())?)((?=\1(x*))(x+(|){3}|\3(|||)|\5(|)|\7).*(?=\9$)){8}` [Answer] # [CP-1610](https://en.wikipedia.org/wiki/General_Instrument_CP1600) assembly, 30 DECLEs = 38 bytes Let's try this on a processor lacking a multiply instruction. This code is intended to be run on an [Intellivision](https://en.wikipedia.org/wiki/Intellivision). CP-1610 instructions are encoded with 10-bit values, known as *'DECLE'* s. This subroutine is 30 DECLEs long, starting at $4808 and ending at $4825. [Takes input in registers](https://codegolf.meta.stackexchange.com/a/7425/58563) *R0* and *R3*. Saves the result in *R2*. ``` ROMW 10 ; use 10-bit ROM ORG $4800 ; map program at address $4800 4800 02B8 000E MVII #14, R0 ; example call 4802 02BB 0006 MVII #6, R3 4804 0004 0148 0008 CALL addX4Y4 4807 0017 DECR PC ; loop forever 4808 0275 addX4Y4 PSHR R5 ; push the return address 4809 0004 0148 001A CALL square ; compute R2 = R0^2 480C 0004 0148 0019 CALL square2 ; compute R2 = R2^2 480F 0272 PSHR R2 ; push this result on the stack 4810 0098 MOVR R3, R0 ; compute R2 = R3^2 4811 0004 0148 001A CALL square 4814 0004 0148 0019 CALL square2 ; compute R2 = R2^2 4817 02F2 ADD@ R6, R2 ; add this result to the intermediate one 4818 02B7 PULR PC ; return 4819 0090 square2 MOVR R2, R0 ; copy R2 to R0 481A 0081 square MOVR R0, R1 ; copy R0 to R1 481B 01D2 CLRR R2 ; initialize R2 = result 481C 0200 0002 B halve ; start by halving R1 481E 00C2 add ADDR R0, R2 ; add R0 to R2 481F 0048 loop SLL R0 ; double R0 4820 0079 halve SARC R1 ; halve R1 4821 0221 0004 BC add ; was the LSB set? 4823 022C 0005 BNEQ loop ; is R1 now equal to zero? 4825 00AF JR R5 ; return ``` ### Example run Running the above code (with *R0* = 14 and *R3* = 6) gives: ``` > b 4807 Set breakpoint at $4807 > r Hit breakpoint at $4807 0900 0000 9B20 0006 01FE 4817 02F1 4807 S-----iq DECR R7 ^^^^ ``` *R2* is set to $9B20, which is 39712 in decimal. [Answer] # Perl, 12 bytes Includes `+1` for `p` Works for 1 or more numbers each given on a separate line on STDIN ``` (echo 2; echo 3) | perl -pe '$\+=$_**4}{' ``` [Answer] # [Haskell](https://www.haskell.org/), 11 bytes ``` sum.map(^4) ``` This is a function that takes the parameters as a list. [Try it online!](https://tio.run/##y0gszk7Nyfn/P822uDRXLzexQCPORPN/bmJmnoKtQko@F2dBUWZeiYKKQppCtJGOgnEsioihiY6CGaqQgY6CkWnsfwA "Haskell – Try It Online") [Answer] # [><>](https://esolangs.org/wiki/Fish), 11 bytes ``` :*:*$:*:*+n ``` [Try it online!](https://tio.run/##S8sszvj/30rLSksFRGjn/f//X7fMCIiNAQ "><> – Try It Online") Takes values through the `-v` flag. Dupe and multipy, dupe and multiply, and repeat with the other value before adding the two together and printing. [Answer] ## [Retina](https://github.com/m-ender/retina/wiki/The-Language), 9 bytes ``` .+ **** _ ``` [Try it online!](https://tio.run/##K0otycxLNPz/X0@bSwsIuOL//zc04TIDAA "Retina – Try It Online") Input should be linefeed-separated. ### Explanation ``` .+ **** ``` `*` is Retina's repetition operator. It has implicit operands `$&` and `_`, respectively, so the substitution pattern is short for `$&*$&*$&*$&*_`. It's also right-associative, if the regex matches a decimal number **n**, this generates a string of **n4** underscores (i.e. a unary representation of the fourth power of **n**). ``` _ ``` To sum the two results and convert the sum back to decimal, we simply count the number of underscores in the string. [Answer] # [Japt](https://github.com/ETHproductions/japt), 3 bytes Takes input as an array of integers; can handle negatives and more than 2 integers at a time. Add `N` at the beginning to take input as individual integers. ``` xp4 ``` [Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=eHA0&input=WzE0LDZd) --- ## Explanation `p4` raises each element to the power of 4 and `x` reduces by addition. [Answer] # [Pyt](https://github.com/mudkip201/pyt), 2 [bytes](https://github.com/mudkip201/pyt/wiki/Codepage) ``` ⁴Ʃ ``` [Try it online!](https://tio.run/##K6gs@f//UeOWYyv//4820TGJBQA) Takes input as a list. [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 5 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set") Anonymous tacit prefix function. Takes a list as argument. The list may have any length and contain any numbers, even complex ones. ``` +.*∘4 ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R2wRtPa1HHTNMgBwFIx0FYy6uNAVDEx0FMxDDQEfByBQA "APL (Dyalog Unicode) – Try It Online") `+.*` is a variant on matrix product, `+.×` as follows: `a b+.×c d` is `(a×c)+(b×d)` and `a b+.×c` is `(a×c)+(b×c)`. So `a b+.*c` is `(a*c)+(b*c)`. `*` is power. `∘4` curry four as right argument. This results in a monadic function `(a*4)+(b*4)`. [Answer] # [J](http://jsoftware.com/), 7 6 bytes -1 byte thanks to Adám ``` 1#.^&4 ``` [Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DZX14tRM/mtyKXClJmfkK6QpGCkYw5iGJgpmcHEDBSNTBDveUCHeSCHeWCHeRMHI@D8A "J – Try It Online") Works for lists with arbitrary length `^&4` - each item of the list to the 4-th power `1#.` - sum of all 4-th powers by base-1 conversion [Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/tfUdrOJMrP5rcilwpSZn5CukKRgpGMOYhiYKZnBxAwUjUwQ73lAh3kgh3lgh3kTByPg/AA "J – Try It Online") ## Alternative # [J](http://jsoftware.com/), 7 bytes ``` +/ .^4: ``` This is a variant of the matrix product, analogue of Adám's APL solution [Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/tfUV9OJMrP5rcilwpSZn5CukKRgpGMOYhiYKZnBxAwUjUwQ73lAh3kgh3lgh3kTByPg/AA "J – Try It Online") [Answer] # Python 3, 20 bytes ``` lambda x,y:x**4+y**4 ``` [Answer] # [MATL](https://github.com/lmendo/MATL), 3 bytes ``` K^s ``` [Try it online!](https://tio.run/##y00syfn/3zuu@P//aEMTHbNYAA "MATL – Try It Online") This can handle more than two input values, as well as negative inputs. ### Explanation: Fasten your seat belts, this might blow your mind! ``` % Implicit input K % Push literal 4 ^ % Raise each element of the input vector to the 4th power s % Sum ``` Also works: ``` 4^s % Push 4 and raise input to it, then sum UUs % Square input twice, then sum ``` [Answer] # JavaScript (ES7), 15 bytes Does exactly what it says on the tin. ``` a=>b=>a**4+b**4 ``` ### Test cases ``` let f = a=>b=>a**4+b**4 console.log(f(2)(3)) console.log(f(14)(6)) console.log(f(0)(25)) ``` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes ``` 4mO ``` [Try it online!](https://tio.run/##MzBNTDJM/f/fJNf///9oQxMdXbNYAA "05AB1E – Try It Online") **Explanation** ``` 4m # raise each to the power of 4 O # sum ``` [Answer] # [Julia](http://julialang.org/), 11 bytes ``` a$b=a^4+b^4 ``` [Try it online!](https://tio.run/##yyrNyUw0@/8/USXJNjHORDspzuR/QVFmXklOnoahiYqZJheMZ6BiZKr5HwA "Julia 0.6 – Try It Online") --- # [Julia](http://julialang.org/), 12 bytes ``` !a=sum(a.^4) ``` [Try it online!](https://tio.run/##yyrNyUw0@/9fMdG2uDRXI1EvzkTzf0FRZl5JTp6GYrShiYJZrCYXQsBAwcg0VvM/AA "Julia 0.6 – Try It Online") [Answer] # Excel, 10 bytes ``` =A1^4+B1^4 ``` Nothing to see here. [Answer] # [C (gcc)](https://gcc.gnu.org/), 26 bytes ``` f(a,b){a=a*a*a*a+b*b*b*b;} ``` [Try it online!](https://tio.run/##S9ZNT07@/z9NI1EnSbM60TZRCwy1k7TA0Lr2f25iZp6GZnVBUWZeSZqGkmpKDRgp6aRpGOkYawIpQxMdMxBtoGNkqqkJ1AIA "C (gcc) – Try It Online") [Answer] ## C, C++ => 29 bytes -1 byte thanks to Jonathan Frech ``` #define Q(a,b)a*a*a*a+b*b*b*b ``` Test cases : ``` #include <stdio.h> int main() { printf("Q(%d,%d) = %d\n", 2, 3, Q(2, 3)); printf("Q(%d,%d) = %d\n", 14, 6, Q(14, 6)); printf("Q(%d,%d) = %d\n", 0, 25, Q(0, 25)); } ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes ``` *4S ``` [Try it online!](https://tio.run/##y0rNyan8/1/LJPj///9GOgrGAA "Jelly – Try It Online") [Answer] # [Triangularity](https://github.com/Mr-Xcoder/Triangularity), 31 bytes ``` ...)... ..IEM.. .)4s^}. u...... ``` [Try it online!](https://tio.run/##KynKTMxLL81JLMosqfz/X09PTxOIufT0PF19QbSmSXFcrR5XqR4Y/P8fbaRjHAsA "Triangularity – Try It Online") [Answer] # [C (gcc)](https://gcc.gnu.org/), 0 + 24 bytes Compile this code ``` main(){ printf("%d\n",x(2,3)); printf("%d\n",x(14,6)); printf("%d\n",x(0,25)); } ``` With this flag: ``` -D=x(a,b)a*a*a*a+b*b*b*b ``` [Try it online! (GCC Tio)](https://tio.run/##S9ZNT07@//9/bmJmnoZmNRdnQVFmXkmahpJqSkyekk6FhpGOsaamNaa4oYmOGVYJAx0jU5BE7f9/yWk5ienF/3VdbCs0EnWSNBO1wFA7SQsMAQ "C (gcc) – Try It Online") [Try it online! (Bash Compile example)](https://tio.run/##S0oszvifmpyRr6CknJmXnFOakqpgU1ySkpmvl2GnpGBnp5Col8wFUZCbmJmnoVmNJqqgUFCUmVeSphGjpJoSkxejpFOhYaRjrKlpTYRCQxMdM@JUGugYmWKqrIXzudKTk0EMBaWY/7outhUaiTpJmolaYKidpAWGMf@VuPT0E/XyS0v@AwA "Bash – Try It Online") [Answer] # [R](https://www.r-project.org/), 16 bytes ``` pryr::f(x^4+y^4) ``` [Try it online!](https://tio.run/##K/r/P81Gt6CossjKKk2jIs5EuzLORPN/moaRjoKxJleahqGJjoIZiGGgo2BkqvkfAA "R – Try It Online") [Answer] ## Ruby, 16 bytes ``` ->a,b{a**4+b**4} ``` [Try It Online!](https://tio.run/##KypNqvz/P81W1y5RJ6k6UUvLRDsJSNRycRUopEUb6RjHghkGOkamsf//AwA) [Answer] # Java 8, 21 bytes ``` a->b->a*a*a*a+b*b*b*b ``` [Try it online.](https://tio.run/##jc5NC4JAEAbgu79ijmq5lH1cLI9Bh04eo8O4mqyt66KjIOJvt8X0nLwwvDAPzOTYolfqVOXJZ@QS6xoeKFRvAdSEJDjkRrCGhGTvRnESpWK3uVzuitIsrbbr0FzCEDhcYUQvjL0Q3Smb2J0yBuYygBm6iaU5P3/RliKBwnxmR1QJlT1f6PQTjbqa0oKVDTFtNiSVzRlqLTvbd@ZycJzgH94fF31eoXcL9k8/PVjD@AU) [Answer] # [Perl 6](http://perl6.org/), 9 bytes ``` *⁴+*⁴ ``` [Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPtf61HjFm0Q8d9aoTixUkFJJV7B1k6hOk2hRiW@VkkhLb9IwcZIwdhOR8HG0ETBDEQbKBiZ2ln/BwA "Perl 6 – Try It Online") [Answer] # Pyth, 5 ``` sm^d4 ``` [Online test](https://pyth.herokuapp.com/?code=sm%5Ed4&input=%5B2%2C3%5D&test_suite=1&test_suite_input=%5B2%2C%203%5D%0A%5B16%2C%206%5D%0A%5B0%2C%2025%5D&debug=0). ``` ^d4 # lambda to take 4th power Q # implicit input m # map lambda over input s # sum ``` [Answer] # [Attache](https://github.com/ConorOBrien-Foxx/attache), 8 bytes ``` Sum@`^&4 ``` [Try it online!](https://tio.run/##NYwxC8IwEEb3@xU3FNFyg9bqXNBZBN2OE2O8xAyGYs7fHwvSb3pveJ8zc/6l9aghZeUmUL1838P9tuirwLLFh8aU0bRYyhHbFZxUn4WbcfRRYM7MEwNO445wK/TnTU@4n2VN2O0EROD8Sdmu0@PBFS0cCM1L/QE "Attache – Try It Online") Takes input as a pair of integers. ## Explanation This is a composition of two functions: * `Sum` * ``^&4` The first executed is ``^&4`, which is equivalent to: ``` `^&4 RBond[`^, 4] RBond[{_1 ^ _2}, 4] {_1 ^ 4} ``` That is, a function that raises its argument to the fourth power. This vectorizes over the input array. Then, `Sum` takes the sum of these elements. ## Alternative approaches ``` Sum@`^&4@V ?? 11 bytes, input is two arguments {Sum[_^4]} ?? 11 bytes, input is array {_^4+_2^4} ?? 11 bytes, input is two arguments ``` [Answer] # [Pyramid Scheme](https://github.com/ConorOBrien-Foxx/Pyramid-Scheme), 220 bytes ``` ^ / \ / \ / + \ / \ ^---------^ /^\ /^\ ^---^ ^---^ /#\ /4\ /#\ /4\ ^--- --- ^--- --- /l\ /l\ /ine\ /ine\ ----- ----- ``` [Try it online!](https://tio.run/##TY3dCoAwCEbvfQqhywihehwRogYNVkRd9fRWrv0IsnPchx73OW1@6a55dZtTxVIChQkZKsFKX2srp/9NA@lS/ftIOEUlhr6I5LDFqGGkkQtB/MSvMwFSyMsCA/ndRTcCO2tupNrD8AA "Pyramid Scheme – Try It Online") `line` pyramids obtain a line from STDIN, `#` pyramids cast their arguments into numbers, `^` pyramids perform exponentiation, and the `+` pyramid adds two things together. [Answer] # Minkolang 0.15, 10 bytes ``` $n4;r4;+N. ``` [Try it here.](http://play.starmaninnovations.com/minkolang/?code=%24n4%3Br4%3B%2BN%2E&input=2%203) ## Explanation ``` $n4;r4;+N. $n take all input as numbers [a, b] 4; raise to the fourth [a, b^4] r reverse stack [b^4, a] 4; raise to the fourth [b^4, a^4] + add [b^4 + a^4] N output [] . terminate ``` [Answer] # [D](https://dlang.org/), 25 bytes ``` (int x,int y)=>x^^4+y^^4; ``` [Try it online!](https://tio.run/##S/mfWFqSr5Bm@18jM69EoUIHRFZq2tpVxMWZaFcCCev/mbkF@UUlCsUlKXpAnJlvzVWWn5mikJuYmaehWc1VXpRZkpqTp5GmYaRjrKlpzVX7HwA "D – Try It Online") A simple lambda that performs exponentiation on each of its arguments, with `^^` being the exponentiation operator. ]
[Question] [ (Taken from <https://en.wikipedia.org/wiki/File:Tangential_quadrilateral.svg>) [![Tangential quadrilateral](https://i.stack.imgur.com/lg5ce.png)](https://i.stack.imgur.com/lg5ce.png) A tangential quadrilateral (see example above) is a quadrilateral in which a circle can be inscribed. Your task is to find the possible value of `d` given `a`, `b`, and `c`. # Specs * `a`, `b`, `c` will all be positive integers. * If no possible value of `d` exists, output `0`. # Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest solution in bytes wins. # Testcases ``` a b c d 3 4 4 3 1 2 3 2 1 5 3 0 ``` [Answer] # Dyalog APL, 4 bytes ``` 0⌈-/ ``` [Try it online!](http://tryapl.org/?a=f%u21900%u2308-/%20%u22C4%20f%203%204%204%20%u22C4%20f%201%202%203%20%u22C4%20f%201%205%203&run) ### How it works ``` 0⌈-/ Monadic function train. Argument: (a b c) -/ Reduce by subtraction. APL evaluates everything from right to left, so this computes a - b - c = a - (b - c) = a - b + c. 0⌈ Take the maximum of 0 and a - b + c. ``` [Answer] # Piet, 32 Codels [enter image description here](https://i.stack.imgur.com/u3EaB.png) Codelsize 20: [![enter image description here](https://i.stack.imgur.com/4p4AF.png)](https://i.stack.imgur.com/4p4AF.png) ### Notes * Pretty straightforward. Could be 7x3=21 Codels if it wasn't for the termination, [but it seems like thats required by default.](http://meta.codegolf.stackexchange.com/questions/4782/do-programs-have-to-terminate) ### Npiet trace images Valid input [1, 2, 3] [![enter image description here](https://i.stack.imgur.com/zvkdR.png)](https://i.stack.imgur.com/zvkdR.png) Invalid input [1, 5, 3] [![enter image description here](https://i.stack.imgur.com/slkpL.png)](https://i.stack.imgur.com/slkpL.png) [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), ~~5~~ 4 bytes Input is taken as: ``` b a c ``` Code: ``` -+0M ``` Explanation: ``` # Inputs: b, a, c - # Substract, (a - b). + # Add with implicit input, (a - b + c). 0 # Push zero on top of the stack. M # Get the largest number that exists in the stack and implicitly print that value. ``` [Try it online!](http://05ab1e.tryitonline.net/#code=LSswTQ&input=NAozCjQ) [Answer] # [Jelly](http://github.com/DennisMitchell/jelly), 5 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` _@/»0 ``` [Try it online!](http://jelly.tryitonline.net/#code=X0Avwrsw&input=&args=MywgNCwgNA) or [verify all test cases](http://jelly.tryitonline.net/#code=X0AvwrswCsOH4oKsRw&input=&args=WzMsIDQsIDRdLCBbMSwgMiwgM10sIFsxLCA1LCAzXQ). ### How it works ``` _@/»0 Main link. Argument: [a, b, c] _@/ Reduce by swapped subtraction. This computes (a _@ b) _@ c = c - (b - a) = c - b + a. »0 Take the maximum of 0 and c - b + a. ``` [Answer] # MATL, 6 bytes ``` -+OvX> ``` My very first MATL answer! It can probably be shorter, I'd love tips! Input is backwards, e.g.: ``` c b a ``` [Try it online!](http://matl.tryitonline.net/#code=LStPdlg-&input=Mwo0CjQ). Explanation: ``` - #Subtract the top two numbers (c and b) + #Add the top two numbers (c-b and a) O #Push a 0 v #Concatenate this into a array X> #Print the smallest value of the array ``` [Answer] # [Cubix](https://github.com/ETHproductions/cubix), 12 ~~9~~ bytes This turned out longer than I wanted and then I messed up the spec. I might be able to knock out a byte or 2. ``` @w+?II-.\0O@ ``` Wraps onto a cube with side length 2 ``` @ w + ? I I - . \ 0 O @ . . . . . . . . . . . . ``` Gets `II` integer input twice, `-.` subtract followed by noop, `\` redirect down (in this case around), hits the second `I` input again, `+` adds, `?` conditional that turns left on negative, right on positive and straight through for zero. Turning left (invalid negative) `w` change lane to the right onto the literal `0` heading right through the `O@` output and terminate. Straight through (invalid zero) hits `\` reflector and head right onto the literal `0` and the `O@` output terminate. Turning right (valid positive) travels around the cube, hitting the `O` output on the bottom face, onto the `w` change lane right, that switches the lane to the `@` terminate. [Try it here](https://ethproductions.github.io/cubix) [Answer] # J, ~~12~~ ~~9~~ ~~8~~ 5 bytes Input is given as `a, b, c`. Saved a byte inspired by using Dennis's subtraction method. ``` 0>.-/ ``` ## Explanation ``` 0>.-/ -/ reduce argument over subtraction 0>. greater of the reduction and 0 ``` ## Test cases ``` rem =: 0>.-/ rem 3 3 4 4 rem 1 2 3 2 rem 1 5 3 0 rem"1 > (3 3 4 ; 1 2 3 ; 1 5 3) 4 2 0 ``` --- Previously: (`a,c,b` input) `+/@}:-{:)`, `+/@(}:,-@{:)` [Answer] # Python, 25 bytes ``` lambda a,b,c:max(0,a-b+c) ``` [Answer] ## PowerShell, ~~41~~ 38 bytes ``` param($a,$b,$c)[math]::Max(0,$a+$c-$b) ``` Pretty straightforward implementation of the [Pitot theorem](https://en.wikipedia.org/wiki/Pitot_theorem) (*thanks to Martin for remembering the name of it*). Saved 3 bytes by using the .NET `[math]::Max()` function. [Answer] # Jolf, 4 bytes ``` \r0m4 ``` Replace `\r` with a literal return, or [try it here!](http://ethproductions.github.io/Jolf/#code=CjBtNA&input=WzMsIDQsIDRd) Explanation: ``` \r0m4 m4 anti-sum of implicit input \r0 max of `0` and the anti-sum ``` [Answer] # Reng v.3.3, 33 bytes ``` ii+i-:²1#x1ø :x²eq!vx1+#x ~n%2+< ``` Takes input like `a c b`. [Try it here!](https://jsfiddle.net/Conor_OBrien/avnLdwtq/) The calculation is simple. `i` gets input, so `ii+` is `a + c`, and `i-` is then `(a + c) - b`. Very simple stuff. The hard part is taking the max with `0`. "What!? How could it be that hard?" Well, I didn't implement inequality in Reng. So we'll have to use math! **Observation 1:** `max(a,b) = (a+b+|a-b|)/2` **Observation 2:** `max(a,0) = (a+|a|)/2` **Observation 3:** `|a| = Sqrt[a^2]` **Observation 4:** Reng doesn't have square roots, either. Nor does it have power. But knowing that we'll only be taking the square roots of perfect squares, we can use trial and error, starting at 1. That is, our algorithm can look like this: ``` x = 1 to a, iterate: if x * x == a break, return X ``` Since we always have `k` being a perfect square, this algorithm always terminates. So, into the rest of the code explanation! ``` ii+i-:²1#x1ø :x²eq!vx1+#x ~n%2+< ``` ## part 1: initialization I've already explained how `ii+i-` works, so let's look at the rest of the line. ``` :²1#x1ø ``` `:` duplicates this number. The bottom number will be `a` in `(a + |a|)/2`. Now, we need to take the absolute value of the top value. We can do this using observations 3 and 4. `²` squares the top value, and `1#x` initializes our counter `x` with `1`. Then we go to the next line with `1ø` ## part 2: square root loop ``` :x²eq!vx1+#x ``` `:` duplicates our maximum value `a` from the top of the stack (for the equality check). `x²` squares our counter `x` and `e` pushes a Boolean representing the equality of `x²` and `a`. If they are equal, `q!` breaks out of the loop by going down (`v`), leaving `|a|` on the stack. Otherwise, we increment `x` (`x1+`) and set `x` to that value (`#x`). ## finalization ``` ~n%2+< ``` `<` redirects the program to look left. shhh it saves bytes. It's equivalent to this series of steps: ``` +2%n~ ``` `+` adds the top two of the stack, thus implementing the first part of `(a + |a|)/2`. `2%` divides that sum by two (`%` is division here because `/` is a mirror). Lastly, we output this as a number (`n`) and terminates the program (`~`). [Answer] ## JavaScript (ES6), 22 bytes ``` (a,b,c)=>a+c>b?a+c-b:0 ``` `Math.max` is too long and there isn't a long enough common subexpression to deduplicate, so that's basically it. If a falsy value had been acceptable, then 21 bytes: `(a,b,c)=>a+c>b&&a+c-b`. [Answer] # Mathematica, 13 bytes ``` Max[##2-#,0]& ``` Anonymous function. Takes input in the order *b*, *a*, *c*. The `##2-#` is just some crazy `Sequence`craft that computes `#2+#3-#`. The `Max[..,0]` just takes the maximum of the result and 0. [Answer] ## Pyke, 6 bytes ``` -+0]Se ``` Explanation: ``` +- - do the mathsy bit (a+c)-b 0] - create a list with [0, ^] Se - Get the maximum value ``` [Try it here!](http://pyke.catbus.co.uk/?code=-%2B0%5DSe&input=5%0A3%0A1) [Answer] ## ><>, 7 bytes ``` -+:0)*n ``` Input assumed to be on the stack, in the order a, c, b. It does c-b+a, and compares that with zero. Then it outputs either 0 or the answer before it terminates. [Try it online!](https://tio.run/##S8sszvj/X1fbykBTK@8/kFWmYGgAIs1BhCkA) [Answer] # MATLAB / Octave, 20 bytes ``` @(a,b,c)max(c-b+a,0) ``` Anonymous function that accepts the three inputs and returns the length of the fourth side. Can be called using `ans(a,b,c)`. [Demo with all test cases](https://ideone.com/YHALyX) [Answer] # Hexagony, 16 ``` ?{?>+'<'-{?/@.!< ``` [Try it online!](http://hexagony.tryitonline.net/#code=P3s_PisnPCctez8vQC4hPA&input=MSA1IDI) In expanded form: ``` ? { ? > + ' < ' - { ? / @ . ! < . . . ``` This is actually a fairly simple program. First, we always execute the instructions in this order: `?{?'-{?/<'+` which just reads some values and computes `a-b+c`. Now if the value is positive, the `>` sends us north west and we bounce to the lower right `<` and then print the number (`!`) and exit (`@`). The only really fancy part of the program is how it handles if the result was negative. If this happens, we move south west and execute: `'?`{` which actually attempts to read another integer after moving the memory pointer around a bit and we land back on the place where we read another integer. Since the read fails to find a value, it returns zero and because zero isn't positive we wrap to the upper edge of the hexagon in this configuration, so we hit `/<!.@` to print out the zero and exit. [Answer] # Python 2, ~~59~~ ~~53~~ 47 bytes *-6 bytes thanks to @KennyLau!* ``` i=input;a,b,c=i(),i(),i();print(0,a+c-b)[b<a+c] ``` Takes 3 inputs, a, b and c. Then applies the Pitot Theorem (d=a+c-b). **Ungolfed** ``` a = input() b = input() c = input() if b < a + c: print a + c - b else: print 0 ``` ]
[Question] [ **This question already exists**: [Encode the simple substitution cipher [duplicate]](/questions/98301/encode-the-simple-substitution-cipher) Closed 7 years ago. A [substitution cipher](https://en.wikipedia.org/wiki/Substitution_cipher) is an encoding method where each letter in the alphabet is replaced with a fixed, different one; for example, given the following substitution map: ``` abcdefghijklmnopqrstuvwxyz || qwertyuiopasdfghjklzxcvbnm ``` The phrase "we all love cryptography" would be encoded as "vt qss sgct eknhzgukqhin". The program will continuously read its input, one line at time; the first line will contain the substitution map, in the form of all 26 letters, in any order, without repetitions, missing letters or extraneous characters; it will be interpreted as "the first letter is the substitution for A, the second letter is the substitution for B [...] the 26th letter is the substitution for Z"; no output will be provided after reading it. For each subsequent line, the program will output the encoded text corresponding to the line. Only letters will be encoded; numbers, symbols and whitespaces will be simply copied to the output. For simplicity, all input (including the substitution map) will only contain lowercase characters. Sample input: ``` qwertyuiopasdfghjklzxcvbnm hello bye! i don't know. ``` Sample output: ``` itssg wnt! o rgf'z afgv. ``` As usual, the shortest solution wins. --- Additional clarifications on input: * **The program must read its input stream** (I thought that was clear); command line parameters, files, named pipes, network sockets, quantum entanglement or extra sensorial perceptions are not allowed. * **The input must include only the actual text to be processed**; quotes, brackets, commas or any other symbol, if found, should simply be copied to the output as they are. * **No additional characters should be required in the input**. If your program requires the input text to be placed in quotes, brackets, commas or any other delimiter, then *You Are Doing It Wrong* (TM). * "Line" is defined as a string of characters followed by a newline; the actual implementation of "newline" if usually left to the OS, but if you need to go into its details, just use whatever you prefer. * An empty line is no special case; the program could either print an empty line or do nothing, but it should not print any actual text, crash, exit, destroy the operating system, set fire to the house, collapse the Sun in a black hole, summon demons from other planes of existence or replace your toothpaste with mayonnaise. * There is no requirement for the program to run interactively; it's free to suck all its input in and then print all its output; there is also not any time limit on its execution, although it would be definitely preferable for it to terminate before the heat death of the universe. [Answer] ## Convex, ~~4~~ ~~6~~ 5 bytes [Crossed out 4 is still regular 4 :(](https://codegolf.stackexchange.com/a/73584/46231) **Note: As @Dennis pointed out, the input format I was using was not up to spec. This version should comply with the new rules, though.** ``` lqT@Ë ``` [Try it online](http://convex.tryitonline.net/#code=bHFUQMOL&input=cXdlcnR5dWlvcGFzZGZnaGprbHp4Y3Zibm0KaGVsbG8KYnllIQppIGRvbid0IGtub3cu) Explanation: ``` l Read a line from input q Read the rest of the input T Push lowercase alphabet ("abcdefghijklmnopqrstuvwxyz") @ Rotate the top 3 items on the stack. er Transliterate Implied output ``` Thanks to @LuisMendo for pointing out an error in the program [Answer] # Pyth, 7 bytes ``` V.zXNGz ``` [Try it online!](http://pyth.herokuapp.com/?code=V.zXNGz&input=qwertyuiopasdfghjklzxcvbnm%0Ahello%0Abye!%0Ai+don%27t+know.&debug=0) How it works: ``` V.zXNGz G = "abcdefghijklmnopqrstuvwxyz" z = input() V.z for N in all_input(): XNGz N.translate(G,z) <--- automatically printed ``` [Answer] # JavaScript ES6, ~~65~~ ~~62~~ 49 bytes Saved 2 bytes thanks to Neil. ``` (a,i)=>a.replace(/./g,x=>i[x.charCodeAt()-97]||x) ``` Takes an string of lines `a` and a dictionary `i`. [Answer] ## sh + coreutils, 16 bytes ``` read s;tr a-z $s ``` 15 bytes if input is from a terminal: ``` tr a-z `sed 1q` ``` [Answer] # [CJam](https://sourceforge.net/projects/cjam/), ~~12~~ 8 bytes *4 bytes saved thanks to Dennis!* ``` l_$q\@er ``` [**Try it online!**](http://cjam.tryitonline.net/#code=bF8kcVxAZXI&input=cXdlcnR5dWlvcGFzZGZnaGprbHp4Y3Zibm0KaGVsbG8KYnllIQppIGRvbid0IGtub3cu) ### Explanation ``` l e# read a line _$ e# fancy way to obtain string "abc...z". Thanks to Dennis! q e# read the rest of input as a string with newlines \@ e# swap, rotate er e# transliterate. Implicit display ``` [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 5 bytes Code: ``` [A¹‡, ``` Explanation: ``` [ # Start an infinite loop. A # Push the lowercase alphabet. ¹ # Push the first input (substitution map). ‡ # Transliterate. Since the arity of this function is 3 and there are only 2 values on the stack, it implicitly takes a line of input. , # Pop and print. ``` So this continually reads a line of input and prints a line of input after. Uses **CP-1252** encoding. This is what I got with the console version: ``` D:\Golfing\05AB1E>C:\Python34\python.exe 05AB1E.py test.abe qwertyuiopasdfghjklzxcvbnm hello itssg welcome vtsegdt greetings, planet! ukttzoful, hsqftz! ``` Trying this online might be a bit weird, since 05AB1E is trying to read another line of input, but there is none, so you need to kill it to receive output (doesn't work all the time). It *might* be a better idea to do this with the **console version** of 05AB1E. [Try it online!](http://05ab1e.tryitonline.net/#code=W0HCueKAoSw&input=cXdlcnR5dWlvcGFzZGZnaGprbHp4Y3Zibm0KaGVsbG8KYnllIQppIGRvbid0IGtub3cu). [Answer] # JavaScript 89 ``` for(i=prompt,x=i(),n='';p=i();n+=p.replace(/./g,m=>x[m.charCodeAt(0)-97])+"\n"); alert(n) ``` [Answer] # [MATL](https://github.com/lmendo/MATL), 14 bytes ``` jXKx`jHY2KXEDT ``` The program exits with an error after producing the correct output (allowed by default). [**Try it online**](http://matl.tryitonline.net/#code=alhLeGBqSFkyS1hFRFQ&input=cXdlcnR5dWlvcGFzZGZnaGprbHp4Y3Zibm0KaGVsbG8KYnllIQppIGRvbid0IGtub3cuCgoK) [Answer] # Ruby, ~~35~~ ~~31~~ 29 bytes Credit to @QPaysTaxes for the `$_` trick, I had assumed that reading more from the STDIN object `$<` would change that variable, but it doesn't. ``` gets $><<$<.read.tr('a-z',$_) ``` `String#tr` is basically a cipher substitution function, making things quite simple. [Answer] # Pyth, ~~34 Bytes~~ ~~31 Bytes~~ ~~29 Bytes~~ 27 Bytes Saved ~~3~~ ~~5~~ 7 bytes thanks to Kenny Lau ``` jmsm?&<JCk123>J96@hQ-J97kdt ``` [Try it out!](http://pyth.herokuapp.com/?code=jmsm%3F%26%3CJCk123%3EJ96%40hQ-J97kdt&input=[%22qwertyuiopasdfghjklzxcvbnm%22%2C%22hello%22%2C%22bye!%22%2C%22i+don%27t+know.%22]&debug=0) [Answer] # Python 3, 50 bytes ``` lambda s,k:s.translate(dict(zip(range(97,122),k))) ``` Or if we really have to implement an infinite loop: # Python 3, 70 bytes ``` t=dict(zip(range(97,122),input())) while 1:print(input().translate(t)) ``` [Answer] # Factor, 155 bytes The logic is actually pretty simple, it's just constraining to the REPL requirement that costs. ``` [let "abcdefghijklmnopqrstuvwxyz" readln string>array bi@ zip :> T [ t ] [ T readln string>array [ dup T key? [ T at ] [ ] if ] map "" join print ] while ] ``` Readable single-function version (don't ever write code like this): ``` :: monolithic-repl ( -- ) "abcdefghijklmnopqrstuvwxyz" readln string>array bi@ zip :> table [ t ] [ table readln string>array [ dup table key? [ table at ] [ ] if ] map "" join print ] while ; ``` Readable, *Factored* version: ``` :: cipher-print ( cipher-table -- ) readln string>array [ dup cipher-table key? [ cipher-table at ] [ ] if ] map "" join print ; : cipher-get ( -- cipher ) "abcdefghijklmnopqrstuvwxyz" readln string>array bi@ zip ; :: cipher-repl ( -- ) cipher-get :> table [ t ] [ table cipher-print ] while ; ``` [Answer] ## C++, 154 Bytes ``` #include <iostream.h> #include "string.h" using namespace std; void encript_string() { char en[26],in[1024]; string s=cin.getline(); strcpy(en,s.c_str()); while(1){ s=cin.get_line(); strcpy(in,s.c_str()); int i=0,m=0; while(in[i] != 10) { m=in[i]-97; cout<<en[m]; } cout<<"\n"; } } ``` ]
[Question] [ As we all know, negative press covfefe has been conspiring to bring down the American president for some months now. There's also, definitely, an algorithm in play in that word. Covfe is a refreshing caffeinated beverage, and following the president's remarks it's clear the word can now be appended with successive f's and e's, so long as they are not adjacent to their own letters. So I wrote some code to generate the inevitable covfefe triangle. The output looks like this: ``` covfefe covfefef covfefefe covfefefef covfefefefe covfefefefef covfefefefefe covfefefefefef covfefefefefefe covfefefefefefef covfefefefefefefe covfefefefefefefef covfefefefefefefefe covfefefefefefefefef covfefefefefefefefefe covfefefefefefefefefef covfefefefefefefefefefe covfefefefefefefefefefef covfefefefefefefefefefefe covfefefefefefefefefefefef covfefefefefefefefefefefefe ``` So here are the rules: * Output 21 lines, the first of which should be 'covfefe'. * Each line must be one character longer than the previous line. * No f can be horizontally adjacent to another f. * No e can be horizontally adjacent to another e. Oh, and have fun! (I'm also interested to see any other nifty covfefe-related snippets) [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 13 bytes ``` E²¹⁺cov…fe⁺⁴ι ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM3sUDDyFBHISCntFhDKTm/TElHwbkyOSfVOSO/QEMpLVUJKmeio5CpCQLW////1y37r1ucAwA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: ``` Implicitly print joined with newlines E²¹ the implicit range 0..21 mapped to ⁺cov the concatenation of "cov" with …fe the characters "fe" repeated until their length is exactly ⁺⁴ι 4 more than the value ``` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), ~~17~~ 16 bytes ``` „fe12×禦¦…covì» ``` [Try it online!](https://tio.run/##MzBNTDJM/f//UcO8tFRDo8PTz20/tAwEHzUsS84vO7zm0O7//wE "05AB1E – Try It Online") **Explanation** ``` „fe # push the string "fe" 12× # repeat it 12 times η # get the prefixes of this string ¦¦¦ # drop the first 3 …covì # prepend the string "cov" to each » # join on newline ``` [Answer] # [Japt](https://github.com/ETHproductions/japt), ~~17~~ 16 bytes ``` 4o25_îeif)i`¬v ``` [Test it online!](http://ethproductions.github.io/japt/?v=1.4.5&code=NG8yNV/uZWlmKWlgrHY=&input=LVI=) 14 bytes of code, +2 for `-R` flag. If we can output as an array, simply remove the `-R` and subtract 2 bytes. ### Explanation ``` 4o25 Generate the range [4, 5, ..., 24]. _ Map each item in this range to eif "fe" (really weird hack, but it works and saves a byte) î ) repeated to length <item> i`¬v with "cov" inserted at the beginning. Implicit: output result of last expression, joined with newlines (-R) ``` Alternatively, you could do `7o28_îfie)h"cov`, which does the same thing, except overwriting `cov` onto the beginning of the string instead of inserting it at the beginning. [Answer] # [Python 2](https://docs.python.org/2/), 37 bytes ``` s='covfef' exec"s+=s[-2];print s;"*21 ``` [Try it online!](https://tio.run/##K6gsycjPM/r/v9hWPTm/LC01TZ0rtSI1WalY27Y4Wtco1rqgKDOvRKHYWknLyPD/fwA "Python 2 – Try It Online") Matches the text shown. --- # [Python 2](https://docs.python.org/2/), 36 bytes ``` s='covfefe' exec"print s;s+='?';"*21 ``` [Try it online!](https://tio.run/##K6gsycjPM/r/v9hWPTm/LC01LVWdK7UiNVmpoCgzr0Sh2LpY21bdXt1aScvI8P9/AA "Python 2 – Try It Online") Prints: ``` covfefe covfefe? covfefe?? covfefe??? covfefe???? covfefe????? covfefe?????? covfefe??????? covfefe???????? covfefe????????? covfefe?????????? covfefe??????????? covfefe???????????? covfefe????????????? covfefe?????????????? covfefe??????????????? covfefe???????????????? covfefe????????????????? covfefe?????????????????? covfefe??????????????????? covfefe???????????????????? ``` [Answer] ## [Pyth](https://github.com/isaacg1/pyth), 29 bytes ``` Vr4 25+"cov"+*/N2"fe"?%N2"f"k ``` Explanation: ``` Vr 4 25 Loops variable N from 4 to 24 (excludes 25) */N2"fe" Repeats string "fe" N / 2 number of times ?%N2"f"k Concatenates "f" if N % 2 is 1 (odd), or an empty string if it is even (N % 2 is 0) + Concatenates strings ``` [Try it online!](https://tio.run/##K6gsyfj/P6zIRMHIVFspOb9MSVtL389IKS1VyV4VRCtl//8PAA "Pyth – Try It Online") [Answer] # [SOGL V0.12](https://github.com/dzaima/SOGL), ~~16~~ 15 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md) ``` 4'⁷Ν{ņcoļvƧfemo ``` [Try it Here!](https://dzaima.github.io/SOGLOnline/?code=NCUyNyV1MjA3NyV1MDM5RCU3QiV1MDE0NmNvJXUwMTNDdiV1MDFBN2ZlbW8_) Explanation: ``` 4'⁷Ν push inclusive range from 4 to 24 { for each do ņcoļv output in a new line "cov" (split into 2 commands of "output 2 chars in a new line" and "output next char" for a byte save) Ƨfemo output "fe" molded into the length of the current item ``` [Answer] # [C# (Mono)](http://www.mono-project.com/), 132 bytes ``` using System.Linq;_=>{for(int i=0;i<21;)System.Console.WriteLine("cov"+string.Concat(new int[4+i++].Select((n,j)=>j%2<1?"f":"e")));} ``` [Try it online!](https://tio.run/##TY5PS8QwEMXv@RQhICRUi7t4Mm1FvCqIe/AgIjE7lSnZGWyyK7L0s9d03S77TvPe/Pv5eLVh4nEbkb7k6jcm2Fhx7spHpG8rhA8uRvks9kJmxeQSerljXMsnh6TNIf5vTrr3CZkq/uzAp0a2sh4/6mbfcq@RksT62mK1XFhz/PLAFDlA@dpjgvwStPK8U0VMfWaZ2t4lTfAj8/rbTYFF8V6uIOTrWtNlZ@qmu1hWizvVqlsFyhhjh3Gmyfxz2WrahmDsKZh0MjPGC7j1geI4OIhh/AM "C# (Mono) – Try It Online") [Answer] Totally valid answer which matches the specs/rules. # PowerShell, 25 Bytes. [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Xyk5vywtNS1VydpCT8/Ioka1Wt1eXUslvvb/fwA "PowerShell – Try It Online") ``` "covfefe";8..28|%{'?'*$_} ``` OR (same byte count) ``` 0..21|%{'covfefe'+'?'*$_} ``` As intended answer which matches the example output. # PowerShell, 44 Bytes. [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XyXZVik5vywtNU3J2kBPz8igRrVaAyiokqytoZ6qrqOepq4ZrRKvahSrWfv/PwA "PowerShell – Try It Online") ``` $c="covfef";0..20|%{($c=$c+('e','f')[$_%2])} ``` Ugly assignment at the beginning, i'm sure there's some that can be saved here. [Answer] # [Japt](https://github.com/ETHproductions/japt/), ~~20~~ 18 bytes ``` `¬vfef` 21ÆU±gJÉ÷ ``` [Test it](http://ethproductions.github.io/japt/?v=1.4.5&code=YKx2ZmVmYAoyMcZVsWdKycO3&input=) 16 bytes, if we can return an array. ``` `¬vfef` 21ÆU±gJÉ ``` [Answer] # [Python 2](https://docs.python.org/2/), ~~53~~ 52 bytes ``` f=lambda n=21:n*' 'and'\ncovf'+('ef'*12)[:-n]+f(n-1) ``` [Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRIc/WyNAqT0tdQT0xL0U9Ji85vyxNXVtDPTVNXcvQSDPaSjcvVjtNI0/XUPN/QVFmXolCmobmfwA "Python 2 – Try It Online") [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 17 bytes ``` ⁾feẋ12“cov”;;\ṫ7Y ``` [Try it online!](https://tio.run/##ASQA2/9qZWxsef//4oG@ZmXhuosxMuKAnGNvduKAnTs7XOG5qzdZ//8 "Jelly – Try It Online") [Answer] # [Husk](https://github.com/barbuz/Husk), 15 bytes ``` ↑21↓7ḣ+¨¢√¨¢"fe ``` [Try it online!](https://tio.run/##yygtzv7//1HbRCPDR22TzR/uWKx9aMWhRY86ZoEopbTU//8B "Husk – Try It Online") NB: `¨¢√¨` is the compressed strind `"cov"` [Answer] # Pyth, 33 bytes `V21+++"cov"*"fe"2*"fe"s/N2*\f%N2` Try it here: <http://pyth.herokuapp.com> [Answer] # [Retina](https://github.com/m-ender/retina), 27 bytes ``` covf12$* 1 ef . $`¶ G`.{7} ``` [Try it online!](https://tio.run/##K0otycxL/P@fKzm/LM3QSEWLy5ArNY1Lj0sl4dA2LvcEvWrz2v//AQ "Retina – Try It Online") Explanation: ``` covf12$* ``` Add `covf` plus 12 `1`s. ``` 1 ef ``` Change each `1` to `ef`. This results in the last line of the desired output, but with an extra `f`. ``` . $`¶ ``` Replace the string with a list of all of its proper prefixes. ``` G`.{7} ``` Delete the prefixes that are too short. [Answer] # [C (gcc)](https://gcc.gnu.org/), ~~77~~ ~~75~~ 74 bytes ``` f(i,j){for(i=4;i++<25;)for(printf("\ncov"),j=i;--j;)putchar("ef"[i-j&1]);} ``` [Try it online!](https://tio.run/##FccxCoUwDADQvaeQDpKgHZT/p@hJ1EGC0RSsUtRFPHvFtz12M3NKAlp6vGWLoO2PtCia@k/4fY8aDgHbB94ui6VvlZzzhPt58DJGsJPYTp3PqwHpSeuoAdDcJssEkMyTXg "C (gcc) – Try It Online") [Answer] # [Python 3](https://docs.python.org/3/), 61 bytes ``` def f(n=20): print(' '*n+('covf'+'ef'*12)[:~n]) if n:f(n-1) ``` not the shortest, but prints triangle without e/f vertical adjacency [Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNI8/WyEDTiouzoCgzr0RDXUFdK09bQz05vyxNXVs9NU1dy9BIM9qqLi9Wk4szM00hzwqoRddQ83@ahuZ/AA "Python 3 – Try It Online") [Answer] # [Perl 5](https://www.perl.org/), 45 bytes ``` $_="covfef ";eval's/((.).)$/$1$2/;print;'x 20 ``` [Try it online!](https://tio.run/##K0gtyjH9/18l3lYpOb8sLTWNS8k6tSwxR71YX0NDT1NPU0VfxVDFSN@6oCgzr8RavULByOD/fwA "Perl 5 – Try It Online") [Answer] # [Perl 5](https://www.perl.org/), 39 bytes ``` $b=covfef;say$b.=substr$b,-2,1for 1..21 ``` [Try it online!](https://tio.run/##K0gtyjH9/18lyTY5vywtNc26OLFSJUnPtrg0qbikSCVJR9dIxzAtv0jBUE/PyPD//3/5BSWZ@XnF/3V9TfUMDA0A "Perl 5 – Try It Online") [Answer] **Ruby - 53 chars** ``` s='covfef';21.times{|i|puts s +=(i.odd? ? 'f' : 'e')} ``` *Note:* This is the OP's answer, there must be better one's out there. ]