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/6500/edit). Closed 7 years ago. [Improve this question](/posts/6500/edit) The problem is very simple: write a program that accepts a single unsigned integer from the command line, and prints out that many random numbers on the standard output, in ascending order. For example: input: ``` 5 ``` output (you can use any type of whitespace): ``` 557 9424 19212 32293 39135 ``` However, you are not allowed to define any variables. **Any at all.** Score is given by code length, shortest wins, and by up-votes if equal. The random numbers can be anything generated by a reasonable pseudo-random generator with a uniform distribution: for example, integers at least 8 bits long (no cheap "0 0 0 0 0 1 1 1 1 " one bit solutions, please), or real numbers (e.g. float) between 0 and 1. In dynamically typed languages, the fist assignment counts as definition in our context, so no cheap Matlab solutions, please :) [Answer] ## J, 8 characters If we can take the number of numbers to be generated at the end of the program like the Q solution, then: ``` /:~256?~ ``` Example: ``` /:~256?~8 18 21 91 201 212 226 246 253 ``` If not, then taking input from the keyboard requires another 8 characters: ``` /:~256?~".1!:1[1 ``` [Answer] # Q, 10 ``` {asc x?1f} ``` . ``` q){asc x?1f}5 `s#0.08724017 0.1024432 0.2310108 0.2560658 0.8671096 ``` [Answer] ### Perl - 28 26 20 chars `say sort map rand.$/,1..<>` I realized the sorting isn't unnecessary, we only need random numbers in ascending order. `rand` will return a real in [0,1), so just add our iteration counter to each `rand` result. ``` say$_+rand for 1..<> ``` or ``` map{say$_+rand}1..<> ``` [Answer] ## GolfScript, 14 chars ``` ~{9.?rand}*]$` ``` Generating random numbers in GolfScript takes quite many characters, especially if you want to pick them from a reasonably large range. Sorting the list takes only one char (`$`), though, and needs no variables. Same code de-golfed and with comments added: ``` ~ # eval input string, turning it into a number { # define a code block: 9.? rand # push a random number between 0 and 99-1 onto the stack } * # execute the previous code block as many times as the input number indicates ] # collect the random numbers off the stack into an array $ # sort the array ` # un-eval the array for output ``` [Answer] ## Ruby, ~~42~~ 34 ``` puts (1..gets.to_i).map{rand}.sort ``` This could probably be made smaller, but don't blame me - I don't even know Ruby. Also, that whitespace after `puts` is significant. Silly language ;) [Answer] # Bash, 45 characters ``` eval `yes 'echo $RANDOM;'|head -n$1`|sort -n ``` Put in a file and run `sh file.sh 25` or replace `$1` by any number [Answer] # Octave / MATLAB, 23 ``` sort(rand(input(""),1)) ``` [Answer] ## C, 108 chars You wanted a C (or derived) answer, so here's one. Gets the number as the first parameter. Works successfully with numbers up to 10 or so. With larger numbers, it usually overflows the stack (due to my awful algorithm). ``` f(x,m,r){x&&f(x-(r>m),r>m?printf("%d\n",r),r:m,rand());} main(c,v)char**v;{srand(time(0));f(atoi(v[1]),0,0);} ``` [Answer] ## R, 19/43(TRUE random) characters ``` sort(runif(scan())) ``` Just for fun, selecting TRUE random numbers: ``` library(random);sort(randomNumbers(scan())) ``` [Answer] ### Scala, 44: ``` (1 to readInt)map(util.Random.nextInt)sorted ``` [Answer] ## Python, 73 characters ``` import sys,random print sorted(eval("random.random(),"*int(sys.argv[1]))) ``` Hopefully imports don't count as defining variables. [Answer] # Haskell (102 / 71 chars) As a proper program (102 chars) ``` import Random import List main=getLine>>=(\n->getStdGen>>=(print.sort.take n.randomRs(0,256*n))).read ``` Or in GHCi (71 chars) ``` :m Random List getLine>>=(`fmap`getStdGen).(sort.).(.randoms).take.read ``` [Answer] # JavaScript, 85 bytes ``` n=>{o=[];for(i=[];i.length<n;i.push(1))o.push(Math.random());return o.sort().join` `} ``` In JavaScript, [arrays are objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), not variables. [Answer] ## Java 8, 96 bytes Because Java is obviously the right tool for this [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'")! [/sarcasm] ``` n->java.util.stream.Stream.generate(Math::random).limit(n).sorted().forEach(System.out::println) ``` This is a `Consumer<Long>` or anything that can be implicitly cast to `long`. Prints random `double`s. ``` n-> // Given an input n ...Stream.generate(Math::random) // Generate an infinite stream by calling Math.random() .limit(n) // Limit the stream to n elements .sorted() // On the sorted stream .forEach(System.out::println) // Print each element on its own line ``` ]
[Question] [ Write a series of programs in the *same language* that print “Hello, world!” using n distinct source characters, where n is in [1..10] inclusive (“distinct” meaning that duplicate characters are ignored from character count). The winner is the solution with the most programs, each with distinct n. I suggest making one solution per language, which is treated like a wiki. Further rules: * *Case-sensitive* ('H' and 'h' are distinct characters) * In *case-insensitive languages*, all non-string-literal characters are assumed to be *uppercase*. * EDIT: No characters ignored by the compiler (comments) * Output must be *exactly* “Hello, world!” (without quotes) - no variations in punctuation or case, and no newline. * “Output” can mean either *value of the expression* or *output to stdout*. * Esoteric programming languages are very much allowed. * EDIT: The language must already exist (as of this question being asked). * If anyone gets all of [1..10], they are the accepted winner. Here's a polyglot example: ``` 'Hello, world' ``` It scores 11 (and thus is not part of a solution) because it includes distinct characters: ``` 'Helo, wrd! ``` [Answer] # DC: 2, 3, 4, 5, 6, 7, 8, 9 and 10 distinct characters Seeing as the value of an expression is accepted as valid, this should qualify for 2 distinct characters (newlines added for legibility): ``` 1111111111111111111111111111111+ 1111111111111111111111111111111+ 1111111111111111111111111111111+ 1111111111111111111111111111111+ 1111111111111111111111111111111+ 11111111111111111111111111111+1+ 11111111111111111111111111111+1+ 1111111111111111111111111111+11+ 1111111111111111111111111111+11+ 11111111111111111111111111+1111+ 11111111111111111111111111+1111+ 1111111111111111111111111+11111+ 11111111111111111111111+1111111+ 11111111111111111111111+1111111+ 1111111111111111111111+11111111+ 1111111111111111111111+11111111+ 1111111111111111111111+11111111+ 111111111111111111111+111111111+ 111111111111111111111+111111111+ 111111111111111111111+111111111+ 11111111111111111111+1111111111+ 11111111111111111111+1111111111+ 11111111111111111111+1111111111+ 11111111111111111111+1111111111+ 11111111111111111111+1111111111+ 11111111111111111111+1111111111+ 1111111111111111111+11111111111+ 1111111111111111111+11111111111+ 1111111111111111111+11111111111+ 11111111111111111+1111111111111+ 11111111111111111+1111111111111+ 11111111111111111+1111111111111+ 11111111111111111+1111111111111+ 11111111111111111+1111111111111+ 11111111111111111+1111111111111+ 1111111111111111+11111111111111+ 1111111111111111+11111111111111+ 1111111111111111+11111111111111+ 1111111111111111+11111111111111+ 1111111111111111+11111111111111+ 1111111111111111+1111111111111+ 1111111111111111+1111111111111+ 111111111111111111+11111111111+ 1111111111111111111+1111111111+ 1111111111111111111+1111111111+ 1111111111111111111+1111111111+ 11111111111111111111111+111111+ 11111111111111111111111+111111+ 11111111111111111111111+111111+ 11111111111111111111111+111111+ 11111111111111111111111+111111+ 1111111111111111111111111+1111+ 1111111111111111111111111+1111+ 11111111111111111111111111+111+ 111111111111111111111111111+11+ 111111111111111111111111111+11+ 111111111111111111111111111111+ 11111111111111111111111111111+ 11111111111111111111111111111+ 11111111111111111111111111111+ 11111111111111111111111111111+ 1111111111111111111111111+ 1111111111111111111111111+ 11111111111111111111111+ 1111111111111111111111+ 1111111111111111111111+ 1111111111111111111111+ 111111111111111111111+ 111111111111111111111+ 111111111111111111111+ 111111111111111111111+ 111111111111111111+ 111111111111111111+ 111111111111111111+ 1111111111111111+ 1111111111111111+ 111111111111111+ 111111111111111+ 111111111111111+ 111111111111111+ ``` The above is equal to `Hello, world!`, which can be seen by printing it with `P`. Note that it yields an error, as the first plus sign doesn't have two values on the stack to work with, but that doesn't change the value of the expression (as the error doesn't stop the execution). Replace the first plus sign with a space for the solution with 3 distinct characters. 4 distinct characters: ``` 11dd1d+++ddd++dP+1dd+d+++dP1ddd++d+++ddPP111dddP11d+d+P1d+d+d+dd+d+P+PP1dd+++PPdd++ddd++1+PP ``` The rest: ``` 2i1001000011001010110110001101100011011110010110000100000011101110110111101110010011011000110010000100001P 3i12000022021201222010112112220012020100011020212102102112221212020P 4i1020121112301230123302300200131312331302123012100201P 5i100103122130403124020421012422302411143103141P 6i2324032511514252112222553531220321252053P 7i2106632145606024426126104063251063041P ``` [Answer] ## Brainfuck, n=2, 3, 4, 5, 6, 7, 8 Case n=2: (new lines added for readability) ``` ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. +++++++++++++++++++++++++++++. +++++++.. +++. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++. +++. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++. ``` Case n=2 will be our basis. For case n=3: we add `-` to the end of the n=2 source. For case n=4: we add `->` to the end of the n=2 source. For case n=5: we add `-><` to the end of the n=2 source. For case n=6: we add `[><]` to the **beginning** of the n=2 source. For case n=7: we add `[><-]` to the beginning of the n=2 source. For case n=8: we add `[><,-]` to the beginning of the n=2 source. Note: if you allow comments to be counted, add `a` anywhere for n=9 and add `ab` anywhere for n=10. [Answer] Emacs Lisp: One expression that returns "Hello, World!" Exactly 10 distinct characters: [s, t, r, i, n, g, ), (, \*, +] ``` (string (*(+(*)( *))(+(*( *(+(*)(* ))(+(*)( *))))(*( +(*)(*)( *)(*))(*(*(+(*)(*))( +(*)(*))(+(*)(*))))) ))(+(*)( *(+(+(*) (*))(+(* )(*))))( *(+(*)(* ))(+(*)( *))(+(*)(*))(+(*)(*) )(+(*)(*)))(*(*(+(*) (*))(+(* )(*))(+(*)(*)))(+(*) (*))(+(*)(*))(+(*)(* ))))(+(* (+(*)(*))(+(*)(*)))( *(+(*)(*))(+(*)(*))( +(+(*)(* ))))(*(+ (*)(*))( +(*)(*)) (+(*)(*) )(+(*)(* ))(+(*)(*)))(*(*(+(* )(*))(+(*)(*))(+(*)( *)))(+(* )(*))(*( +(*)(*)) (+(*)(*) ))))(+(* (+(*)(*) )(+(*)(*)))(*(+(*)(* ))(+(*)(*))(+(+(*)(* ))))(*(+(*)(*))(+(*) (*))(+(*)(*))(+(*)(* ))(+(*)( *)))(*(* (+(*)(*) )(+(*)(* ))(+(*)( *)))(+(* )(*))(*( +(*)(*)) (+(*)(*)))))(+(+(*)( *)(*))(*(+(*)(*))(+( *)(*)) (+(* )(*))) (*(+(* )(*) )(+(*) (*)))( *(+( *)(*)) (+(*)( *))( +(*)(* ))(+(* )(*) )(+(*) (*)))( *(*( +(*)(* ))(+(*)(*))(+(*)(*)) )(+(*)(*))(*(+(*)(*) )(+(*)(*)))))(+(*)(* )(*(+(*)(*))(*(+(*)( *))(+(*) (*))))(* (+(*)(*) (*)(*))( *(*(+(*) (*))(+(* )(*))(+( *)(*)))) )(*)(*))(+(*(*(+(*)( *))(+(*)(*)))(*(+(*) (*))(+(*)(*))(+(*)(* )))))(+(*(*(+(*)(*)) (+(*)(*) )(+(*)(* ))))(+(* )(*)(*)) (*(+(*)(*))(+(*)(*)) (+(*)(*) ))(*(+( *)(*))(+ (*)(*)) )(*(+(*) (*))(+( *)(*))(+ (*)(*))( +(*)(*)) (+(*)(*) ))(*(*(+ (*)(*))( +(*)(*))(+(*)(*)))(+ (*)(*))(*(+(*)(*)))) )(+(+(*)(*)(*)) (*(+(*)(*))(+(*)(*)) (+(*)(*) ))(*(+(* )(*))(+( *)(*)))( *(+(*)(* ))(+(*)( *))(+(*) (*))(+(* )(*))(+(*)(*)))(*(*( +(*)(*))(+(*)(* ))(+(*)( *)))(+(* )(*))(*( +(*)(*)) (+(*)(*) ))))(+(* )(*)(*(+ (*)(*))(+(*)(*)))(*(+(*)(*))(+ (*)(*)))(*(+(*)(*))(+(*)(*))(+ (+(*)(*))))(*(+(*)(*))(+(*)(*) )(+(*)(*))(+(*)(*))(+(*)(*)))( *(*(+(*)(*))(+(*)(*))(+(*)(*)) )(+(*)(*))(*(+(*)(*))(+(*)(*)) )))(+(*(+(*)(*))(+(*)(*)))(*(+ (*)(*))(+(*)(*))(+(+(*)(*))))( *(+(*)(*))(+(*)(*))(+(*)(*))(+ (*)(*))(+(*)(*)))(*(*(+(*)(*)) (+(*)(*))(+(*)(*)))(+(*)(*))(* (+(*)(*))(+(*)(*)))))(+(+(*)(* ))(+(*)(*))(*(+(*)(*))(+(*)(*) )(+(*)(*))(+(*)(*))(+(*)(*)))( *(*(+(*)(*))(+(*)(*))(+(*)(*)) )(+(*)(*))(+(*)(*))(+(*)(*)))) (+(*)(*(*(+(*)(*))(+(*)(*)))(* (+(*)(*))(+(*)(*))(+(*)(*)))))) ``` [Answer] ## H9+ ``` H H0 H01 H012 H0123 H01234 H012345 H0123456 H01234567 H012345678 ``` [Answer] # [Actually](https://github.com/Mego/Seriously), 10 bytes ``` HIKLPTUVZ] ``` [Try it online!](https://tio.run/##S0wuKU3Myan8/9/D09snICQ0LCr2/38A "Actually – Try It Online") All prefixes of the program output `Hello, World!`: ``` H HI HIK HIKL HIKLP HIKLPT HIKLPTU HIKLPTUV HIKLPTUVZ HIKLPTUVZ] ``` [Answer] # *[99](https://github.com/TryItOnline/99)*, 3 to 10 distinct chars ``` 999 9 9 99 99999999 999 9 99 99 99999 9 999 9 99 99 99 999 999999 99 99 99 9999999 9999 999 9 99 99 99 9999999 9 999 9 999 9 999 9 99 99 99 999999 9 999999 9 99 9999 99 99999 999 999999 999 9 99 99 9999999 9999 9 999 9 99 99 99 999999 9 99 99 99 999999 999 9 99 99 99999 9999999 9 99 ``` [Try it online!](https://tio.run/##s7T8/9/S0lIBCLlAFBQogDFQBC6ogC6mYAlXz2WJohRKY1GPbJACLkPh4khSKA5BUobuSrjVuMzFFMH0KJLa//8B "99 – Try It Online") This is just standard *99*. For the rest, replace the 999 with `9a99`, `9ab99`, etc. ]
[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/209980/edit). Closed 3 years ago. [Improve this question](/posts/209980/edit) # Number Splitting ## Instructions Oh no, my numbers have stuck together! Luckily, we can split them apart with code. Your code should be a function that takes an integer input from stdin or as an argument. You must split the number into single digits, keeping the order and possible duplicates of these digits. The output should be an array and it may be returned from the function or from stdout. Other forms of output may be discussed. The array elements may be a string or number. ## Examples ``` 345 -> [3, 4, 5] 12218 -> [1, 2, 2, 1, 8] ``` ## Scoring This is code golf, so shortest code wins. [Answer] # [Japt](https://github.com/ETHproductions/japt), 1 [byte](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) Trivial challenges get trivial solutions. ``` ì ``` [Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=7A&input=MzQ1) [Answer] # [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 13 bytes ``` IntegerDigits ``` [Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773zOvJDU9tcglMz2zpPh/QFFmXomCQ3q0sYlpLBecZ2hkZGgR@/8/AA "Wolfram Language (Mathematica) – Try It Online") [Answer] # JavaScript, 12 bytes -3 bytes if we can take input as a string. ``` n=>[...n+""] ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i5aT08vT1tJKfZ/cn5ecX5Oql5OfrpGmoaxiamm5n8A) [Answer] # [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 4 bytes ``` \B , ``` [Try it online!](https://tio.run/##K0otycxL/P8/xolL5/9/QyMjQwsA "Retina 0.8.2 – Try It Online") Explanation: Simply inserts a `,` between each pair of digits. Alternatively, if a newline-delimited list is acceptable, then for 3 bytes: ``` !`. ``` [Try it online!](https://tio.run/##K0otycxL/P9fMUHv/39DIyNDCwA "Retina 0.8.2 – Try It Online") Explanation: Simply lists each digit separately. Alternatively, to produce the example output, then for 13 bytes: ``` \B , ^ [ $ ] ``` [Try it online!](https://tio.run/##K0otycxL/K@q4Z7wP8aJS0eBK44rmkuFK/b/f2MTUy5DIyNDCwA "Retina 0.8.2 – Try It Online") Link includes test cases. Alternatively, this can be done in [Retina](https://github.com/m-ender/retina/wiki/The-Language) 1 for 12 bytes: ``` [[|", "]]L`. ``` [Try it online!](https://tio.run/##K0otycxLNPz/Pzq6RklHQSk21idB7/9/YxNTLkMjI0MLAA "Retina – Try It Online") Link includes test cases. [Answer] # [Arn](https://github.com/ZippyMagician/Arn), [1 byte](https://github.com/ZippyMagician/Arn/wiki/Carn) Mmm. I have absolutely no idea how I found this... ``` \ ``` [Try it!](https://zippymagician.github.io/Arn?code=%5D&input=123) # Explained ``` _ The current input (implicit) \ Map/Fold by this: _ The current item of the input, overloaded by \ Thus, Map/Fold yields a list of the items of the input string. ``` # [Arn](https://github.com/ZippyMagician/Arn), [2 bytes](https://github.com/ZippyMagician/Arn/wiki/Carn) ``` <i ``` [Try it!](https://zippymagician.github.io/Arn?code=%3Ci&input=123) # Explained Unpacked: `:!"` ``` _ Input indicator (implicit) :! Split by " The empty string " Trailing quote mark (implicit) ``` [Answer] # APL+WIN, 4 bytes Prompts for integer: ``` ⍎¨⍕⎕ ``` [Try it online! Courtesy of Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcjzra0/4/6u07tOJR71Sg8H@gwP80LmMTU640LkMjI0MLLgA "APL (Dyalog Classic) – Try It Online") [Answer] # [Assembly (MIPS, SPIM)](https://github.com/TryItOnline/spim), 106 bytes Outputs the digits space-separated. ``` .data .text main:li $v0,12 syscall move $a0,$v0 beq $a0,10,e li $v0,11 syscall li $a0,32 syscall b main e: ``` [Try it online!](https://tio.run/##Ky7IzP3/Xy8lsSSRS68ktaKEKzcxM88qJ1NBpcxAx9CIq7iyODkxJ4crN78sVUEl0UAHKM6VlFoIZhsa6KRywdQawtWCRICyxgjdSQogY7lSrf7/NzQyMrQAAA "Assembly (MIPS, SPIM) – Try It Online") # [Assembly (MIPS, SPIM)](https://github.com/TryItOnline/spim), 160 bytes This outputs in a format looking like a list of digits. ``` .data .text main:li $a0,91 li $v0,11 syscall l:li $v0,12 syscall move $a0,$v0 beq $a0,10,e li $v0,11 syscall li $a0,44 syscall b l e:li $a0,93 li $v0,11 syscall ``` [Try it online!](https://tio.run/##bY07CoAwEAX7PYWFZZBstFBvs@oWgY0fEkRPH3@YRrthYN7zs3UxFgMFgiLwFsCRHVuxWU5aNQgXrVohgt99TyIg7etMcm5a@S5ODx0vN6NW/Nc/21WVTJcJcPosv02MaAzWBw "Assembly (MIPS, SPIM) – Try It Online") [Answer] # Javascript(ES6), 38 bytes Just to kick this off. ``` a=(w)=>{return w.toString().split("")} ``` ## Output: 345 -> ["3", "4", "5"] 12218 -> ["1", "2", "2", "1", "8"] [Answer] # Python 2, 18 bytes ``` lambda x:list(`x`) ``` # Python 3, 21 bytes ``` lambda x:list(str(x)) ``` [Answer] # Python 3: ~~28~~ 20 bytes [Try it Online - lambda function](https://tio.run/##K6gsycjPM/7/v8I2JzE3KSVRIc8qWqu4pEgjTzP2f0FRZl6JRoWGsYmppiYXjGdoZGRooan5HwA) [Try it Online - normal function def](https://tio.run/##K6gsycjPM/7/PyU1TaFCI0/TSqtCx7a4pAjItC5KLSktylOo@F9QlJlXolGhYWxiqqnJBeMZGhkZWmhq/gcA) Tried it with lambda function (20 bytes) instead of normal function definition ``` x=lambda n:[*str(n)] ``` My earlier response with normal def function - 28 bytes ``` def x(n):*x,=str(n);return x ``` Calling the function as follows: ``` print(x(345)) print(x(12218)) ``` Output: ``` ['3', '4', '5'] ['1', '2', '2', '1', '8'] ``` [Answer] # [C (gcc)](https://gcc.gnu.org/), 36 bytes Returns a string representation of the integer. ``` f(i){int*s;asprintf(&s,"%d",i);i=s;} ``` [Try it online!](https://tio.run/##PY4xC8IwEIX3/IqjUsm1EW1VEGIGBzdx6Fo7hLaRA02lEQdLf3s9QZzex/Hu8dWLa11Pk5OEA/lnErQNj57JyXlQUdxEilCTCXqcZk3ryLdwKIrT8Swtggz0bjvHuPxRYhGF4H@4W/Ly1VGDMAiA78mWlRlgvdkqyPI828GowN5ab/6LCkgLbruul2RWGmj/LXCmKcJPjK3AQBmH6uIjXiipUsASnIhajNMH "C (gcc) – Try It Online") [Answer] # [Jelly](https://github.com/DennisMitchell/jellylanguage), 1 byte Another trivial solution. ``` D ``` [Try it online!](https://tio.run/##y0rNyan8/9/l////xiamAA "Jelly – Try It Online") [Answer] # [Pyth](https://github.com/isaacg1/pyth), 3 bytes ``` jQT ``` [Try it online!](https://tio.run/##K6gsyfj/Pysw5P9/QyMjQwsA "Pyth – Try It Online") Explanation: Takes the integer input (Q) and converts it into base 10 (T) and returns the individual digits in a list. --- # [Pyth](https://github.com/isaacg1/pyth), 3 bytes ``` cz1 ``` [Try it online!](https://tio.run/##K6gsyfj/P7nK8P9/Q0MjYxMA "Pyth – Try It Online") Unlike the above one, this one takes input as a string and returns an array of the characters of the string. Still 3 bytes. :<) ]
[Question] [ # Description : Given a string of space separated binary digits or space separated booleans or an array of binary digits or array of booleans . Your job is to find the xor of each until you end up with one answer either 0 or 1. The inputs will always be valid and will only be either 0 or 1. # Example : ``` 1 0 0 1 0 --> 0 1 0 1 1 1 0 0 1 0 0 0 0 --> 1 ``` This is code golf so shortest code will win. Good luck. [Answer] # [Java (JDK 10)](http://jdk.java.net/), 12 bytes ``` s->s.sum()%2 ``` [Try it online!](https://tio.run/##rU@7asNAEOz1FdsY7oJ9xGn9ADeBFKmUzrhYy5I5@V7c7jkIo29XzsJOirg0DOxjZmd3WzzjrD2cBm2DjwxtrlVibRRxrNGql0Xxj2qSq1h795DMvcogEXyidnApAELaG10BMXIOZ68PYDMnSo7aHbc7wHgkOUoBvvyH4/fbgmXOy/GONTSwGmi2JkXJCjl5GxajvuyIa6t8YhWyHRsnGoUhmG5DeVpsYsSObt8IV39DFm13l/kUXkdck15K@Qy7@R1/1r@47@iLfvgB "Java (JDK 10) – Try It Online") If a string is really required, then **20 bytes**: ``` s->s.chars().sum()%2 ``` [Try it online!](https://tio.run/##lY27CgJBDEX7/YogCDOCg9r6ABvBwko7sYirq7POi0lGEPHb12HdThu5kJDcnJsa7zisT7dG2@AjQ51nlVgbRRzPaNVgWnxZVXIla@9@mnlXGiSCDWoHzwIgpKPRJRAj53b3@gQ2e2LLUbvL/gAYLyTbU4CdXztedQ9mn5MFVDBvaLggVV4xkpCKkhWyP2mmLbR9EJ@t8olVyAAbJyqFIZjHknKc6I1hlJVrT8o/kHGrDv2oC3gVr@YN "Java (JDK 10) – Try It Online") The "string" answer uses the fact that a space is codepoint 32, which mod 2 returns 0. [Answer] # JavaScript (ES6), 18 bytes ``` s=>eval(s.join`^`) ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/Y1i61LDFHo1gvKz8zLyEuQfN/cn5ecX5Oql5OfrpGmka0oY6CARiBGLGamlxY5Q1hCKEWjoCa/gMA "JavaScript (Node.js) – Try It Online") [Answer] # [Python 2](https://docs.python.org/2/), 17 bytes ``` lambda a:sum(a)%2 ``` [Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHRqrg0VyNRU9Xof0FRZl6JQppGtKGOARACyVhNLhRBQzCESkJgrOZ/AA "Python 2 – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 2 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` OÉ ``` [Try it online.](https://tio.run/##MzBNTDJM/f/f/3Dn///RhjoGOoZgaABmGUBgLAA) **Explanation:** * `O`: Take the sum of the input-array * `É`: Evaluates `sum % 2 == 1`, returning `1` if the sum is odd, `0` otherwise --- **3 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)**: A leading `Ç` can be added if the space-delimited string input was still mandatory, instead of a boolean-array. [Try it online.](https://tio.run/##MzBNTDJM/f//cLv/4c7//w0VDBQMwdAAzDKAQAA) * `Ç`: Push the ASCII values of all characters, and implicitly convert it to a list. `0 1` would become `[48, 32, 49]` in that case. The `O` (sum) and `É` (is odd?) will still act the same. [Answer] # [JavaScript (Node.js)](https://nodejs.org), 23 bytes ``` a=>a.reduce((c,d)=>c^d) ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i5Rryg1pTQ5VUMjWSdF09YuOS5F839yfl5xfk6qXk5@ukaaRrShjgEQAslYTU0uLHKGYAhVA4FAlf8B "JavaScript (Node.js) – Try It Online") [Answer] # [SNOBOL4 (CSNOBOL4)](http://www.snobol4.org/csnobol4/), 44 bytes ``` A X =X + INPUT :S(A) OUTPUT =REMDR(X,2) END ``` [Try it online!](https://tio.run/##K87LT8rPMfn/35EzQsE2QkFbwdMvIDSE0ypYw1GTi9M/NATIU7ANcvV1CdKI0DHS5HL1c/n/35DLAAiBJAA "SNOBOL4 (CSNOBOL4) – Try It Online") [Answer] # [Perl 5](https://www.perl.org/) `-p040`, 10 bytes Assumes the input list can't be empty ``` $\^=0+$_}{ ``` [Try it online!](https://tio.run/##K0gtyjH9/18lJs7WQFslvrb6/39DBUMFAyA2/JdfUJKZn1f8X7fAwMQAAA "Perl 5 – Try It Online") [Answer] # [MATL](https://github.com/lmendo/MATL), ~~3~~ 2 bytes ``` so ``` Input can be a numeric vector of the form `[1 0 0 1 0]`, or a string such as `'10010'` (thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe) for noticing!). [**Try it online!**](https://tio.run/##y00syfn/vzj///9oQwUDIASSsQA "MATL – Try It Online") ### Explanation The code is `so` simple that it hardly needs an explanation, but here it goes. ``` s % Implicit input: numeric vector (or string). Sum of the numbers. (For string % input, the ASCII codes are summed. Character '1' is odd, '0' is even, and % space is even too, so the parity is the same as with numeric vector input) o % Parity. Implicit display ``` [Answer] # Java 10, 41 bytes ``` b->{var r=1<0;for(var c:b)r^=c;return r;} ``` The variable r is initially set to false, since we are `XOR`ing `b[0]` with it. Try it online [here](https://tio.run/##pY7BbsIwDIbP6VP42Eij2q503RugSeMyaRqSG1IUCAly3G5TlWcvCSDBAU67@Pdv2d/vLQ44265306FvrVGgLIYACzQOxkIYx5o6VBo@3z/yQLTeW40Ofj2Vl/7rOztZFyIW4oIJjJxk8GYN@wQrl0zGbdIq0ibIEyoj0yE0MLWzt3FAAmpeXp/rLrGzU/NW0qpRNWnuyQHVcRIi5YjlX2C9r3zP1SFx2boykar8lNM/cH1sZOr1E3Row1VuZlHKf/DO5rY@DLor5/RYxOkI). [Answer] # [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 8 bytes ``` L~,€Os2% ``` [Try it online!](https://tio.run/##S0xJKSj4/9@nTudR0xr/YiPV////KxkqGCgYgqEBmGUAgUr/8gtKMvPziv/r6mbmFuRkJmeWAAA "Add++ – Try It Online") [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), ~~5~~ ~~3~~ 2 bytes ``` ^/ ``` [Try it online!](https://tio.run/##y0rNyan8/z9O///h9kdNa/7/jzbUUTDQUTCEIQMY1wCOYnUUolFkYgE "Jelly – Try It Online") -2 bytes thanks to user202729! [Answer] # [Befunge-98 (FBBI)](https://github.com/catseye/FBBI), 8 bytes ``` #.~+2%#@ ``` [Try it online!](https://tio.run/##S0pNK81LT9W1tPj/X1mvTttIVdnh/39DBQMgBJIA "Befunge-98 (FBBI) – Try It Online") [Answer] # [Japt](https://github.com/ETHproductions/japt), 2 bytes ``` r^ ``` [Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=cl4=&input=WzEsMCwwLDEsMF0=) Does exactly what it says on the tin, `r`educe the array by XORing. [Answer] # [Cubix](https://github.com/ETHproductions/cubix), 11 bytes ``` i?+<^<@Oa1< ``` [Try it online!](https://tio.run/##Sy5Nyqz4/z/TXtsmzsbBP9HQ5v9/QwUDBUMwNACzDCAQAA "Cubix – Try It Online") It's been a while, so it feels good to write a Cubix answer! [Answer] # [Whispers v2](https://github.com/cairdcoinheringaahing/Whispers), 38 bytes ``` > Input > 2 >> ∑1 >> 3%2 >> Output 4 ``` [Try it online!](https://tio.run/##K8/ILC5ILSo2@v/fTsEzr6C0hMtOwYjLzk7hUcdEQxBtrArm@peWACUVTP7/jzbUUTDQUTCEIQMY1wCOYgE "Whispers v2 – Try It Online") I feel like 3 answers is too many, but I wanted to get Whispers out again. I'm still working on an XOR approach [Answer] # (Traditional) APL, 3 or 4 bytes [TIO](https://tio.run/##SyzI0U2pTMzJT///qKM9Ir/o/6POBfqP@qaCuP8VwAAoymWoYACEQJILVcwQDKFyEAgA), courtesy Adám ``` ≠/⍎⎕ ``` Analysis: `⎕` - Accept input. `⍎` - "unquote" it (if it's a quoted string, this will convert it to a numeric vector. If it's already a numeric vector, this is effectively a null op) `/` - reduction - apply the operator to the left to each successive item in the vector to the right `≠` - "not equal" - when applied strictly to boolean arguments, this is functionally identical to XOR (which is not implemented as a separate operator in APL) If it may be assumed that the input will be a numeric vector instead of a quoted string, then the 'unquote' can be removed, saving one byte: ``` ≠/⎕ ``` [Answer] # [Ruby](https://www.ruby-lang.org/), 42 bytes ``` ->s{s.split(' ').reduce(0){|a,b|a^b.to_i}} ``` [Try it online!](https://tio.run/##KypNqvyfZvtf1664ulivuCAns0RDXUFdU68oNaU0OVXDQLO6JlEnqSYxLkmvJD8@s7b2f0FpSbFCWrS6oYIBEAJJ9VguZDFDMITKQaB67H8A "Ruby – Try It Online") [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 2 [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") Tacit prefix function. ``` ≠/ ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HnAv3/aY/aJjzq7XvUN9XT/1FX86H1xo/aJgJ5wUHOQDLEwzP4f5qCoYIBEAJJLgjbEAyhYhAIAA "APL (Dyalog Unicode) – Try It Online") `/` is reduction and `≠` is XOR because XOR only gives `1` if its arguments are unequal. [Answer] # [Julia 0.6](http://julialang.org/), 12 bytes ``` b->⊻(b...) ``` [Try it online!](https://tio.run/##yyrNyUw0@59m@z9J1@5R126NJD09Pc3/uYkFGgVFmXklOXmPOmak6ShoRBvoGOoYAKFhrI5CtKGCgYIhGBqAWQYQGKuuqanwHwA "Julia 0.6 – Try It Online") `⊻` is the xor symbol, and `b...` distributes an array as individual elements before sending it to the xor function (since xor needs multiple arguments passed separately, not a single array argument). A bit more interestingly, a version that accepts space separated (/comma-separated/unseparated) boolean values as a string, and returns the xor result : ### Julia 0.6, 22 bytes ``` b->sum(Int.([b...]))%2 ``` [Try it online!](https://tio.run/##yyrNyUw0@59m@z9J1664NFfDM69ETyM6SU9PL1ZTU9Xof25igUZBUWZeSU7eo44ZaToKGkoGOoY6BkBoqKSgo6BkqGCgYAiGBmCWAQQqwaSUNDUV/gMA "Julia 0.6 – Try It Online") [Answer] # [C (gcc)](https://gcc.gnu.org/), ~~41~~ ~~39~~ 38 bytes Saved a few bytes with inspiration from ceilingcat. Saved another byte thanks to Jonathan Frech ``` r;f(char*s){for(r=0;*s;)r^=*s++;r&=1;} ``` [Try it online!](https://tio.run/##S9ZNT07@/7/IOk0jOSOxSKtYszotv0ijyNbAWqvYWrMozlarWFvbukjN1tC69n9uYmaehiZXNZeCQkFRZl5JmoaSakpMnpIOkGGoYACEhmBsqKSpaY1LkSEYwhSDIVh57X8A "C (gcc) – Try It Online") ]
[Question] [ **This question already has answers here**: [Code close to the challenge: Sum of integers](/questions/53604/code-close-to-the-challenge-sum-of-integers) (34 answers) Closed 8 years ago. So, ~~blatantly plagiarizing from~~ inspired by [this challenge](https://codegolf.stackexchange.com/questions/53604/code-close-to-the-challenge-sum-of-integers) and its sequel, I thought I'd add another. The text to match: > > What do you get when you multiply six by nine > > > The result your function/program/etc. should print or return: > > 42 > > > An online calculator for Levenshtein distance can be found here: <http://planetcalc.com/1721/> **Comments are disallowed.** [Answer] # GolfScript, 2 ``` What 42 you get when you multiply six by nine ``` All words except `do` are undefined tokens, so they do nothing. Try it online in [Web GolfScript](http://golfscript.apphb.com/?c=V2hhdCA0MiB5b3UgZ2V0IHdoZW4geW91IG11bHRpcGx5IHNpeCBieSBuaW5l). [Answer] # TI-BASIC, 3 Replaces the first character with length(, which is a single TI-BASIC token. ``` length("t do you get when you multiply six by nine ``` [Answer] # Ruby, 10 ``` p"What do you get when you multiply six by nine".sum/99 ``` In the spirit of the challenge. Following the letter I think the best you can do is ``` p 42||"What do you get when you multiply six by nine" ``` but that program would still work if you changed the string. [Answer] # Pyth, 4 ``` 42 "What do you get when you multiply six by nine ``` That's not a comment, it's a string that doesn't get printed. [Answer] # CJam, 3 ``` "hat do you get when you multiply six by ni", ``` `,` pushes the string's length. Try it online in the [CJam interpreter](http://cjam.aditsu.net/#code=%22hat%20do%20you%20get%20when%20you%20multiply%20six%20by%20ni%22%2C). [Answer] ## CMD, 9 ``` echo 42||What do you get when you multiply six by nine ``` Code after `||` inline will only run if the previous command generates an error. ]
[Question] [ I'm solving problem: in file "a.in" given the number N - length of the number consists of ones. Need to gets square of it, and put this in file "a.out". This is my shortest solution(150 bytes): ``` char s[1<<27];j;main(i,n){for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i;j+=i<n/2?i:n-i,s[i-1]=48+j%10,j/=10);fprintf(fopen("a.out","w"),"%s\n",s);} ``` This is formated copy: ``` char s[1<<27];j; main(i,n){ for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i; j+=i < n/2 ? i: n-i, s[i - 1] = 48 + j % 10, j /= 10 ); fprintf(fopen("a.out","w"),"%s\n",s); } ``` The best solution of this problem has size 131 bytes, how? [Answer] without changing your logic, you can save 9 characters by using `fputs` (instead of `fprintf`). ``` fputs(s,fopen("a.out","w")); ``` you can also save one character by not doubling `n` at first step, thus removing divide by two: ``` ...,i=n*2;--i; j+=i<n?i:2*n-i ``` [Answer] You can save another character, by doing `j/=10` after `for` - `for(...)j/=10;` My best so far, 145 characters: ``` char s[1<<27];j; main(i,n){ for(fscanf(fopen("a.in","r"),"%d",&n),s[i=n*2-1]=10;i; j+=i<n?i:n*2-i, s[--i]=48+j%10 )j/=10; fputs(s,fopen("a.out","w")); } ``` [Answer] ## C, 104 chars (Assuming ugoren's comment is correct) ``` main(n,k){fscanf(fopen("a.in","r"),"%d",&n);for(k=1;--n;k=k*10+1);fprintf(fopen("a.out","w"),"%d",k*k);} ``` Note that I needed to compile it with `-m32` on OSX to keep it from crashing. Probably something to do with the implicit prototypes brought about by not including `stdio.h`. [Answer] ## J, 17 characters Invalid answer and not really of any use to the OP, but I was bored and this occupied a few minutes. ``` *:10#.1$~".1!:1[1 ``` `1!:1[1` take input from the keyboard, `1$~` creates a list of 1s of the length specified by the input, `10#.` converts to a base 10 number, `*:` squares it. [Answer] ## GolfScript 7 Another answer in an illegal language, for the same reason as [the one invoked by Gareth](https://codegolf.stackexchange.com/a/6575/3527). ``` ~1`*~.* ``` Explanation: * takes a number as command line parameter * `~` evaluates the number * `1`` pushes the `'1'` string on the stack * `*` multiplies the character `'1'` by the number specified as input (results in a string) * `~` evaluates the string of `1`s, thus storing the equivalent numeric value on the stack * `.*` squares the existing value In order to get the expected output, the program should be called like this: ``` more a.in | ruby golfscript.rb program.gs > a.out # :-) ``` [Answer] Just for fun a 'dc' solution. It read/writes from stdin/stdout, because of its limitations ``` $ dc -e '?0sn[lnA*1+sn1-d0<x]dsxxlnd*p' <<< 3 12321 ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes (feedback welcome!) ``` 1xV² ``` [Try it online!](https://tio.run/##y0rNyan8/9@wIuzQpv9A2gAA "Jelly – Try It Online") Repeat '1' a number of times equal to the input (`x`), concatenate and e`V`aluate the result, and square it. **Old solution:** ``` RŒBV ``` [Try it online!](https://tio.run/##y0rNyan8/z/o6CSnsP///xsDAA "Jelly – Try It Online") As per @ugoren's explanation. Make a range from 1 to N, then bounce it (mirror except the last element) with `ŒB` and use `V` to concatenate the digits. [Answer] # [Wren](https://github.com/munificent/wren), 55 bytes Just do an invalid answer in case file manipulation doesn't work. ``` Fn.new{|x|Num.fromString("1"*Num.fromString(x)).pow(2)} ``` [Try it online!](https://tio.run/##Ky9KzftfllikkFaal6xgq/DfLU8vL7W8uqaixq80Vy@tKD83uKQoMy9dQ8lQSQtNqEJTU68gv1zDSLP2f3BlcUlqrl55UWZJqgbIML3kxJwcDSVTJU3N/wA "Wren – Try It Online") ## Explanation Takes input as string: ``` Fn.new{|x| } // New anonymous function Num.fromString(x) // Convert input into a number Num.fromString("1"* ) // Evaluate 1 with that number times .pow(2) // Square the resulting value ``` [Answer] ## C#, 172 chars ``` namespace System{class P{static void Main(){var b=Numerics.BigInteger.Parse(new String('1',int.Parse(IO.File.ReadAllText("a.in"))));IO.File.WriteAllText("a.out",b*b+"");}}} ``` Best I could do with a language with big integers. Unless you're willing to add Python to the language list... [Answer] **Java, 198 chars** Saw you mention Java, thought I'd give it a try. This is the best I can get using the standard runtime: ``` import java.io.*;enum F{F;System s;{try{s.setOut(new PrintStream("a.out"));s.out.print((int)Math.pow(1/(9/Math.pow(10,new java.util.Scanner(new File("a.in")).nextInt())),2));}catch(Exception e){}}} ``` [Answer] ### bash: 69 chars: ``` w=$(for i in $(seq 1 `<a.in`) do echo -n 1 done) echo $((w**2))>a.out ``` a.out - really? :) The only problem: invalid language. [Answer] # K, 13 Another invalid answer but what the hell. ``` {a*a:.:x#"1"} ``` [Answer] # [Keg](https://github.com/JonoCode9374/Keg), `-hr`, 5 bytes ``` 1⅍*ℤ² ``` [Try it online!](https://tio.run/##y05N///f8FFrr9ajliWHNv3/b/JfN6MIAA "Keg – Try It Online") Another illegal answer, but hey, as far as I know, there ain't any CGCC jail y'all can throw me into. [Answer] # [Japt](https://github.com/ETHproductions/japt), 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) Outputs a digit array. ``` ì1 ì² ``` [Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=7DEg7LI&input=OA) [Answer] # C, 130 chars ``` char s[1<<27];main(i,n,j){for(read(open("a.in",0),s),n=atoi(s);j=j/10+n-abs(n-i);s[n*2-++i]=48+j%10);fputs(s,fopen("a.out","w"));} ``` ]
[Question] [ # Background We define the prime-counting function, \$\pi(x)\$, as the number of prime numbers less than or equal to \$x\$. You can read about it [here](https://en.m.wikipedia.org/wiki/Prime-counting_function "Prime-counting function on Wikipedia"). For example, \$\pi(2) = 1\$ and \$\pi(6) = 3\$. It can be shown, using dark magic, that \$ \lim\_{x \to \infty} \frac{\pi(x)}{x/\log x} = 1 \$ which means we can approximate \$ \pi(x) \$ by \$ x/\log x\$. # Your task Your purpose is to write a function/program that takes `x` as input and outputs the approximation of \$\pi(x)\$ as given by the ratio of the input and the logarithm of the input, with **exactly** \$\pi(x)\$ decimal places. Either rounding works fine. # Test cases ``` f(4) = 2.89 f(10) = 4.3429 f(19.3) = 6.52003877 f(60) = 14.6543602005583370 f(173) = 33.570776430488395580723956088340374417691 f(499) = 80.3205598921264941447922062868184315657020413225943243128931714242910058741601601524983152243502 f(1024) = 147.73197218702985291365628733459375487248854570526575965547001926974558404415335218027792618429504967649254587490842053177273361276604002741459580500208428403451262667619517 ``` # Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest solution wins... With a twist! If the code you wrote gives the right answer for results with up to `p` decimal places and your code has `b` bytes, then your score is \$(e^{-p/64} + \frac13)b \$ which essentially means you get a better score if the precision is really high, as the factor multiplying by `b` [decays rapidly as the precision increases](https://www.wolframalpha.com/input/?i=Plot+exp%28-p%2F64%29+%2B+1%2F3+from+1+to+512 "Plot of the decaying function on WA") until flattening at \$\frac13\$. If you can't tell for sure the precision up to which your code works, you can take `p` to be the number of decimal places of the last test case your code can handle exactly. For this challenge, the minimum score is `1/3`, which would be attainable by a 1-byte long submission with arbitrary precision. # Admissible solution To wrap up, your code is a valid solution if and only if it computes the approximation of \$\pi(x)\$ as given by the formula and, when it gives the output, the output has exactly \$\pi(x)\$ decimal places. The `p` for the scoring will be how many decimal places you can get right. [Notice the distinction](https://tio.run/##K6gsycjPM/7/v6AoM69EQ6naykDP0MDAIK1WSS8tvyg3sUTDSEvLQM9UU/P/fwA). The code linked outputs square root of 2 with 1000 decimal places BUT python only gets some of the decimal places right. --- Standard loopholes are forbidden [Answer] # [Python 3](https://docs.python.org/3/), 61 bytes \$\approx\$ 77.6375 score ``` import math def f(x):p=x/math.log(x);print(f"{p:.{int(p)}f}") ``` [Try it online!](https://tio.run/##K6gsycjPM/7/PzO3IL@oRCE3sSSDKyU1TSFNo0LTqsC2Qh8kopeTnw7kWxcUZeaVaKQpVRdY6VWDmAWatWm1Spr/0/KLFCoUMvMUNEx0DA10DC31jHXMgLS5sY6JpSVQyMhE0wpk5H8A "Python 3 – Try It Online") Correct up to 4 decimals for \$\pi(10)\$. **Original post solution:** # [Python 3](https://docs.python.org/3/), 41 bytes \$\approx\$ 54.66 score ``` lambda x:int(x/__import__('math').log(x)) ``` [Try it online!](https://tio.run/##HYzLCoUgFAD3fcXZdQ5IL@VeDPoWMcIS8oG4sK@3x2pgYCZe@QieVwMLYD21WzcNZbY@Y@mVsi6GlJXC1ul8tNSdYcdCVKlpTEhQwHpAwcaBjbLj7Pfwz5mQ8lGToDmmd2W@5gY "Python 3 – Try It Online") Saved 20 bytes thanks to [Expired Data](https://codegolf.stackexchange.com/users/85908/expired-data)!!! Taking a leaf out of [Expired Data](https://codegolf.stackexchange.com/users/85908/expired-data)'s book and going for zero precision so \$p=0\$. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), ~~17~~ 14 bytes - Score = ~~22.6...~~ 18.6... *-3 bytes/4 score thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)* ``` žr.n÷'.0IÅPg×J ``` [Try it online!](https://tio.run/##yy9OTMpM/f//6L4ivbzD29X1DDwPtwakH57u9f@/oaWeMQA "05AB1E – Try It Online") As far as I'm aware 05ab1e doesn't have arbitrary length decimal precision. You can probably come up with an answer which calculates pi(x) decimal points of x/log(x) in less than 68 bytes and then concats them but frankly I'm not interested in this question any more. --- # Old answer before the question was revised # [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes = 8 score ``` žr.n/ò ``` [Try it online!](https://tio.run/##yy9OTMpM/f//6L4ivTz9w5v@/zcBAA "05AB1E – Try It Online") Does x/ln(x) and then rounds to the nearest integer, hence p = 0 [Answer] # [Bash](https://www.gnu.org/software/bash/) + [bc](https://www.gnu.org/software/bc/manual/html_mono/bc.html), 89 bytes, arbitrary precision, final score \${89\over3} \approx 29.67\$ ``` f(){ a=`primes 1 $((${1%.*}+1))|wc -l` echo "scale=$a+20;a=$1/l($1);scale=$a;a/1"|bc -l } ``` [Try it online!](https://tio.run/##NYvfCoMgHIXvfQrXHOii7NdiI6R3SUVJsD/MwS6qV5@bwW7O@fgOR8kwxPOJKzdxldhStiLZ9cvTjSZgwIRSssKlvO45MLa9NS58j4weZpwFLb3piMzrSsiOAPeUABN/LSSHbFPpgfZocYMshipFW95@dT/4kbBp22OsGxQ/8/Jy8xRi4b8 "Bash Try It Online") `${1%.*}` strips off the fraction `$((` ... `+1)))` adds one, as primes doesn't output the final number if prime. `primes 1`... outputs the list of primes `|wc -l` counts them At this point, a contains \$\pi(x)\$. The `echo` puts together a [bc](https://www.gnu.org/software/bc/manual/html_mono/bc.html) program, which is then piped to bc. * Set the scale to 20 more than needed (to get the accuracy) * do the approximation * set the scale to the exact number of digits * do a division by 1 so the scale is applied [Answer] # [bc](https://www.gnu.org/software/bc/manual/html_mono/bc.html), 61,51,46,45 bytes +2 for -l, (almost) arbitrary precision, final score \$\approx{47\over3} \approx 15.6666744835...\$ ``` define f(x){scale=999 return(scale=x/l(x))/1} ``` [Try it online!](https://tio.run/##S0r@/z8lNS0zL1UhTaNCs7o4OTEn1dbS0pKrKLWktChPAyJQoZ8DlNXUN6yFqS4oyswriQfpUahW4ALzFJTSNJR0FCp0FJQ0FWwVlKBGgA3mqv0P02GiyQVjGhogsS31jBE8M2QZcyQJE0tLZP1GQNP@5ReUZObnFf/XzQEA "bc Try It Online") Unlike the test cases, I don't give too many digits. I give the number of digits based on the approximation, not the counted value. Precision degrades with this solution when the result reaches 1000, at f(9119). At that point, one must add another 9 on the first line. A general solution would be possible, but longer. I guess this makes the score for this version 15.6666744835... It turns out, with initial scale=99 the score is 25.127..., and with initial scale=9999 the score is 16 + 6.75...E-67. I could write scale=9^9, get 387420489 digits of precision (probably a few less accurate), but it would take too long to run. TIO doesn't even let 9^4 get passed the second test case. This would get a score of 15.6666666666..., but still slightly more the 15⅔. Edit: Saved 10 bytes by eliminating scale=0 and rounding on scale=a Edit: saved 5 bytes by eliminating a temporary Edit: saved 1 byte by eliminating whitespace [Answer] # Mathematica, \$\approx\$ 7.67 score ## ~~25~~ 23 bytes, arbitrary precision, final score \$ \frac{23}{3}\$ ``` N[#/Log@#,PrimePi@#+1]& ``` *-2 bytes*, courtesy of @ExpiredData Here is a benchmarking solution. [Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73y9aWd8nP91BWSegKDM3NSDTQVnbMFbtf1q0SayCvr5CSH5wSVFmXjqIDVSRV8KVFm1ogFvKUs8Yp6QZHn3muLWZWFqiyKG4xAiHM/8DAA "Try it online!"). ]
[Question] [ **This question already has answers here**: [Produce the word 'codegolf' without using any of its characters in code [closed]](/questions/42350/produce-the-word-codegolf-without-using-any-of-its-characters-in-code) (28 answers) Closed 8 years ago. # Goal Your goal is to write "Code Golf" without using any letters [A-Z, a-z], even in your source code. It can't use of the following special characters either (!, \_, <, (, ), ., {, }, ', and >). # Bonus / Scoring * If the code backwards also writes "Code Golf", you get -10. Good luck! Standard loopholes disallowed. Mine also isn't a duplicate, because it also has character restrictions. [Answer] # HTML, 46 bytes ``` &#67;&#111;&#100;&#101; &#71;&#111;&#108;&#102; ``` This prints / outputs: Code Golf [Answer] # Whitespace, 146 characters I have included `S`pace, `T`ab, and `L`ine feed indicators. ``` S S S T S S S S T T L T L S S S S S T T S T T T T L T L S S S S S S S T T S S T S S L T L S S S S S S S T T S S T S T L T L S S S S S S S S T S S S S S L T L S S S S S S S T S S S T T T L T L S S S S S T T S T T T T L T L S S S S S T T S T T S S L T L S S S S S T T S S T T S L T L S S L L L ``` [Try it online](https://ideone.com/MZQAlN) **Explanation:** * `S S` pushes a number to the stack * `S T S S S S T T L` is the number 67 in binary ending with a line * `T L S S` outputs the top of the stack * This process repeats for each letter * Three linefeeds at the end terminates the program Note that this does not end with a linefeed, so the command prompt will appear directly after the output. There is also some easy golfing by manipulating the stack and/or creating the numbers more efficiently, but it's past my bedtime... **Edit:** I am unable to sleep and have been inspired by vihan1086's HTML answer. I don't see a requirement that the backwards-forwards running be in one language, so here is an **WHITESPACE + LMTH** answer that runs forwards and backwards: ``` ;201#&;801#&;111#&;17#&;23#&;101#&;001#&;111#&;76#& ``` This scores 146 + 50 - 10 = 186 [Answer] # CJam, 25 ``` "¡ÍÂÃ~¥ÍÊÄ"94"`[]":^"-"+~ ``` [Try it online](http://cjam.aditsu.net/#code=%22%C2%A1%C3%8D%C3%82%C3%83~%C2%A5%C3%8D%C3%8A%C3%84%2294%22%60%5B%5D%22%3A%5E%22-%22%2B~) **Explanation:** "¡ÍÂÃ~¥ÍÊÄ" is "Code Golf" with each character (code point) incremented by 94. ``` "¡ÍÂÃ~¥ÍÊÄ"94 push that string and 94 "`[]":^ xor the characters '`', '[' and ']', obtaining 'f' "-"+ concatenate with "-", resulting in "f-" ~ evaluate "f-", which subtracts 94 from each character ``` [Answer] # GolfScript, 27 bytes ``` 0000000: 5b 31 32 33 20 31 32 36 20 31 32 35 5d 2b 7e [123 126 125]+~ 000000f: 22 bc 90 9b 9a df b8 90 93 99 22 25 "........."% ``` The above is a reversible xxd dump. The only ASCII characters the code uses are `[123 65]+~"%`. ### Proof of work ``` $ LANG=en_US $ xxd -ps -r > codegolf.gs <<< 5b31323320313236203132355d2b7e22bc909b9adfb89093992225 $ wc -c codegolf.gs 27 codegolf.gs $ golfscript codegolf.gs Code Golf ``` ### How it works * Lacking input, GolfScript initially has an empty string on the stack. * The array `[123 126 125]` contains the character codes of `{`, `~` and `}`. * `+` concatenates. Since strings take priority over arrays, this pushes `"{~}"`. * `~` evaluates that string, pushing the block `{~}`. * The string of non-ASCII characters contains the logical NOTs of the character code of the string **Code Golf**. * `%` maps the pushed block over the string. `~` is logical NOT, which is involutive, so this pushes the character codes of **Code Golf**. * Finally, GolfScript prints the string on the stack. ]
[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/187528/edit). Closed 4 years ago. [Improve this question](/posts/187528/edit) ## Input A single integer in your language's preferred format, e.g `int` or an array of digits are all acceptable. ## Output A truthy or falsely value, depending on whether the given number is palindromic (same forwards and backwards) ## Rules * Numbers will always be positive, at least two digits long. * This is [fastest-algorithm](/questions/tagged/fastest-algorithm "show questions tagged 'fastest-algorithm'"), so lowest O(n) time complexity wins. # Test cases * 123454321 - true * 296296 - false * 296692 - true * 5499456 - false * 0 - false/error/any value [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), *O*(1) `⊃∘'111111111110`… …`10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'` Anonymous tacit prefix function. [Try it online!](https://tio.run/##7NqxTTNrFEXRcoiQPCVZQiKxBCkxCaIC6nMjJgMnRMafuZu1IqJ3NfO0zzj498@H@4eX/eHp8XQ6vr8e3z7utm@7L7/759l/@Xp/7RxxxJGf/jqvewHXXHPtJte8VNdcE7qX6pprQvdSXXNN6P4Xuuaa0F1zzTWhu@aaa0J3zTXXhO6aa64t@Xcybrjhxn9aGDfccEPxbrjhhuLdcMMNT@SGG254IjfccMNbc8MNN7w1N9xQvLfmhhuKd8MNN250w2tzww0fYDfccEPxbrjhhuLdcMMNxbvhhhuKd8MNNxTvhhtuKN4NN9zwRG644YYncsONxA2vzQ03fIDdcMMNxbvhhhuKd8MNNxTvhhtuKN4NN9xQvBtuuKF4N9xwwxO54YYbnsgNNxI3vDY33PABdsMNNxTvhhtuKN4NN9xQvBtuuKF4N9xwQ/FuuOGG4t1www1P5IYbbngiN9xI3PDa3HDDB9gNN9xQvBtuuKF4N9xwQ/FuuOGG4t1www3Fu@GGG4p3ww03PJEbbrjhidxwI3HDa3PDDR9gN9xwQ/FuuOGG4t1www3Fu@GGG4p3ww03FO@GG24o3g033PBEbrjhhidyw43EDa/NDTd8gN1www3Fu@GGG4p3ww03FO@GG24o3g033FC8G264oXg33HDDE7nhhhueyA03Eje8Njfc8AF2ww03FO@GG24o3g033FC8G264oXg33HBD8W644Ybi3XDDDU/khhtueCI33Ejc8NrccMMH2A033FC8G264oXg33HBD8W644Ybi3XDDDcW74YYbinfDDTc8kRtuuOGJ3HBj8I1tbfNAlS0BbAlgSwBbAmBLAFsC2BLAlgD8nS2xXIAtAWwJYEsAbAlgSwBbAtgSAFsCtLbEcgG2BLAlgC0BsCWALQFsCWBLAGwJ0NoSywXYEsCWALYEwJYAtgSwJYAtAbAlQGtLLBdgSwBbAtgSAFsC2BLAlgC2BMCWAK0tsVyALQFsCWBLAGwJYEsAWwLYEgBbArS2xHIBtgSwJYAtAbAlgC0BbAlgSwBsCdDaEssF2BLAlgC2BMCWALYEsCWALQGwJUBrSywXYEsAWwLYEgBbAtgSwJYAtgTAlgCtLbFcgC0BbAlgSwBsCWBLAFsC2BIAWwIs3BKzAviJAtgSwJYA2BLAlgC2BLAlALYEaG2J5QJsCWBLAFsCYEsAWwLYEsCWANgSoLUllguwJYAtAWwJgC0BbAlgSwBbAmBLgNaWWC7AlgC2BLAlALYEsCWALQFsCYAtAVpbYrkAWwLYEsCWANgSwJYAtgSwJQC2BGhtieUCbAlgSwBbAmBLAFsC2BLAlgDYEqC1JZYLsCWALQFsCYAtAWwJYEsAWwJgS4DWllguwJYAtgSwJQC2BLAlgC0BbAmALQFaW2K5AFsC2BLAlgDYEsCWALYEsCUAtgRobYnlAmwJYEsAWwJgSwBbAtgSwJYA2BJg4ZaYFcBPFMCWALYEwJYAtgSwJYAtAbAlQGtLLBdgSwBbAtgSAFsC2BLAlgC2BMCWAK0tsVyALQFsCWBLAGwJYEsAWwLYEgBbArS2xHIBtgSwJYAtAbAlgC0BbAlgSwBsCdDaEssF2BLAlgC2BMCWALYEsCWALQGwJUBrSywXYEsAWwLYEgBbAtgSwJYAtgTAlgCtLbFcgC0BbAlgSwBsCWBLAFsC2BIAWwK0tsRyAbYEsCWALQGwJYAtAWwJYEsAbAnQ2hLLBdgSwJYAtgTAlgC2BLAlgC0BsCVAa0ssF2BLAFsC2BIAWwLYEsCWALYEwJYAC7fErAB@ogC2BLAlALYEsCWALQFsCYAtAVpbYrkAWwLYEsCWANgSwJYAtgSwJQC2BGhtieUCbAlgSwBbAmBLAFsC2BLAlgDYEqC1JZYLsCWALQFsCYAtAWwJYEsAWwJgS4DWllguwJYAtgSwJQC2BLAlgC0BbAmALQFaW2K5AFsC2BLAlgDYEsCWALYEsCUAtgRobYnlAmwJYEsAWwJgSwBbAtgSwJYA2BKgtSWWC7AlgC0BbAmALQFsCWBLAFsCYEuA1pZYLsCWALYEsCUAtgSwJYAtAWwJgC0BWltiuQBbAtgSwJYA2BLAlgC2BLAlALYEWLglZgXwEwWwJYAtAbAlgC0BbAlgSwBsCdDaEssF2BLAlgC2BMCWALYEsCWALQGwJUBrSywXYEsAWwLYEgBbAtgSwJYAtgTAlgCtLbFcgC0BbAlgSwBsCWBLAFsC2BIAWwK0tsRyAbYEsCWALQGwJYAtAWwJYEsAbAnQ2hLLBdgSwJYAtgTAlgC2BLAlgC0BsCVAa0ssF2BLAFsC2BIAWwLYEsCWALYEwJYArS2xXIAtAWwJYEsAbAlgSwBbAtgSAFsCtLbEcgG2BLAlgC0BsCWALQFsCWBLAGwJ0NoSywXYEsCWALYEwJYAtgSwJYAtAbAlwMItMSuAnyiALQFsCYAtAWwJYEsAWwJgS4DWllguwJYAtgSwJQC2BLAlgC0BbAmALQFaW2K5AFsC2BLAlgDYEsCWALYEsCUAtgRobYnlAmwJYEsAWwJgSwBbAtgSwJYA2BKgtSWWC7AlgC0BbAmALQFsCWBLAFsCYEuA1pZYLsCWALYEsCUAtgSwJYAtAWwJgC0BWltiuQBbAtgSwJYA2BLAlgC2BLAlALYEaG2J5QJsCWBLAFsCYEsAWwLYEsCWANgSoLUllguwJYAtAWwJgC0BbAlgSwBbAmBLgNaWWC7AlgC2BLAlALYEsCWALQFsCYAtARZuiVkB/EQBbAlgSwBsCWBLAFsC2BIAWwK0tsRyAbYEsCWALQGwJYAtAWwJYEsAbAnQ2hLLBdgSwJYAtgTAlgC2BLAlgC0BsCVAa0ssF2BLAFsC2BIAWwLYEsCWALYEwJYArS2xXIAtAWwJYEsAbAlgSwBbAtgSAFsCtLbEcgG2BLAlgC0BsCWALQFsCWBLAGwJ0NoSywXYEsCWALYEwJYAtgSwJYAtAbAlQGtLLBdgSwBbAtgSAFsC2BLAlgC2BMCWAK0tsVyALQFsCWBLAGwJYEsAWwLYEgBbArS2xHIBtgSwJYAtAbAlgC0BbAlgSwBsCbBwS8wK4CcKYEsAWwJgSwBbAtgSwJYA2BKgtSWWC7AlgC0BbAmALQFsCWBLAFsCYEuA1pZYLsCWALYEsCUAtgSwJYAtAWwJgC0BWltiuQBbAtgSwJYA2BLAlgC2BLAlALYEaG2J5QJsCWBLAFsCYEsAWwLYEsCWANgSoLUllguwJYAtAWwJgC0BbAlgSwBbAmBLgNaWWC7AlgC2BLAlALYEsCWALQFsCYAtAVpbYrkAWwLYEsCWANgSwJYAtgSwJQC2BGhtieUCbAlgSwBbAmBLAFsC2BLAlgDYEqC1JZYLsCWALQFsCYAtAWwJYEsAWwJgS4CFW2JWAD9RAFsC2BIAWwLYEsCWALYEwJYArS2xXIAtAWwJYEsAbAlgSwBbAtgSAFsCtLbEcgG2BLAlgC0BsCWALQFsCWBLAGwJ0NoSywXYEsCWALYEwJYAtgSwJYAtAbAlQGtLLBdgSwBbAtgSAFsC2BLAlgC2BMCWAK0tsVyALQFsCWBLAGwJYEsAWwLYEgBbArS2xHIBtgSwJYAtAbAlgC0BbAlgSwBsCdDaEssF2BLAlgC2BMCWALYEsCWALQGwJUBrSywXYEsAWwLYEgBbAtgSwJYAtgTAlgCtLbFcgC0BbAlgSwBsCWBLAFsC2BIAWwJcfUs2awJ@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@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@/y3a6P2/99/b5Pez2/WNYlLqs5WNY1M26rqdzU8ez61bjWerr71LLdJsu4@@uGz/1Hw "APL (Dyalog Unicode) – Try It Online") Simply picks the result from a pre-compiled list. [Answer] # Java, complexity: \$O(\lfloor\log\_{10}(n) + 1\rfloor)\$ ``` boolean f(int n){ int reverse = 0; //int debugIterations = 0; for(int palindrome = n; palindrome != 0; palindrome /= 10){ //debugIterations++; int lastDigit = palindrome % 10; reverse = reverse * 10 + lastDigit; } //System.out.println("Debug iterations: "+debugIterations); return n == reverse; } ``` Loops once for every digit in the input-number. Pretty straight-forward implementation tbh.. [Try it online.](https://tio.run/##bVFNa4QwFLz7K16Fgla6fqwuWPG2lx562mPpIa5RstVEkiiU4m@3SVZXkYYckpk3My8vNzSg11v5PV0bJAR8IEJ/LQAhkSRXmArGGowoVA6hEqirOX3ieMBcYMghyBTk@xoscdHX7xJzpWVULGTFuFF3qCG05KzVMppt70@6dAv4OYSBSdPmO2PPywyhTVXX8kxqIpXnRv@s5PeitdPl9KI48FalrhvNIy4/QuL2wHp56Lhyb6hjn3U2kEf4G9jerh9XO3Ase06BQv5IyqxxyizFdX3RqGnOQx0YKaFVg3YuUqXUn1@A5qdKLKQTRsc4iY9R6GYrGKUntXfIKY22SBKnaZwsRb5vwGBbkc5ri4X3nNFav910aMj11wH@mQ71bD2PyqHubDJOfw) [Answer] # Java, O(1) ``` boolean f(int n){ if (n <= 0 || n >= 16777216) throw new Error(n+" is not a valid input!"); int reverse = n/10000000%10*1 + n/1000000%10*10 + n/100000%10*100 + n/10000%10*1000 + n/1000%10*10000 + n/100%10*100000 + n/10%10*1000000 + n/1%10*10000000; int len = (int) Math.log10(n); reverse/= Math.pow(10, 7-len); return reverse == n; } ``` [Try it online!](https://tio.run/##XZJNc4IwGITv/oqtM52BWpVggKGW3nrsyWPbQ1TUWEyYEHA61d9OIx8i5pZnk519d949K9h4v/4pVwnLMnwwLvA3ADLNNF@VSymTmAlsLC40hH2R@AaWwGsEB6cTBN4iED8IApf4NvROySNEfMS7UlJZYjQEzyCkBkPBEr4GF2muH4b2/OJlXFVcxCqLEUFMiVOfR@I8EYw6UgHnhtTghjSgIy24kitoSQcacgOcNl4SCxPtMr9t6tG7SSK3xLFElb/JPo1qKZVHizjPCMbmV/NA50p0M5oh54NzCaT5MuGrpmcU0hRzMOVbC6242H5@g1VlAzrOtEXcmUsqwwa4oe/6dyB0e4BSrweI27cgLrnT7@SeSmnv1tM8GobU8/u/Z9Sjbejz4LpS9ajVm26lgMVvpuPDROZ6kpoCdCIuq/PypYejjem6cTmX/w "Java (JDK) – Try It Online") Kevin Cruijssen's answer, unrolled for 24-bit numbers. [Answer] # APL+WIN, O(1) Thanks to Adam for suggested changes to my original code and his explanation - see the comments section. Prompts for input of integer. ``` 17=+/(⌽17↑n)=¯17↑n←⍕⎕ ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcjzra0/4bmttq62s86tlraP6obWKepu2h9RAWUMmj3qlA1f@B6v6ncRkaGZuYmhgbGXKlcRlZmgERhGFmaQRkmJpYWpqYgoQMuLgA "APL (Dyalog Classic) – Try It Online") ]
[Question] [ It is only Tuesday, ugh. I deserve a treat. Golf me a Castle. The Least amount of bytes wins! Taken no input and output this image exactly: ``` /\ /\ / \ / \ ---- ---- | |^^^^^^^^^| | ----------------- | _ | | | | | | | | | | | ``` ### Edit [Build me a brick wall!](https://codegolf.stackexchange.com/questions/99026/build-me-a-brick-wall) 36 votes versus my -9. Okay. [Answer] # [Bubblegum](http://esolangs.org/wiki/Bubblegum), 52 bytes ``` 00000000: 35c8 3111 c030 1443 b1fd a310 815c 08f5 5.1..0.C.....\.. 00000010: 5a22 06df 64b0 263f db0f 7562 367d b831 Z"..d.&?..ub6}.1 00000020: eb50 3726 e4ad 9059 5513 c007 c804 2142 .P7&...YU.....!B 00000030: f441 74fc .At. ``` Obligatory Bubblegum answer. [Answer] # Swift 3, 200 bytes ``` var z=" /\\ 9/\\\n/ \\ 7/ \\\n-2 7-2\n| |^7| |\n-95\n| 5_ 5|\n| 1| | | | 1|\n| 4| | 4|",o="",x="" for c in z.characters{let k="\(c)" if let b=Int(k){for i in 0...b{o+=x}}else{o+=k x=k}} print(o) ``` Basically loop trough the `Characters` of `z` string, if a digit (b) is found then repeat the last character `b+1` times [Try online here](http://swiftlang.ng.bluemix.net/#/repl/5823c9fda56869580c971836) [Answer] # Ruby, 130 bytes ``` f=->a,b=' '{a+b*9+a};g=->s{?|+s.center(15)+?|};puts f[' /\\ '],f['/ \\'],f[c=?-*4],f[d='| |',?^],f[c,?-],g[?_],g[d+' '+d],g['| |'] ``` This can probably be golfed down more. [Answer] ## JavaScript (ES6), 120 bytes ``` _=>` /\\44/\\ /8\\36/8\\ 173617 |8|38|8| 69 |28_28| |12|8| |8|12| |24| |24|`.replace(/\d\d?/g,n=>' -^'[n&3].repeat(n/4)) ``` ### Demo ``` let f = _=>` /\\44/\\ /8\\36/8\\ 173617 |8|38|8| 69 |28_28| |12|8| |8|12| |24| |24|`.replace(/\d\d?/g,n=>' -^'[n&3].repeat(n/4)) console.log(f()) ``` ]
[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/25045/edit). Closed 9 years ago. [Improve this question](/posts/25045/edit) You have to write a program that will count all the characters in specified source file so that people entering a code golf competition can see their score. You do not need to ignore comments (it is code golf) in your program but newlines should be counted as a character. The number of characters must be printed to stdout. Shortest code wins! Example in python: ``` import sys try: content = open(sys.argv[1], "r").read() except IndexError, e: print("No file specified") sys.exit(1) except IOError, e: print("File not found") sys.exit(1) count = 0 for i in list(content): if(i!=''): count+=1 print(str(count)+" characters long") ``` Note: you cannot use the bash command `wc -c`. [Answer] # bash+coreutils, 7 chars ``` stat $1 ``` [Answer] # Dash, 18 ``` tr \\0-ÿ \\n|wc -l ``` Reads from STDIN. Doesn't use `wc -c` or Bash. ]
[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/4094/edit) Write a function that, given N >= 0, finds the Nth number in a [standard Gray code](http://oeis.org/A003188). Example input: ``` 1 2 3 4 ``` Example output: ``` 1 3 2 6 ``` [Additional reference](http://en.wikipedia.org/wiki/Gray_code) [Answer] ### Perl, 7 chars ``` $_^$_/2 ``` This is an expression that returns the Gray code, given the input in `$_`. You can use it on the command line with the `-n` switch: ``` perl -nE 'say $_^$_/2' ``` or use it in a `map`: ``` perl -E 'say for map $_^$_/2, 1 .. 10' 1 3 2 6 7 5 4 12 13 15 ``` If you specifically want a *function*, I can do that too (in 20 chars): ``` sub g{$_[0]^$_[0]/2} ``` --- **Edit:** Since this challenge is now tagged [fastest-code](/questions/tagged/fastest-code "show questions tagged 'fastest-code'"), let me include the equivalent C preprocessor macro, which should be about as fast as this can be done: ``` #define g(i) ((i)^(i)>>1) ``` A faster solution, if one exists, is likely to require hand-optimized assembly code. Even then, a good optimizing C compiler may be hard to beat. Looking at the disassembly of the benchmark code below, it seems gcc compiles this into three Intel assembly instructions: ``` 8048428: 89 c2 mov %eax,%edx 804842a: d1 ea shr %edx 804842c: 31 c2 xor %eax,%edx ``` This (a register copy, a shift and an XOR) is about what I'd expect any decent compiler to produce. Of course, a good compiler might also be able to interleave the operations with surrounding code to improve pipelining. (In the benchmark, the inner loop is tight enough that there's not much room for that.) Testing just how fast this is can be a bit tricky, since we need to make sure the compiler won't just optimize away the Gray code calculation, or even the entire testing loop. Here's a piece of code that sums up all unsigned 32-bit integers eight times over, either in Gray code order or, if `NOGRAY` is defined, in normal binary order. Obviously, the output should be zero in either case, but at least gcc isn't smart enough to realize that. ``` #include <inttypes.h> #include <stdio.h> #ifdef NOGRAY # define g(i) (i) #else # define g(i) ((i)^(i)>>1) #endif int main (void) { uint32_t k, i, n = 0; for (k = 0; k < 8; k++) { for (i = 1; i != 0; i++) n += g(i); } printf("%lu\n", (unsigned long) n); return 0; } ``` On my 2.2GHz AMD Athlon 64 X2 CPU, compiled with gcc 4.4.3 with `-O3` for i486-linux-gnu, running this code takes about 46.9 seconds, compared to about 31.2 second with `NOGRAY` defined. That gives about 15.7 seconds for 235−8 Gray code calculations, which comes down to about 0.457 nanoseconds, or almost exactly **one CPU cycle** per calculation. However, it's worth noting that that's the *marginal* cost of including the Gray code calculation in the loop. The total time to execute the benchmark loop (which includes two adds and a conditional jump in addition to the three lines of assembly I showed above) is about 1.365 nanoseconds, or three cycles per iteration. [Answer] ### Golfscript, 4 chars ``` .2/^ ``` [Answer] ### scala: ## It's not a code-golf! However - if you like to golf: ``` def g(n:Int)=n^(n/2) ``` 20 chars, according to my set of natural numbers. But since speed matters, I produce a compilable form: ``` object Graycode extends App { def graycode (n: Int) = n^(n/2) def test (max: Int) { var i = 0 val start = System.nanoTime () while (i < max) { graycode (i) i += 1 } val stop = System.nanoTime () val diff = (stop-start)*1.0 / (1000*1000*1000) println ("Time: " + diff + "s\tn: " + max + "\tspeed: " + max * 1.0/diff + " /s") } override def main (args: Array[String]) = { var max = args(0).toInt val graycode = Graycode graycode.test (max) } } ``` You can compare it against your solution this way: ``` scala Graycode 1000000000 Time: 23.882410496s n: 1000000000 speed: 4.1871820274066865E7 /s ``` About 4 million ints per second on my machine. If I comment out the call to graycode, I get as speed: 7.683713972447292E8 /s, so it is not mainly the time used to loop, which is measured above. Of course your absolute times will vary, but you may compare it to measurements of your code. Please provide measurement methods with your solutions too. ]
[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/127980/edit). Closed 6 years ago. [Improve this question](/posts/127980/edit) # Introduction [OnePlus](https://en.wikipedia.org/wiki/OnePlus) is a Chinese smartphone manufacturer founded in December 2013. Their latest phone, OnePlus 5, was unveiled on June 20, 2017. I am sure you have seen that the name of the phone can easily be translated to a sum. `OnePlus` can be written like `1+` thus `OnePlus 2 = (1+ 2) = 3` # Input The name of one OnePlus phone. The above list in the only possible input ``` OnePlus 1 OnePlus 2 OnePlus X OnePlus 3 OnePlus 3T OnePlus 5 ``` # Output The sum of the name (a number **not a string**) ``` OnePlus 1 => 2 OnePlus 2 => 3 OnePlus X => an integer OnePlus 3 => 4 OnePlus 3T => 27 (T = Today = 23 thus 1+3+23=27) OnePlus 5 => 6 ``` # Rules The input can be written in different versions. This applies to every names. For example ``` OnePlus 1 OnePlus1 One+ 1 One+1 1+ 1 1+1 ``` * The output for `OnePlus X` is an integer that should be different from the other phones names. Whatever you want except `2,3,4,27,6` * The `T` in `OnePlus 3T` will always be `23` which is the day I am posting this. * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest solution (in bytes) wins. [Answer] # [Retina](https://github.com/m-ender/retina), ~~26~~ 16 bytes *-10 bytes thanks to @MartinEnder* ``` O 1 T 995 . $* 1 ``` [Try it online!](https://tio.run/##K0otycxL/K@q4Z7w35/LkCuEy9LSlEuPS0WLy/D/f/@81ICc0mIFQy4YywjOioCzjBGsEDjTFAA "Retina – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes ``` 0Uθ.VT26:> ``` [Try it online!](https://tio.run/##MzBNTDJM/f/fIPTQusMr9MJCjMys7P7/989LDcgpLVYwDgEA "05AB1E – Try It Online") `θ` has been replaced by `®è` on TIO since it hasn't been pulled there yet. Alternatively, `¤` would work too. Explanation: ``` 0Uθ.VT26:> "Accepts a single line from STDIN"\ 0 "Push 0"\ U "Assign to X"\ θ "(implicit input)"\ "Take the last element"\ .V "Eval as 05AB1E code"\ T "Push 10"\ 26 "Push 26"\ : "Infinitely replace"\ > "Increment"\ ``` [Answer] # [Perl 5](https://www.perl.org/), 21 bytes 20 bytes of code + `-p` flag. ``` $_=/\d$/?$&+1:27*/T/ ``` [Try it online!](https://tio.run/##K0gtyjH9r6xYAKQVdAv@q8Tb6sekqOjbq6hpG1oZmWvph@j/t1ZQiVfQs1VQislTslZQVnBMScnMS1dIVMhLLc/JzEtVKMlXyE3MBtIZqQr5pSUFpSUKyTmpiUWpRf/981IDckqLFQy5YCwjOCsCzjJGsELgTFMA "Perl 5 – Try It Online") If the input ends with an integer (`/\d$/`), then we add one to it (`$&+1`) and outputs it. Otherwise, we output `27*/T/` which is `27` if the inputs contains a `T`, and `0` otherwise. [Answer] # [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 138 bytes ``` using System.Linq;s=>s.Replace("One","1").Replace("Plus","+").Replace("T","+23").Replace("X","9").Split('+').Select(e=>int.Parse(e)).Sum() ``` [Try it online!](https://tio.run/##nZDBisIwEIbvfYrQiwnVgisepLaXBU@KZRXWa4ijBNLEzaSCLD57d1pkFW/tHEL4ki/zZxROlPPQ1Kjtme1uGKBK19r@ZFHEqJSRiKz07uxl1ZHfbm0LgwxasavTR7aR2nLxf/S81Nbj2VVt1RKDp05jbUPBTnnUYF5g@gUXIxXweGshHsfTWDxRaWoklryyfQs@Zq/oQGhBYHcxOvBRMqItGFCBQ15Qt7SUHoGDIF5XXDSPD75l/HQWnYH02@sANAfgpy5Vm4JRLpH1tQZJ7DDImg2z9oO0eV8r6T/ApJ8xfW9x73b35g8 "C# (.NET Core) – Try It Online") [Answer] # Java 8, ~~79~~ 61 bytes ``` s->{int x=s.charAt(s.length()-1);return x<58?x-47:x<85?27:9;} ``` **Explanation:** [Try it here with all possible test cases.](https://tio.run/##pZJfS8MwFMXf9ykue2oJDWRaNtfN4QdwCvNBEB9iFrfMLi1NOiqjn71mf3zVA4X2oenh5p7fOTt5kElRartbf3Uql87RozT2OCAy1uvqUypNy9Pn@YBUtPKVsRtycRYO2/CGx3npjaIlWZpT55L740nbzB1XW1k9@MjxXNuN30ZxIuKs0r6uLDWzdLJoktvxtJlN0sVoPL3L2i67jCzrjzyMvE4@FGZN@7DY9fq3d5LxZavVt/N6z4va8zL88rmNLFfR8Mnq57x2JIbxedX/lSNY@Qorb3DlCyxN/1JiM2AqMBSYCYwEJ9ITCMNKwrCGMKweDOsGA4vB@raCYQwwBBgBDADov499gTRAIPkLJH2BZC@g5EW/3AVDfCO2EdeIacjzr@V20HY/) ``` s->{ // Method with String parameter and integer return-type int x=s.charAt(s.length()-1); // Get the last characters of the input return x<58? // If it's a digit: x-47 // Return that digit + 1 :x<85? // Else if it's a 'T': 27 // Return 27 : // Else (it's a 'X') 9; // Return 9 (unique digit other than 2,3,4,6,27) } // End of method ``` [Answer] # [C (gcc)](https://gcc.gnu.org/), ~~65~~ ~~63~~ 48 bytes ``` f(char*s){s+=strlen(s)-1;s=*s?*s^84?*s-47:27:9;} ``` [Try it online!](https://tio.run/##S9ZNT07@/z9NIzkjsUirWLO6WNu2uKQoJzVPo1hT19C62Far2F6rOM7CBEjqmphbGZlbWVrX/ufKTczM09DkquZSAIKCosy8kjQNJdWUmDwlHSDDPy81IKe0WMFQSVPTGr8SI8JKIggrMSZCSQhhNaZ4lWhD/VPL9f9rXr5ucmJyRioA "C (gcc) – Try It Online") [Answer] # Excel VBA, ~~87~~ 51 bytes Anonymous VBE immediate window function that takes input from cell `[A1]` and outputs OnePlus math to the VBE immediate window ``` i=Asc(Right([A1],1)):?IIf(i<58,i-47,IIf(i<85,27,9)) ``` ## Old Version Anonymous VBE immediate window function that takes input from cell `[A1]` that and outputs OnePlus math to the VBE immediate window ``` ?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23")) ``` ### Input/Output As a result of the `Application.Evaluate` call this solution is afforded access to all of the Excel WorkSheet Functions ``` [A1]="OnePlus 3T" ?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23")) 23 [A1]="OnePlusPi()" ?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23")) 4.14159265358979 [A1]="One+Day(Now())" ?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23")) 26 ``` ]
[Question] [ Your job is to output the html of the current version (at the time of this writing) of the Wikipedia page for Kolmogorov complexity: <https://en.wikipedia.org/w/index.php?title=Kolmogorov_complexity&oldid=781950121&action=raw> ([backup](https://gist.githubusercontent.com/anonymous/826ffbc9c86501f86db740ad0c97fd40/raw/d963d6b5804156cd7fb19da91724720cea985d48/Kolmogorov%2520complexity)) This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code wins. [Answer] # 7zip file manager: 12,156 bytes hex dump: [here](https://pastebin.com/1BUJqZ0v) ## how to use: `7zip e [savedfileName]` I'm posting this because it's about as small as you can get it without using HTTP calls. [Answer] # [Bubblegum](https://esolangs.org/wiki/Bubblegum), 12,290 bytes [**Hexdump of solution.**](https://gist.github.com/GolfingSuccess/e3a00ccd25a6f7c1406c4129951ad9b3) [Try it online!](https://tio.run/#bubblegum "Bubblegum – Try It Online") (you have to paste the hexdump yourself, it's too long to fit in 30k chars) ]
[Question] [ **This question already has answers here**: [Convert a number to Hexadecimal](/questions/68247/convert-a-number-to-hexadecimal) (32 answers) Closed 8 years ago. ## Challenges You need to do a program that outputs the input string to hexadecimal! For each character in the input string, convert it's ascii value to hexadecimal and output it out. ## Example ``` Something = 536f6d657468696e67 ``` Of course, this is code golf, so the shorter code wins! [Answer] ## Pyth, 3 bytes ``` .Hz ``` [Pyth docs](https://github.com/isaacg1/pyth/blob/d0857326708284d884298464363e633e1390b190/rev-doc.txt#L292): ``` .H <str> Converts A to a hexadecimal string, treating the string as a base 256 integer. ``` `z` is a variable autoinitialized to `input()`. [Try it here.](https://pyth.herokuapp.com/?code=.Hz&input=Something&debug=0) [Answer] ## Bash, 6 bytes​​​​​​​​​​ ``` xxd -p ``` [Answer] # JavaScript ES6, 49 bytes ``` s=>s.replace(/./g,l=>l.charCodeAt().toString(16)) ``` [Try it online](http://vihan.org/p/esfiddle/?code=f%3D%20s%3D%3Es.replace(%2F.%2Fg%2Cl%3D%3El.charCodeAt().toString(16))%0A%0Af(%22Something%22)%3B) [Answer] ## Python3 console, 21 bytes ``` input().encode("hex") input() -- Gets the input in a string. .encode("hex") -- Encodes it to hexadecimal. ``` Doing this on the console saves the `print` argument. [Answer] # 𝔼𝕊𝕄𝕚𝕟, 7 chars / 9 bytes ``` ïⓢ⒨⒞ⓧ)⨝ ``` `[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter3.html?eval=false&input=Something&code=%C3%AF%E2%93%A2%E2%92%A8%E2%92%9E%E2%93%A7%29%E2%A8%9D)` Explanation later. [Answer] # TeaScript, 5 bytes ``` ΣcT16 ``` I really need to add base conversion built-ins [Try it online](http://vihan.org/p/teascript/#?code=%22%CE%A3cT16%22&inputs=%5B%22Something%22%5D&opts=%7B%22int%22:false,%22ar%22:false,%22debug%22:false%7D) ## Explanation ``` Σ // Loop through input c // Get char code T16 // To hexadecimal ``` [Answer] # JavaScript ES6, 50 bytes ``` s=>[for(c of s)c.charCodeAt().toString(16)].join`` ``` Using an [array generator comprehension](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Generator_comprehensions), it loops through each character of the string and generates an array of the transform, then call `.join()` with an empty string as an argument to prevent inclusion of commas in default array `toString()` method. [Try it Online](http://vihan.org/p/esfiddle/?code=f%3Ds%3D%3E%5Bfor(c%20of%20s)c.charCodeAt().toString(16)%5D.join%60%60%0Af(%22Something%22)) This currently only works in Firefox v ≥ 30 [Answer] # [Perl 6](http://perl6.org), 25 bytes ``` {lc [~] .ords».base(16)} ``` ### Usage: ``` my &code = {lc [~] .ords».base(16)} say code 'Something'; # 536f6d657468696e67 ``` [Answer] ## Python, 24 bytes ``` lambda x:x.encode("hex") ``` Test: ``` a=lambda x:x.encode("hex") a("something") # 736f6d657468696e67 a("Hello World!") # 48656c6c6f20576f726c6421 ``` ]
[Question] [ **This question already has answers here**: [Count the divisors of a number](/questions/64944/count-the-divisors-of-a-number) (68 answers) Closed 3 years ago. Create a function which takes in a input integer and then returns the number of factors it has, like if you pass `25` then it will return `3` since it has 3 factors i.e. `1,5,25`. **Challenge:** Make the fastest and the smallest code! [Answer] # [Neim](https://github.com/okx-code/Neim), 1 byte ``` 𝐜 # Get Divisor count ``` [Try it online!](https://tio.run/##y0vNzP3//8PcCXP@/zcyBQA "Neim – Try It Online") Got to use Neim, yay. ]
[Question] [ Target: Write a `floor()` function from scratch. Manipulating like converting float to string, and cutting all after dot are allowed. All languages are allowed. Any usage of built in language functions (like `toInteger()`) or similar is not allowed, casting operators are not allowed. So, your task is implement floor() function without using casting and built in language functions. Your function must support at least max 32-bit integer values (you will never receive negative values). Forced casting (like `somevar as float`) and normal casting - such as`(int) somevar` - is not allowed, any built in functions, not allowed, all other stuff allowed. Winner: Shortest implemention. [Answer] # [C (gcc)](https://gcc.gnu.org/), 57 bytes ``` i;int f(float n){for(i=-2147483648;i<=n;i++);return i-1;} ``` [Try it online!](https://tio.run/nexus/c-gcc#U87MS84pTUlVsCkuScnM18uw@59pnZlXopCmkZaTn1iikKdZnZZfpJFpa2CdaWObZ52pra1pXZRaUlqUp5Cpa2hd@z83MTNPI1GzmouzoAioM01DSTUlJk9JJ03DWM9AU9Mam7ihiaGpJUiu9j8A "C (gcc) – TIO Nexus") (it takes too long, so I changed it to start from `0`. [Answer] # [CJam](https://sourceforge.net/p/cjam), 6 bytes ``` q'.%0= ``` [Try it online!](https://tio.run/nexus/cjam#@1@orqdqYPv/v6GJsaGxkZ6ppaWlsREA "CJam – TIO Nexus") I found several 6 bytes solution but I can't do less than this. [Answer] # Javascript, 6 chars ``` x=>~~x ``` Test: ``` f = x=>~~x document.addEventListener('input', event => { var x = event.target.valueAsNumber document.querySelector('output').textContent = x + " => " + f(x) }) ``` ``` <input type=number> <output></output> ``` [Answer] # [Python 2](https://docs.python.org/2/), ~~21~~ 13 bytes ``` lambda x:x//1 ``` Outputs a float if input is float, outputs an integer if input is integer. [Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqhQYVWhr2/4vzwjMydVIaSoNNWKi7OgKDOvRCFNIzOvoLREQ1Pzv6GRMZehibGhsZGeqaWlpbERlyGXAZeBniGXIRAb6BkAaQMA "Python 2 – TIO Nexus") [Answer] # [Japt](https://github.com/ETHproductions/japt), 2 bytes ``` |0 ``` [Try it online](http://ethproductions.github.io/japt/?v=1.4.4&code=fDA=&input=MTIzLjc4OQ==) --- ## Alternative ``` ÂU ``` [Try it online](http://ethproductions.github.io/japt/?v=1.4.4&code=wlU=&input=MTIzLjc4OQ==) [Answer] # Batch, 53 bytes ``` @for /f "tokens=1 delims=." %%a in ("%1")do @echo %%a ``` *Trims everything after `.`* ]
[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/79938/edit). Closed 7 years ago. [Improve this question](/posts/79938/edit) There's been challenges for the [shortest cat program](https://codegolf.stackexchange.com/questions/62230/simple-cat-program), but as far as I know, there hasn't been any for the *longest* one. A cat program is a program that copies its input to its output. Here's an example: ``` Input: Hello Output: Hello Input: cat Output: cat ``` So, the rules are simple: * The program has to copy its input to its output * No loopholes allowed. * **This is code-bowling, so the longest code wins.** Also, I'm quite new here, so if you don't like this challenge, then please do tell me why so I'll be able to make better ones later! [Answer] # [Brachylog](https://github.com/JCumin/Brachylog), theoretically infinite ``` ............................................................................................. ``` You can add as many periods as you like. The first period will unify the output with the input. The second period will unify the output with the output (which is always true), the third period will unify the output with the output, etc. [Answer] # Lenguage, 23855 bytes Program: Any file that is 23855 bytes long Based off the brainfuck cat program on an interpreter returns 0 on EOF: ``` ,[.,] ``` ]
[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/69327/edit). Closed 8 years ago. [Improve this question](/posts/69327/edit) > > People, it's a popularity contest, you have to do somthing cool here. > > Think about cool ways of breaking the code in most languages, not about validating for everyting! > > > > > Initially this challenge is NOT for esoteric languages. But I didn't disabled them as I expect voters to be fair enough to downvote answers based only on esoteric language syntax uniqueness. > > > > > It's not too broad. I thought about code golf tag, but desided that it will be unnessesary limitation for the answers. I expect anwsers to be short and exploiting some language feature. > > > > > By the way, I have an interesting solution for VB.NET and it is shorter than 8 chars :) > > > --- Write a statement that multiplies the (integer) variable by 10 and assigns result to the same variable. If your language has no integer type, you may assume that the value is an integer not greater then some limit (you can specify this limit yourself, but it defenitly have to be adequate). The initial and resulting values have to be number. Using string as one of them (or both) is forbidden. But you don't want the code to be protable, so you are going to write it in such way, that the code is valid for **as *few* programming languages as possible**. Ideally in the only language. Example: > > You have variable > > > > ``` > int x = 77; > > ``` > > and the answer is > > > > ``` > x *= 10; > > ``` > > Declaration is not the part of the answer, only `x *= 10;` is. So this code is valid for C, C++, C#, Java, Javascript and probably some other languages. It's defenity a bad answer in this challenge. Just drop a semicolon to cut off C, C++, C# and Java, but VB.NET appears in this case. Scoring system: it's a popularity contest. For now I'll define the answer score as number of votes, but I'll keep a right to change scoring system by including number of languages into it. So you have to provide a statement and list of languages (ideally one language) it is valid in. [Answer] In Perl you can do: ``` $var .= 0; ``` because it is not typed. or ``` $var =~ s/$/0/; ``` Regex that adds a zero at the end of line. [Answer] # [Vitsy](https://github.com/VTCAKAVSMoACE/Vitsy), 2 bytes ``` a* ``` Call this method through any normal means (00k or 0m). The top item of the stack will be multiplied by 10 (a in hexadecimal). This is very anti-polyglot because most stack based languages don't *have* methodology. ]
[Question] [ Make a [cat program](https://esolangs.org/wiki/Cat_program), with a catch. The program must refuse under all circumstances to output "Hello World", instead outputting "Goodbye World", with matching spacing (but matching casing is not required). "Hello World" must never appear as a substring of the output, regardless of casing, not even if the two words are (or are not) separated by newlines, spaces, tabs, or even multiple executions of the program. # Rules These are all forbidden: ``` Hello World HelloWorld Hello world HELLOWORLD I want to wish you hello world HeLlOwOrLd and all who inhabit it Hello world I said hello world news ``` Instead, the output should read: ``` Goodbye World GoodbyeWorld Goodbye world GOODBYEWORLD I want to wish you goodbye world Goodbyeworld and all who inhabit it Goodbye world I said goodbye world news ``` However, other characters that separate hello and world will cause the string to not be matched. These should be repeated verbatim: ``` Hello, world hello happy world HELLO2THEWORLD ``` If the program is run twice in sequence (for example, in a batch script), first against the string "hello" and then against the string "world", the output should be: ``` goodbye world ``` But if it is run against "hello" and then "friends", the output should be: ``` hello friends ``` You can choose whether to abstain from printing hello until the next run (this means if that command never comes, it will never print, which is acceptable), or to change it retroactively, if possible. The program does not have to take into account the possibility of other programs being run between runs. # Examples Here's a quick .sh I put together to test it (I named my binary goodbye): ``` echo hello world | ./goodbye echo hello friends | ./goodbye echo HeLlO wOrLd | ./goodbye (echo hello; echo world) | ./goodbye (echo hello; echo friends) | ./goodbye echo helloworld | ./goodbye echo "hello world" | ./goodbye echo I say hello | ./goodbye echo world | ./goodbye echo hello | ./goodbye echo friends of mine | ./goodbye echo hello happy world | ./goodbye echo hello2theWORLD | ./goodbye ``` This is code golf, so lowest byte count (per language) wins! [Answer] It seems there's some confusion over whether this is possible, so here's an example answer in... # FLEX/C (557 bytes) ``` %option noyywrap %{#include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #define p(X) printf(X) #define s(X) strncat(w,X,99) #define g(X) if(l==1){X} #define d w[0]='\0';p(t);l=0; #define t yytext int l = 0;char *w; %} %% [hH][eE][lL][lL][oO] {l=1;} [wW][oO][rR][lL][dD] {g(p("goodbye");)p(w);d} [\r\n\t ] {g(s(t);)else{p(t);}} . {g(p("hello");)p(w);d} %% main(int c,char **a){w=malloc(99);w[0]='\0';if(access("f",F_OK)==0){l=1;remove("f");s("\n");}yylex();if(l==1){FILE* f=fopen("f","w");fclose(f);}else{p("\n");}} ``` Here's the ungolfed version: ``` %option noyywrap %{ #include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #define FLAG_FILE "goodbye.flg" int last = 0; char *whitespace; %} %% [hH][eE][lL][lL][oO] { last = 1; } [wW][oO][rR][lL][dD] { if (last == 1) { printf("goodbye"); } printf(whitespace); whitespace[0] = '\0'; printf(yytext); last = 0; } [\r\n\t ] { if (last == 1) { strncat(whitespace, yytext, 100); } else { printf(yytext); } } . { if (last == 1) { printf("hello"); } printf(whitespace); whitespace[0] = '\0'; printf(yytext); last = 0; } %% main(int argc, char **argv) { whitespace = malloc(1000); whitespace[0] = '\0'; if (access(FLAG_FILE, F_OK) == 0) { last = 1; remove(FLAG_FILE); strncat(whitespace, "\n", 100); } yylex(); if (last == 1) { FILE* file_ptr = fopen(FLAG_FILE, "w"); fclose(file_ptr); } else { printf("\n"); } } ``` It chooses the abstain option, which as noted in the question, allows it to abstain from printing the last word if the last word in the input is "hello", and then decide on the next run whether to print "hello" or "goodbye" based on whether the following word is "world." ]
[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/42350/edit). Closed 7 years ago. [Improve this question](/posts/42350/edit) You need to produce the word **codegolf** --- ### **Rules:** 1. ***None*** of the characters of the word `codegolf` (i.e. 'c', 'o', 'd', 'e', 'g', 'o', 'l' and 'f') in either case can exist anywhere in the code. 2. Case of the word must be one of three: * All Upcase (`CODEGOLF`) * All Downcase (`codegolf`) * Capitalized (`Codegolf`) 3. You only need to produce it somehow so there can be other characters in the output as well. For example, `21§HCodegolf092` is an acceptable result. 4. The shortest code (counting in bytes) to do so in any language wins. --- I guess it will be less trickier in some languages than others (Brainfuck, Javascript, etc.) [Answer] ## Bash(works if there are no other files matching `/bin/?at`), 14 ``` /bin/?at /*/u* ``` This expands to `cat <files>`, where the files include /dev/urandom. Because of the infinite monkey theorem, this will eventually output "codegolf". [Answer] # PHP, 8 bytes ``` CODEGOLF ``` Does not contain 'c', 'o', 'd', 'e', etc. (You *might* want to ban their uppercase versions as well.) [Answer] # C - lots of characters Without `include`, `define`, `char`, `printf`, `return` and lots of other useful things, it's a real challenge to try to do this in C. I thought of outputting upside down letters, i.e. ɟloƃǝpoɔ, but the l and o are the same. So here's the best I can do, which many people might remember as being very much like their first C assignment. ``` int main() { puts(" @ @ @@ "); puts(" @ @ @ "); puts(" @ @ @ "); puts(" @@@ @@@ @@@@ @@@ @@@@ @@@ @ @@@@@ "); puts(" @ @ @ @ @ @ @ @ @ @ @ @ @ @ "); puts(" @ @ @ @ @ @@@@@ @ @ @ @ @ @ "); puts(" @ @ @ @ @ @ @ @ @ @ @ @ @ "); puts(" @@@ @@@ @@@@ @@@ @@@@ @@@ @ @ "); puts(" @ "); puts(" @ "); puts(" @@@ "); } ``` To compile: `gcc -o codegolf codegolf.c`, surprisingly `gcc`, at least my installation, doesn't complain about missing includes or returns. Running: ``` $ ./codegolf @ @ @@ @ @ @ @ @ @ @@@ @@@ @@@@ @@@ @@@@ @@@ @ @@@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @@@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @@@ @@@ @@@@ @@@ @@@@ @@@ @ @ @ @ @@@ ``` If you squint your eyes and/or zoom out, it kind of looks okay! [Answer] # Pyth, 9 bytes with updated rules ``` ^v"\107"8 ``` `v"\107"` evals a string containing `G`, octal escaped, which is the pyth variable for the alphabet. `^G8`, is the result, which prints all 8 letter strings in the lowercase alphabet, including `codegolf`. Runs out of memory on my machine, unfortunately. [Answer] # Javascript (2,786 Bytes) I'm not competing with this answer, just pointing out that it can be done. ``` ([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[!+[]+!![]]+([][[]]+[])[!+[]+!![]+!![]]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+([][[]]+[])[+[]]+([][[]]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(![]+[])[!+[]+!![]+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+([]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+(!![]+[])[+[]]+([][[]]+[])[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]])())[!+[]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]])()([][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(![]+[])[!+[]+!![]+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+([]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+(!![]+[])[+[]]+([][[]]+[])[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]])())[!+[]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]])()(([]+{})[+[]])[+[]]+(!+[]+!![]+!![]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+[]))+([]+{})[+!![]]+(![]+[])[!+[]+!![]]+([][[]]+[])[!+[]+!![]+!![]+!![]] ``` --- **Output:** ``` codegolf ``` [Answer] # CJam, 15 bytes ``` "r~utv~}w"{H^}% ``` I guess it should be shorter than Marbelous. [Answer] ## PHP, 13 bytes ``` <?=~œ›š˜“™; ``` StackExchange may swallow some of the control characters. Here's a hexdump of the program: ``` 3c 3f 3d 7e 9c 90 9b 9a 98 90 93 99 3b ``` It bitwise inverts the string, and prints it using the PHP short tag syntax. [Answer] # Java, 118 Bytes This is probably the lamest answer. Java programs have many key words. In order to print anything you have to use `System.out`. Despite all of these restrictions I can remove all of the letters in `codegolf` from my program except two letters. With `c` and `o` allowed, 118 bytes: ``` c\u006cass a{pub\u006cic static voi\u0064 main(String[]a){Syst\u0065m.out.print("\143\157\144\145\143\157\154\146");}} ``` With `l` and `o` allowed, 123 bytes: ``` \u0063lass a{publi\u0063 stati\u0063 voi\u0064 main(String[]a){Syst\u0065m.out.print("\143\157\144\145\143\157\154\146");}} ``` With `c` and `f` allowed, 128 bytes: ``` c\u006cass a{pub\u006cic static v\u006fi\u0064 main(String[]a){Syst\u0065m.\u006fut.print("\143\157\144\145\143\157\154\146");}} ``` With `l` and `f` allowed, 133 bytes: ``` \u0063lass a{publi\u0063 stati\u0063 v\u006fi\u0064 main(String[]a){Syst\u0065m.\u006fut.print("\143\157\144\145\143\157\154\146");}} ``` With no restrictions on boilerplate code, 98 bytes: ``` class a{public static void main(String[]a){System.out.print("\143\157\144\145\143\157\154\146");}} ``` Expanded: ``` class a{ public static void main(String[]a){ System.out.print("\143\157\144\145\143\157\154\146"); } } ``` [Answer] ## Perl - 12 ``` say a.."z"x8 ``` This also takes advantage of rule 3. It prints every word from `a` to `zzzzzzzz`. Run with: ``` perl -E'say a.."z"x8' ``` [Answer] # CJam, 10 bytes ``` 'P,{_m*}3* ``` It runs very slowly, and it should run out of memory on most computers. But if it exited successfully finally, it will print a lot of things including `CODEGOLF`. [Answer] # [Marbelous](https://codegolf.stackexchange.com/a/40808/29588) - 9 bytes ``` 7A /\/\?? ``` This will with a probability approaching 1 print a string containing all three acceptable outputs, since it prints an endless string of random ascii characters (up to and including the lowercase 'z' with ascii value 7A). Nothing was specified about whether this program should terminate. And just to make it clear, the characters get printed as they get generated, not after the program terminates (which is never). [Answer] ## Brainfuck (66 Bytes) Can you do it in Brainfuck? Yes? Than I do it in Brainfuck! ``` ++++[++++>---<]>.[->+++++<]>.-----------.+.++.++++++++.---.------. ``` **Output:** ``` CODEGOLF ``` [Answer] # Javascript (29 bytes / 25 characters) ``` this['bt\x6fa']("àÄâÅ") ``` SE strips out the control characters, so here's a hex dump: ``` 74 68 69 73 5B 27 62 74 5C 78 36 66 61 27 5D 28 22 08 C3 A0 C3 84 18 C3 A2 C3 85 22 29 ``` ## With escape characters (34 / 29) ``` this['bt\x6fa']("\bàÄ\x18âÅ") ``` [Answer] # dc, 20 ``` 4850170388041124934P ``` Prints the ASCII byte stream 0x434F4445474F4C46. [Answer] # J, 6 (12?) char A sentence returning `CODEGOLF` at the REPL, along with every other combination of 8 ASCII characters and a whole bunch of spaces, newlines, and box-drawing characters. ``` {8#<a. ``` If you want to toss this into STDOUT, prepend `1!:2&4` to double the charcount. [Answer] # Python 2.7, ~~52~~ 48 bytes ``` print('%'+`map`[13])*8%(67,79,68,69,71,79,76,70) ``` **Output:** ``` CODEGOLF ``` This answer creates a format string using a 'c' found in the representation string of the built-in `map` function. The program then uses the format string to convert each integer into a character that creates the 'CODEGOLF' string. [Answer] # C, ~~49~~ 48 bytes -1 byte thanks to ceilingcat. ``` main(){int a[]={1701080931,1718382439};puts(a);} ``` # C11, ~~46~~ 45 bytes ``` main(){puts((int[]){1701080931,1718382439});} ``` It's obviously possible in C. Works in 32bit little-endian systems. [Answer] # Brainfuck (145 Bytes) ``` +++++++++++[>++++++>++++++>++++++>++++++>++++++>++++++>++++++>++++++<<<<<<<<-]>+.>+++++++++++++.>++.>+++.>+++++.>+++++++++++++.>++++++++++.>++++. ``` --- **Output:** ``` CODEGOLF ``` [Answer] # CJam, 18 bytes ``` "1n¯]"245bHb{'B+}% ``` This answer prints the result instantaneously without consuming infinite system memory :) It is just base conversion of the string `CODEGOLF` to both save bytes and to avoid using any of the restricted characters. [Just try it out here](http://cjam.aditsu.net/) [Answer] Alright, here we go again. # **[The Hexadecimal Stacking Pseudo-Assembly Language](https://esolangs.org/wiki/Hexadecimal_Stacking_Pseudo-Assembly_Language)** (156): (Technically not a valid entry, or so I'm told) ``` 200066 400000 200063 400000 200009 400000 210000 200066 400000 200009 400000 210000 200067 400000 200065 400000 200064 400000 200066 400000 200009 400000 210000 200063 400000 140000 ``` Output: ``` codegolf ``` [Answer] # Shell, 21 ``` tr 2-@ A-P<<<4@568@=7 ``` [Answer] # ROT13, 8 bytes ``` pbqrtbys ``` `rot13` is part of `bsdgames`. [Answer] # Unnamed Two-Dimensional Programming Language, 26 bytes ``` 67&79&68&69&71&79&76&70&s; ``` **Output:** ``` CODEGOLF ``` You can try it out [here](https://www.khanacademy.org/computer-programming/a/6252487852687360) (Replace the code in the `code()` function with this code). If it is acceptable, the final semicolon can be removed and the program will loop infinitely (in theory, not in the interpreter, as the interpreter gives up after 2048 instructions to avoid a browser-crashing infinite loop) for a score of **25 bytes**. This works by pushing the values for the characters `CODEGOLF` to the stack, printing them, and terminating. [Answer] # [Jelly](http://github.com/DennisMitchell/jelly), 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` “£ṙɲI⁵» ``` [Try it online!](http://jelly.tryitonline.net/#code=4oCcwqPhuZnJsknigbXCuw&input=) [Answer] # Vitsy, 6 bytes ``` <ZR^72 ``` This has a 1 in 36028797018963968 chance of printing the right order of characters per character output with ~10000 characters output a second. This means that, by 3.17 million years from now, you'll almost certainly have seen it. :) Using a method found [here](https://codegolf.stackexchange.com/a/42376/44713). [Try it online!](http://vitsy.tryitonline.net/#code=PFpSXjcy&input=) [Answer] **[Lua](http://www.lua.org/), 33 bytes** CODEGOLF (33 bytes) ``` print("\67\79\68\69\71\79\76\70") ``` Codegolf (40 bytes) ``` print("\67\111\100\101\103\111\108\102") ``` codegolf (40 bytes) ``` print("\99\111\100\101\103\111\108\102") ``` [Answer] ## Pyke, 5 bytes ``` ~aHpr ``` [Try it here!](http://pyke.catbus.co.uk/?code=%7EaHpr) [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 5 bytes ``` ’ƒËŠˆ ``` Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=4oCZxpLDi8Wgy4Y&input=) ]
[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/22492/edit). Closed 9 years ago. [Improve this question](/posts/22492/edit) You will take input such as <http://examples.example.co.nz/abcdefg> and return the name of the website, in which this example would be `example`. To be more specific, I am looking for the [Second Level Domain](https://en.wikipedia.org/wiki/Second-level_domain), which immediately precedes the TLD (Top Level Domain), but the Third Level Domain if the website is a [Country Code Second-Level Domain](http://en.wikipedia.org/wiki/Country_code_second-level_domain). Shortest bytes wins (competition ends March the 5th)! [Answer] # Ruby, 15 characters Assuming input is stored in variable `s`. ``` s.split(?.)[-2] ``` # GolfScript, 7 Exact translation. ``` "."/-2= ``` # Ruby with edge cases, 28 Such as `http://example.com/foo.bar` ``` s.split(?/)[2].split(?.)[-2] ``` # GolfScript with edge cases, 13 ``` "/"/2="."/-2= ``` [Answer] # JavaScript, 27 bytes Assuming `a` is the variable and `c` is a 1 or 0, ``` i=a.split('.')[i.length-c]; ``` would work. `c` is set to 3 if the domain is a `ccsld` and set to 2 if the domain isn't a `ccsld`. `c` can also be edited to a larger number if the page has dots in it. [Answer] # C, 120 ``` char s[999],*p,*q,*r;main(){gets(s);for(q=p=strstr(s,"//")+2,*strstr(p,"/")=0;*p;p++)if(*p=='.')*p=0,r=q,q=p+1;puts(r);} ``` [Answer] The 2 "solutions' above fail, what if the website has the URL www.some1.name.ext/whatever.this/www/? The solution in JavaScript is: ``` var arr = myurl.split('/'); var domain = arr[2]; var arr2 = domain.split('.'); var name = arr2[arr2.length-2]; ``` or ``` name = myurl.split('/')[2].split('.')[myurl.split('/')[2].split('.').length-2]; ``` [Answer] # Python - 30 Python's not too good for these things. ``` a.split("/")[2].split(".")[-2] ``` Doesn't work for TLDs with more than one `.`. [Answer] # Python2 172, Python3 156 This one is long, but i think it fullfills all the requeriments of the question. ``` s = "http://examples.example.co.nz/abcdefg" #BEGIN_CODE import re,urllib2 l=re.findall("..",urllib2.urlopen("http://goo.gl/molpki").read()) m=re.search(r"(?:\w+\.)*(\w+)\.(\w+)\.(\w+)",s) g=m.groups() r=g[0]if g[2]in l else g[1] #END_CODE print(r) ``` `l` contains a list of all country codes from wikipedia `m` contains the last third, second and first level domains, dropping all the others `r` contains the result All could go in a line, but since `;` is the same as `\n` i leave it like this. EDIT: Tested with `www.some1.name.ext/whatever.this/www/?` and returns `name` so i guess it works. ### Python 3 version ``` import re,requests as u g=re.search(r"(?:\w+\.)*(\w+)"+"\.(\w+)"*2,s).groups() r=g[0]if g[2]in re.findall("..",u.get("http://goo.gl/molpki").text) else g[1] ``` Same as above, r contains result. ]
[Question] [ This is a **code-golf**, so keep your code small! The **objective** is to create a function that receives 3 arguments: * **Rows**(int): The max number of an item in each array; * **Cols**(int): The max number of dimensions (sub-arrays); * **Val**(\*): The starting value in each item; This function should return a **multidimensional array** with the proper size and with the items containing the value specified. It should be able to return any number of dimensions. ### Example: ``` var multiArray = createMultiArray(2, 4,'empty'); multiArray[0][0][0][0] === 'empty' //true multiArray[0][0][0][1] === 'empty' //true multiArray[0][0][0][2] === 'empty' //true multiArray[0][0][1][0] === 'empty' //true ... multiArray[2][2][2][2] === 'empty' //true ``` [Answer] ## GolfScript This is pretty trivial, so there's no need to over-complicate it: ``` {[1$({2$@(@A}{\;}if]*}:A; ``` [Online demo](http://golfscript.apphb.com/?c=e1sxJCh7MiRAKEBBfXtcO31pZl0qfTpBOwoKMiAzICdYJyBBIHA%3D) [Answer] ### GolfScript, 17 characters A non-recursive approach in GolfScript. ``` {\{\[.;]*}+@*}:A; ``` [Online demo](http://golfscript.apphb.com/?c=e1x7XFsuO10qfStAKn06QTsKCjMgMiAnWCcgQSBw&run=true) [Answer] ## JavaScript, 132 characters ``` function m(e,t,n){var r=0,i=[];var s=function(i){r++;for(var o=0;o<=e;o++){if(r==t)i[o]=n;else i[o]=s([])}r--;return i};return s(i)} ``` UnGolfed: ``` function multiArray(maxRows, maxCols, val){ var c = 0, farray = []; var recursive = function(array){ c++; for(var r = 0; r <= maxRows; r++){ if(c == maxCols) array[r] = val; else array[r] = recursive([]); } c--; return array; }; return recursive(farray); } ``` [Answer] ## Mathematica, 32 bytes ~~Within reach of GolfScript for once!~~ Scrap that, I didn't see Howard's answer. ``` f=ConstantArray[#3,#+0Range@#2]& ``` [Answer] ## APL, 19 bytes ``` {(¯1↑⍵)⍴⍨⊃(//)⌽2↑⍵} ``` Sample: ``` {(¯1↑⍵)⍴⍨⊃(//)⌽2↑⍵} 2 4 'empty' ┌─────┬─────┐ │empty│empty│ ├─────┼─────┤ │empty│empty│ └─────┴─────┘ ┌─────┬─────┐ │empty│empty│ ├─────┼─────┤ │empty│empty│ └─────┴─────┘ ┌─────┬─────┐ │empty│empty│ ├─────┼─────┤ │empty│empty│ └─────┴─────┘ ┌─────┬─────┐ │empty│empty│ ├─────┼─────┤ │empty│empty│ └─────┴─────┘ ``` [Answer] # [Python 3](https://docs.python.org/3/), 36 bytes ``` lambda a,b,x:eval("["*b+"x"+"]*a"*b) ``` [Try it online!](https://tio.run/nexus/python3#bc6xCoQwEATQ/r4ibGPUFI5YCX6JWmxQQVARkcP7@pyVCBnYYhmG4U1NFxZd/aBGnXdXPX51sdJK5nO5JJc@0/tPg5rGTLZ0lUvGdT9/SfrZj3k7rbZF/xwJEYVgTURNsE2wTbBNRJtgTjAnmBPMCeYEc4I58XKGPw "Python 3 – TIO Nexus") [Answer] # [J](http://jsoftware.com/), 8 bytes ``` $/@]$<@[ ``` [Try it online!](https://tio.run/nexus/j#@59ma6Wi7xCrYuMQ/T81OSNfQT01t6CkUl0hTcFEwYgrtSKzRMHgPwA "J – TIO Nexus") ]
[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 8 years ago. [Improve this question](/posts/55181/edit) ## Challenge Write a program to factor this set of 10 numbers: ``` 15683499351193564659087946928346254200387478295674004601169717908835380854917 24336606644769176324903078146386725856136578588745270315310278603961263491677 39755798612593330363515033768510977798534810965257249856505320177501370210341 45956007409701555500308213076326847244392474672803754232123628738514180025797 56750561765380426511927268981399041209973784855914649851851872005717216649851 64305356095578257847945249846113079683233332281480076038577811506478735772917 72232745851737657087578202276146803955517234009862217795158516719268257918161 80396068174823246821470041884501608488208032185938027007215075377038829809859 93898867938957957723894669598282066663807700699724611406694487559911505370789 99944277286356423266080003813695961952369626021807452112627990138859887645249 ``` Each of these: * Is a 77-digit number less than 2^256. * Is a semiprime (e.g., the product of exactly 2 primes). * Has something in common with at least one other number in the set. Thus, this challenge is not about general factoring of 256-bit semiprimes, but about factoring *these* semiprimes. It is a puzzle. There is a trick. The trick is fun. It is possible to factor each of these numbers with surprising efficiency. Therefore, the algorithm you choose will make a much bigger difference than the hardware you use. ## Rules 1. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer wins. 2. You may use any method of factoring. (But don't precompute the answers and just print them. You program should do actual work.) 3. You may use any programming language (or combination of languages), and any libraries they provide or you have installed. However, you probably won't need anything fancy. [Answer] # Pyth, 12 bytes ``` V.Q--iRN.Q1N ``` Try it here: [Demonstration](http://pyth.herokuapp.com/?code=V.Q--iRN.Q1N&input=15683499351193564659087946928346254200387478295674004601169717908835380854917%0A24336606644769176324903078146386725856136578588745270315310278603961263491677%0A39755798612593330363515033768510977798534810965257249856505320177501370210341%0A45956007409701555500308213076326847244392474672803754232123628738514180025797%0A56750561765380426511927268981399041209973784855914649851851872005717216649851%0A64305356095578257847945249846113079683233332281480076038577811506478735772917%0A72232745851737657087578202276146803955517234009862217795158516719268257918161%0A80396068174823246821470041884501608488208032185938027007215075377038829809859%0A93898867938957957723894669598282066663807700699724611406694487559911505370789%0A99944277286356423266080003813695961952369626021807452112627990138859887645249&debug=0) ### Explanation: ``` implicit: .Q is the list of the input numbers V.Q for N in .Q: iRN.Q compute the gcd of N with each number in .Q - 1 remove 1s - N remove the number N and print ``` [Answer] # Julia ``` f=l->(A=map(big,[gcd(l[i],l[j]) for i=1:length(l),j=1:length(l)]);A-=eye(A).*(l-1);for i=1:length(l) println(l[i]," = ",join(unique(A[i,:])," × "))end); ``` Running it: ``` julia> tic();f(l);toc() 15683499351193564659087946928346254200387478295674004601169717908835380854917 = 1 × 123830525223423718982054269884856893727 × 126652934104061135988638942588043498971 24336606644769176324903078146386725856136578588745270315310278603961263491677 = 123830525223423718982054269884856893727 × 1 × 196531562802139162910711939551924590851 39755798612593330363515033768510977798534810965257249856505320177501370210341 = 126652934104061135988638942588043498971 × 1 × 313895598975456800331958744266933545471 45956007409701555500308213076326847244392474672803754232123628738514180025797 = 1 × 196531562802139162910711939551924590851 × 233835251470362519313085185758275325847 56750561765380426511927268981399041209973784855914649851851872005717216649851 = 1 × 218051709768607497734800854124975705007 × 260261943488556401874345256435550440693 64305356095578257847945249846113079683233332281480076038577811506478735772917 = 1 × 218051709768607497734800854124975705007 × 294908745103709254641398276907437631131 72232745851737657087578202276146803955517234009862217795158516719268257918161 = 1 × 233835251470362519313085185758275325847 × 308904433345854212511531098349325333463 80396068174823246821470041884501608488208032185938027007215075377038829809859 = 1 × 260261943488556401874345256435550440693 × 308904433345854212511531098349325333463 93898867938957957723894669598282066663807700699724611406694487559911505370789 = 1 × 294908745103709254641398276907437631131 × 318399740590727338211743341325021840319 99944277286356423266080003813695961952369626021807452112627990138859887645249 = 1 × 313895598975456800331958744266933545471 × 318399740590727338211743341325021840319 elapsed time: 0.002534739 seconds ``` Note: Because of how Julia operates, you might want to run it twice - the first time you run it, the tic/toc will include the time required to "compile" it. The second time, it will have already compiled it. [Answer] # CJam, 32 bytes ``` q~]__ff{{_@\%}h}:|1-_m*_::*\er:p ``` Try it online: [permalink for Chrome](http://cjam.aditsu.net/#code=q~%5D__ff%7B%7B_%40%5C%25%7Dh%7D%3A%7C1-_m*_%3A%3A*%5Cer%3Ap&input=15683499351193564659087946928346254200387478295674004601169717908835380854917%0A24336606644769176324903078146386725856136578588745270315310278603961263491677%0A39755798612593330363515033768510977798534810965257249856505320177501370210341%0A45956007409701555500308213076326847244392474672803754232123628738514180025797%0A56750561765380426511927268981399041209973784855914649851851872005717216649851%0A64305356095578257847945249846113079683233332281480076038577811506478735772917%0A72232745851737657087578202276146803955517234009862217795158516719268257918161%0A80396068174823246821470041884501608488208032185938027007215075377038829809859%0A93898867938957957723894669598282066663807700699724611406694487559911505370789%0A99944277286356423266080003813695961952369626021807452112627990138859887645249) | [permalink for Firefox](http://cjam.aditsu.net/#code=q~%5D__ff%7B%7B_%40%5C%2525%7Dh%7D%3A%7C1-_m*_%3A%3A*%5Cer%3Ap&input=15683499351193564659087946928346254200387478295674004601169717908835380854917%0A24336606644769176324903078146386725856136578588745270315310278603961263491677%0A39755798612593330363515033768510977798534810965257249856505320177501370210341%0A45956007409701555500308213076326847244392474672803754232123628738514180025797%0A56750561765380426511927268981399041209973784855914649851851872005717216649851%0A64305356095578257847945249846113079683233332281480076038577811506478735772917%0A72232745851737657087578202276146803955517234009862217795158516719268257918161%0A80396068174823246821470041884501608488208032185938027007215075377038829809859%0A93898867938957957723894669598282066663807700699724611406694487559911505370789%0A99944277286356423266080003813695961952369626021807452112627990138859887645249) [Answer] ## CJam, 38 bytes ``` q~]_2m*{~{_@\%}h;}%_2$-&2m*f{_::*@#=p} ``` Try it [here](http://cjam.aditsu.net/#code=q~%5D_2m*%7B~%7B_%40%5C%25%7Dh%3B%7D%25_%7Bs%2C50%3C%7D%2C%262m*f%7B_%3A%3A*%40%23%3Dp%7D&input=15683499351193564659087946928346254200387478295674004601169717908835380854917%0A24336606644769176324903078146386725856136578588745270315310278603961263491677%0A39755798612593330363515033768510977798534810965257249856505320177501370210341%0A45956007409701555500308213076326847244392474672803754232123628738514180025797%0A56750561765380426511927268981399041209973784855914649851851872005717216649851%0A64305356095578257847945249846113079683233332281480076038577811506478735772917%0A72232745851737657087578202276146803955517234009862217795158516719268257918161%0A80396068174823246821470041884501608488208032185938027007215075377038829809859%0A93898867938957957723894669598282066663807700699724611406694487559911505370789%0A99944277286356423266080003813695961952369626021807452112627990138859887645249). This answer is shorter than any of the factors in the output. [Answer] ## J, 2 bytes This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") now, so I assume efficiency doesn't actually matter, which means: ``` q: ``` (J's "factor prime" function) will return the right answer (in the form of a neatly formatted `2x10` array!) if you pass it an array of bignums give it a couple of hours/days to factor the semiprimes. [Answer] # Pyth, 15 13 12 bytes ``` jbmS{iLd.Q.Q ``` Expects the list of primes seperated by newlines on stdin. Outputs in the following format: ``` [1, 123830525223423718982054269884856893727, 126652934104061135988638942588043498971, 15683499351193564659087946928346254200387478295674004601169717908835380854917] [1, 123830525223423718982054269884856893727, 196531562802139162910711939551924590851, 24336606644769176324903078146386725856136578588745270315310278603961263491677] [1, 126652934104061135988638942588043498971, 313895598975456800331958744266933545471, 39755798612593330363515033768510977798534810965257249856505320177501370210341] [1, 196531562802139162910711939551924590851, 233835251470362519313085185758275325847, 45956007409701555500308213076326847244392474672803754232123628738514180025797] [1, 218051709768607497734800854124975705007, 260261943488556401874345256435550440693, 56750561765380426511927268981399041209973784855914649851851872005717216649851] [1, 218051709768607497734800854124975705007, 294908745103709254641398276907437631131, 64305356095578257847945249846113079683233332281480076038577811506478735772917] [1, 233835251470362519313085185758275325847, 308904433345854212511531098349325333463, 72232745851737657087578202276146803955517234009862217795158516719268257918161] [1, 260261943488556401874345256435550440693, 308904433345854212511531098349325333463, 80396068174823246821470041884501608488208032185938027007215075377038829809859] [1, 294908745103709254641398276907437631131, 318399740590727338211743341325021840319, 93898867938957957723894669598282066663807700699724611406694487559911505370789] [1, 313895598975456800331958744266933545471, 318399740590727338211743341325021840319, 99944277286356423266080003813695961952369626021807452112627990138859887645249] ``` [Answer] # Pyth, 4 bytes Since we don't have to abuse the common divisors we can simply use the factorization function and map it to the input: ``` PM.Q ``` Yay loopholes! ]
[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/160781/edit). Closed 5 years ago. [Improve this question](/posts/160781/edit) # Introduction For as long as programmers have been programming and as long as English teachers have been teaching, there's a controversy over the datasets called *Arrays* and *Lists* (or hashes). Arrays have almost always had their first index at 0. Which, for the programmer, is understandable because of math. But along the way, as more and more languages have appeared, and more and more people start to program, they can't wrap their mind around the array. They know it's a table of indexes with values assigned to each index, but they don't know why it starts at 0, because 0 typically means nothing. 0 is a quantitative value that we don't see (or can, but mostly in context). # Task It's simple: **Make your arrays/list/hashes/whatever start at one** This doesn't require special tinkering to the compiler/interpreter. Make a user's array have their expected values at position 1. Loopholes aren't allowed. # Examples A basic example (written in Pseudo): ``` list = [1,2,3] lis = [null] value = 1 Loop list Through 3 Times as Index_Value lis[value] = Index_Value value += 1 print(lis) // or return lis, doesn't matter ``` # Rules 1. No [standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) allowed 2. Languages that have arrays/lists/hashes that start at one OR are configurable to have settable index numbers. 3. Input will be given, you may expect a array. However, if the array requires certain types, assume the array is filled with integers. Basically, test for [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (I do encourage any answers that aren't for competition) 4. Output must be the fixed array. If the fixed array is assigned to value `a`, then `a[1] == 1` 5. Anything can be in the `a[0]` index, the user will not care. Though, preferably, **BUT NOT REQUIRED**, the value should be `null` or some other comparable value. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins. [Answer] # [Haskell](https://www.haskell.org/), 4 bytes ``` (0:) ``` [Try it online!](https://tio.run/##y0gszk7NyfmfZhvzX8PASvN/bmJmnoKtQkFRZl6JgopCmkK0oY6CkY6Ccez/f8lpOYnpxf91kwsKAA "Haskell – Try It Online") Just prepends 0. ``` data List a = Cons a (List a) | Emp deriving (Eq) instance Show a => Show (List a) where show Emp = "[]" show (Cons x Emp) = "[" ++ show x ++ "]" show (Cons x xs) = "[" ++ show x ++ ", " ++ tail (show xs) len :: Integral b => List a -> b len Emp = 0 len (Cons x xs) = succ $ len xs pre :: a -> List a -> List a pre = Cons app :: a -> List a -> List a app x Emp = pre x Emp app x (Cons y ys) = pre y $ app x ys (!) :: Integral b => List a -> b -> a Emp ! i = error "index too large" (Cons x xs) ! 1 = x (Cons x xs) ! i = xs ! (pred i) ``` [Try it online!](https://tio.run/##jVE9T8MwEN39K16iDokKEgjEUCldUAckNkbE4CZWauHawTbUkfjvwR8RTSiVekN8ee/d3Tt7R807E2IYGmopnrmxoKjwqKTxSZGAEt/Y7DsCHw3T/IvLFsXmoySES2OprBleduoQStcp@6087JhmsdIE3LfBJCrkr2/5kS7iYBdk5UjnWC4T6UKW/yd3psQZ@RUiYikXKBJuvG/BJGaxWuFJWtZqKrANa4x3cb3GNqrnzivcRHTuoIL5rGssEChnCOk0OxkTex67p@xUOb4CIbTrLuwRlG5mtELoG7GRTYZ79N5wYnvvN3G9n1Zk5eUXEz6UhIEZ@Mw601pp5Fw2zMEqBUF1y3Iyva8Mt1Hr/qA8ocanhTfYgJfDnnLpwUbFxxfMQgQbaYM7v0E478fzIe4blZ3mMmknv4tU7OcPPw "Haskell – Try It Online") [Answer] # C Macro, 17 bytes ``` #define F(t)(t-1) ``` [Answer] ## Inform 7, 97 bytes This challenge seems like one that Inform 7 could actually accomplish, despite its enormous verbosity! ``` To decide what list of numbers is f (L - a list of numbers): add 0 at entry 1 in L; decide on L. ``` Prepends a zero. [Answer] # [Java (OpenJDK 8)](http://openjdk.java.net/), 67 bytes ``` a->{int c[]=new int[a.length+1],i=1;for(int u:a)c[i++]=u;return c;} ``` [Try it online!](https://tio.run/##jY9NboMwEIX3nGKWWDhWHZL@WVTqAZpNlsiLqeOkpmCQsVNFiLNTU9pl1KxmNPPme28qPOOq7bStDp@TabrWeajijAVvavbqHF56kaga@x7e0NghATDWa3dEpWE3xL6U4NKlIhFjFPQevVGwAwsFTLh6mWWgSllY/TWfl8hqbU/@I@OSmoKLY/uDgPCMRJUmy2QRhNM@OAtKjJOI1C6815H6Cz@35gBNTJTuvTP2VEokcziA/aX3umFt8KyLG1/bdPmD@XbRppa59C@KHDhd05xu6Jbe0wf6SJ8ovxsJIeIa7vrmFqNttOA5XXOab/63GZNx@gY "Java (OpenJDK 8) – Try It Online") This was a fun little challenge in Java since Java arrays are static in size, but it seems like this is significantly less challenging in every language that can just slap a zero on for the first- excuse me, *zeroth* element **Explanation:** ``` int i=1,c[]=new int[a.length+i]; ////Initialize counter and declare new array with length: 1 + input array length for(int u:a) //Loop through each element in input array c[i++]=u; //Increment counter after shifting each element up one spot in the output array return c; //return new array starting at index 1 ``` **Credit:** -3 bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)! [Answer] ## Python 3, 14 bytes ``` lambda s:[0]+s ``` Puts a zero at the start of the list. `None` would be a better null value but it's three bytes longer. [Answer] # JavaScript, 10 bytes ``` a=>[,...a] ``` a[0] is a *hole* after fix [Answer] # [Perl 5](https://www.perl.org/) `-p`, 6 bytes ``` #!/usr/bin/perl -p s//0 / ``` [Try it online!](https://tio.run/##K0gtyjH9/79YX99AQf//f0MFIwXjf/kFJZn5ecX/dQsA "Perl 5 – Try It Online") Prepends 0 The controversy mostly exist because people confuse counting and naming :-) ]
[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/121796/edit). Closed 6 years ago. [Improve this question](/posts/121796/edit) # Task When running the program must show the season according to the host computer's current time. # Rules * The output must be either: Spring, Winter, Summer or Autumn. * The capitalization does not matter. * The output must not contain anything else the the season names stated above. * A season is 3 months and january is in this case the start of spring. (Northern hemisphere) # Testcase (program ran in January) Output: ``` Spring ``` (program ran in April) Output: ``` Summer ``` # Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer in bytes wins. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 40 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` “¡ɗNʂ:ḲO¶Z{ṅ{Ḳ®⁵⁹¢»ŒV’:3ị“ȷ14ċ⁵¶<b_þṭ»Ḳ¤ ``` Jelly has **no native date functionality**, yet this program prints `Spring` in January, February and March; `Summer` in April, May and June; `Autumn` in July, August, and September; and `Winter` in October, November and December. **[Try it online!](https://tio.run/nexus/jelly#@/@oYc6hhSen@51qsnq4Y5P/oW1R1Q93tlYD2YfWPWrc@qhx56FFh3YfnRT2qGGmlfHD3d1ADSe2G5oc6QbKHtpmkxR/eN/DnWsP7QbpWPL//38uBQA)** ### How? ``` “¡ɗNʂ:ḲO¶Z{ṅ{Ḳ®⁵⁹¢»ŒV’:3ị“ȷ14ċ⁵¶<b_þṭ»Ḳ¤ - Main link: no arguments “¡ɗNʂ:ḲO¶Z{ṅ{Ḳ®⁵⁹¢» - compressed string: " time.gmtime().tm_mon" ŒV - evaluate Python code - gets the month, January=1 ... December=12 (the time module has been imported in the interpreter for the time formatting atom ŒT) ’ - decrement :3 - integer divide by three ¤ - nilad followed by link(s) as a nilad: “ȷ14ċ⁵¶<b_þṭ» - compressed string "Summer Autumn Winter Spring" Ḳ - split on spaces ị - index into (1-based) - implicit print ``` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), ~~25~~ 16 bytes ``` “Ž¹Ž€È±–„“#žf3÷è ``` Explanation: ``` “Ž¹Ž€È±–„“ Push the string 'spring summer autumn winter' # Split on spaces žf Push month 3÷ Integer divided by 3 è Index ``` [Try it online!](https://tio.run/##ASwA0/8wNWFiMWX//@KAnMW9wrnFveKCrMOIwrHigJPigJ7igJwjxb5mM8O3w6j//w "05AB1E – Try It Online") [Answer] # [Japt](https://github.com/ETHproductions/japt), ~~32~~ ~~30~~ 27 bytes ``` `spÎAdä>H©umØC`qd gKg z3 ``` [Try it online](https://ethproductions.github.io/japt/?v=1.4.5&code=YHNwzkFk5D5IH6l1bZjYQ4BgcWQgZ0tnIHoz&input=) --- ## Explanation A compressed string of lowercase, separated season names delimited with `d` is decompressed by enclosing it in backticks. `qd` splits the string into an array on `d`s. The `g` method gets the element at the index of the current month (`Kg`) floor divided by 3 (`z3`). ]
[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/86778/edit). Closed 7 years ago. [Improve this question](/posts/86778/edit) # Number to String ## Instructions Convert a signed 32-bit integer to a string (base-10 preferably) without any string formatting calls (or built in type coercion that will directly convert a number to a string). Negative numbers must include leading `-`. ## Score Calculation Shortest byte length; Tie breaker by efficiency (execution time) [Answer] # JavaScript ES6, ~~61~~ ~~57~~ ~~46~~ ~~45~~ 42 bytes Apparently this is what you want. Apparently Leaky Nun saved me 17 bytes. Output in binary: ``` f=n=>n<0?"-"+f(-n):n?f(n>>1)+"01"[n%2]:"0" ``` Output in decimal: ``` f=n=>n<0?"-"+f(-n):n<10?"0123456789"[n]:f(n/10|0)+f(n%10) ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), ~~14~~ 12 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` ~~”-“”<?0³AD+48Ọ~~ <0”-x³AD+48Ọ ``` [Try it online!](http://jelly.tryitonline.net/#code=PDDigJ0teMKzQUQrNDjhu4w&input=&args=LTEyMw) ]
[Question] [ **This question already has answers here**: [Simple cat program](/questions/62230/simple-cat-program) (330 answers) Closed 5 years ago. # Challenge Your challenge is to make a simple program that takes the [input] and formats it as "Hello, [input]!" ## Input Either a function call variable or STDIN, this is the name. Can contain any character, UTF-8, and can be empty - would result in `Hello,!`. Also newlines in the input are fine - ``` On a new line -> Hello, On a new line! ``` **Why? Because the challenge is not about if the message makes sense or not, it's about 'how quickly can you *format*?'.** ## Output Hello, ! # Example Here would be a program in CJam: ``` "Hello, %s!"qae% lolad -> Hello, lolad! John Smith -> Hello, John Smith! this is a new line -> Hello, this is a new line! <null> -> Hello, ! ``` # Winner The winner is the answer with the shortest bytes, as always. [Answer] ## [Retina](https://github.com/m-ender/retina/wiki/The-Language), 13 bytes ``` '!>`^ Hello, ``` [Try it online!](https://tio.run/##K0otycxLNPz/X13RLiGOyyM1JydfR@H//5TEouy81OJiHYXcSoX8nBSFtKLM1LwUAA "Retina – Try It Online") ### Explanation ``` ^ Hello, ``` This part prepends the `Hello,` (and a space) to the input. Then `>` lets us configure the implicit output of the program and with `'!` we can append the exclamation mark to the output (basically a generalisation of printing with a trailing linefeed). [Answer] # [pl](https://github.com/quartata/pl-lang), 9 bytes ``` Hello, _! ``` [Try it online!](https://tio.run/##K8j5/98jNScnX0chXvH/f5fUvLzMYgA "pl – Try It Online") [Answer] # Java 8, 18 bytes ``` s->"Hello, "+s+"!" ``` [Try it online.](https://tio.run/##hY3NCsIwEITvfYoxpxa1LyB6FkEvPaqHNY02mm6kWRWRPnuNkqsIs7A/3@yc6U7Tc30ZtKMQsCbLrwywLKY7kjbYfEagks7yCTpPTShmcd/HigpCYjU2YMwxhOlCLY1zfgI1DmM1UsMsi9T1dnCRSvDd2xptjEsft3tQkbKeQUxb@puU13gSxzmXOlfOO6pV8U3@Ta18w6haK81fVBobEEU7ZvOAs2z@ehLQZ/3wBg) [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), ~~8~~ 7 bytes ``` ”Ÿ™, ÿ! ``` [Try it online!](https://tio.run/##MzBNTDJM/f//UcPcozsetSzSUTi8X/H///LEEgA "05AB1E – Try It Online") [Answer] # [Perl 5](https://www.perl.org/), 19 bytes ``` say"Hello, ",<>,"!" ``` [Try it online!](https://tio.run/##K0gtyjH9/784sVLJIzUnJ19HQUnHxk5HSVHp//@c/JzElH/5BSWZ@XnF/3V9TfUMDfQMAA "Perl 5 – Try It Online") [Answer] # [Elixir](https://elixir-lang.org/), 23 bytes ``` fn a->"Hello, #{a}!"end ``` [Try it online!](https://tio.run/##S83JrMgs@u/pr1dQWlKsofE/LU8hUddOySM1JydfR0G5OrFWUSk1L@W/pp4GUFFRamKKglViTo6m5v@k/KS0cq7E8tS08lQA "Elixir – Try It Online") # [Elixir](https://elixir-lang.org/), 32 bytes ``` IO.puts"Hello, #{IO.read :all}!" ``` [Try it online!](https://tio.run/##S83JrMgs@v/f01@voLSkWMkjNScnX0dBuRooUJSamKJglZiTU6uo9P9/IhdXEgA "Elixir – Try It Online") [Answer] # [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 21 bytes ``` x:"Hello, " +? +"!" O ``` [Try it online!](https://tio.run/##S0xJKSj4/7/CSskjNScnX0dBiUvbnktbSVGJy/////8lGZnFChmJxVx5qeU5mXmpxVyZeQqZJQA "Add++ – Try It Online") [Answer] # Japt, 12 bytes Couldn't think of a simpler solution. ``` "Hello, {N}! ``` [Try it online!](https://ethproductions.github.io/japt/?v=1.4.5&code=IkhlbGxvLCB7Tn0h&input=dGVzdA==) [Answer] # [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 21 bytes ``` {print"Hello, "$0"!"} ``` [Try it online!](https://tio.run/##SyzP/v@/uqAoM69EySM1JydfR0FJxUBJUan2//@0/HwA "AWK – Try It Online") [Answer] # [sed](https://www.gnu.org/software/sed/), 15 bytes ``` s/.*/Hello, &!/ ``` [Try it online!](https://tio.run/##K05N0U3PK/3/v1hfT0vfIzUnJ19HQU1R////tPx8AA "sed – Try It Online") [Answer] # [ReRegex](https://github.com/TehFlaminTaco/ReRegex), 17 bytes Trivial and probably as short as it can get. ``` Hello, (?#input)! ``` [Try it online!](https://tio.run/##K0otSk1Prfj/3yM1JydfR0HDXjkzr6C0RFPx//@S8nyuvNRyrpzMvNRiAA "ReRegex – Try It Online") [Answer] # JavaScript, 17 bytes ``` s=>`Hello, ${s}!` ``` [Answer] # [4](https://github.com/urielieli/py-four), 111 bytes ``` 3.6009960199602996207252062002020200052062009020200152052062012020200252062044520620325207218215217219620335204 ``` [Try it online!](https://tio.run/##LYzLDYAwDEPvTMEEyPnQ0iG4MAI3Lq1E91dISRPJzrOsqJlsCSglgYawCyPzznAH/wtMLIHkGAnNwuyrhsvgzHSwV8mP8VTEQzU7374ta8zV7qf2Vj8 "4 – Try It Online") Nothing too special going on here. This is just a glorified cat program. [Answer] # [Ruby](https://www.ruby-lang.org/), 33 bytes A lambda, accepting a string and returning a string: ``` ->s{"Hello,#{s.size>0?' '+s:s}!"} ``` [Try it online!](https://tio.run/##TYy9DoIwFEb3PsWlDgxW4mwCjrj5ALWD0EskaQrpTyICz14bJOB4zznfNb4aQpOHU2FHekOlOnYYbWbbDxbnawrp0V7snNA5cALAKWWwZgkVbEFD53cK8dpMaRD1Q99N9RfsMHZEZPisXyA7mFrde8cA3z3WDuUUXxi0XjnIoeGLFZH1wNfyZ9lW5dtWENQyfAE "Ruby – Try It Online") # [Ruby](https://www.ruby-lang.org/) + `-p`, 16 bytes (not fully compliant) A full program, which does not support empty inputs (prints nothing) or inputs containing newlines (treats each line as a separate input): ``` $_="Hello, #$_!" ``` [Try it online!](https://tio.run/##KypNqvz/XyXeVskjNScnX0dBWSVeUen/f/ei1NQ8Bf@ipH/5BSWZ@XnF/3ULAA "Ruby – Try It Online") The fun trick here: when string interpolation is done on a variable name starting with `$`, the curly braces can be dropped from the normal `#{}` wrapper. [Answer] # [Haskell](https://www.haskell.org/), 21 bytes ``` ("Hello, "++).(++"!") ``` [Try it online!](https://tio.run/##y0gszk7NyfmfZhvzX0PJA8jM11FQ0tbW1NPQ1lZSVNL8n5uYmadgq1BQWhJcUuSTp6CikKagVJ5flJOi9P9fclpOYnrxf93kggIA "Haskell – Try It Online") [Answer] # [V](https://github.com/DJMcMayhem/V) / vim, 11 bytes ``` iHello, <esc>A! ``` `<esc>` is a literal escape character [Try it online! (V)](https://tio.run/##K/v/P9MjNScnX0fBJrU42c5R8f//8vyinJT/umUA "V – Try It Online") ]
[Question] [ You will take a set of input numbers, and output the minimum and maximum of the set. You can either write two programs, with 1 program doing each function, or one combined program. Here's an example in Perl, 50 and 42 bytes (92 total): Max: ``` sub mx {return ( reverse sort {$a <=> $b} @_ )[0]} ``` Min: ``` sub mn {return ( sort {$a <=> $b} @_ )[0]} ``` And a single program, 96: ``` sub mxmn {return ( reverse sort {$a <=> $b} @_ )[0] if shift; return ( sort {$a <=> $b} @_ )[0]} ``` [Here's some more test cases.](http://pastebin.com/sJ6DjjAK) ## Leaderboard Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language. ``` /* Configuration */ var QUESTION_ID = 4310; // Obtain this from the url // It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author. /* App */ var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; if (/<a/.test(lang)) lang = jQuery(lang).text(); languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang > b.lang) return 1; if (a.lang < b.lang) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } } ``` ``` body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } 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] Perl does have `min` and `max` subs. ``` use List::Util qw( min max ); my $min = min @values; my $max = max @values; ``` A common module has a `minmax` function which finds both at once faster than they can be found individually (which is far more important than compactness of code). ``` use List::MoreUtils qw( minmax ); my ($min, $max) = minmax @values; ``` [Answer] If it doesn't have to be Perl and you just want the simplicity of Scheme instead of just shaving off characters (I don't care about long variable names (symbols in Scheme)), here's my Scheme for this (pun intended): Of course we could cheat and use the fonctions (min a b c d ...) and (max a b c ...). Don't mind the long variable names, they were chosen to be descriptive: ``` (define (min . args) (extremum < args)) (define (max . args) (extremum > args)) (define-syntax extremum   (syntax-rules ()     [(_ op . args)      (if (null? args) (error "Read The Fucking Code!")          (reduce (lambda (a b) (if (op a b) a b))            (car rest) (cdr rest)))]     [else (error "Read The Fucking Code!")])) ``` But if you want less code (fold is sort of like reduce): ``` (define (min . args) (e < args)) (define (max . args) (e > args)) (define-syntax e   (syntax-rules ()     [(_ o . r) (fold (lambda (a b) (if (o a b) a b)) (car r) (cdr r))])) ``` [Answer] If all numbers are non-negative, this works: ``` sub max{\@s[@_];$#s} ``` [Answer] # [Japt](https://github.com/ETHproductions/japt) `-g`, 1 byte Min ``` n ``` [Try it online!](https://tio.run/##y0osKPn/P@///2hTHXMdSx1DHTMdEyBtoWOqYxiroJsOAA "Japt – Try It Online") --- # [Japt](https://github.com/ETHproductions/japt) `-g`, 2 bytes Max ``` n< ``` [Try it online!](https://tio.run/##y0osKPn/P8/m//9oUx1zHUsdQx0zHRMgbaFjqmMYq6CbDgA "Japt – Try It Online") --- # Total: 3 bytes [Answer] Both programs pretty much just evaluate the input & sort it. Min takes the first item of the sorted list, and Max takes the last item of the sorted list. # [GolfScript](http://www.golfscript.com/golfscript/), 4 bytes Min ``` ~$0= ``` [Try it online!](https://tio.run/##S8/PSStOLsosKPn/v07FwPb//2hTBXMFSwVDBTMFEyBtoWCqYBgLAA "GolfScript – Try It Online") # [GolfScript](http://www.golfscript.com/golfscript/), 5 bytes Max ``` ~$-1= ``` [Try it online!](https://tio.run/##S8/PSStOLsosKPn/v05F19D2//9oUwVzBUsFQwUzBRMgbaFgqmAYCwA "GolfScript – Try It Online") ## Total: 9 bytes [Answer] ## Perl, 28 char This sub provides an array that contains the min in the first member and the max in the second member: ``` sub a{@_=sort@_;(shift,pop)} ``` ## Perl, 34 char (27 inside the sub) According to comments, in fact the above doesn't work for array length less than 2, here a new attempt that works even for zero length array and array that contains only numerics: ``` sub a{@_&&(sort{$a<=>$b}@_)[0,-1]} ``` [Answer] I don't think Perl is very golfy for such a problem. Here are two alternatives for *numerical lists only*: --- **20 chars (inside sub)** ``` sub min{(sort{$a<=>$b}@_)[0]} sub max{(sort{$b<=>$a}@_)[0]} ``` --- **30 chars (inside sub)** ``` sub min{$r=pop;$r=$_<$r?$_:$r for@_;$r} sub max{$r=pop;$r=$_>$r?$_:$r for@_;$r} ``` [Answer] # Io, 28 + 28 = 56 I found the magical pure-arithmetic max/min functions! (You guys definitely have a better formula than be, so feel free to mention a better one!) # [Io](http://iolanguage.org/), 28 bytes The max function; ``` method(x,y,(x+y+(x-y)abs)/2) ``` [Try it online!](https://tio.run/##y8z/n5tYoWBlqxDzPze1JCM/RaNCp1JHo0K7UlujQrdSMzGpWFPfSBOkSsNQx0hToaAoM68kJ@8/AA "Io – Try It Online") # [Io](http://iolanguage.org/), 28 bytes Min function ``` method(x,y,(x+y-(x-y)abs)/2) ``` [Try it online!](https://tio.run/##y8z/n5tYoWBlqxDzPze1JCM/RaNCp1JHo0K7UlejQrdSMzGpWFPfSBOkSsNQx0hToaAoM68kJ@8/AA "Io – Try It Online") ## Explanation for both programs In order to find a purely-arithmetic max-min function, I started to think of averages. Let's take 3 and 4 as examples. ``` (3+4)/2 = 3.5 ``` We can see that the distance towards both sides are equal: ``` 3 - 3.5 = -0.5 4 - 3.5 = 0.5 ``` We do the difference and take the absolute value, to get the distance that we need to add / subtract towards the average. `0.5` in this case. Then, we find the average again. If we're finding the max, we add it by the distance, otherwise we subtract the value by the distance: ``` 3.5 + 0.5 = 4 3.5 - 0.5 = 3 ``` Our current expression is: ``` x + y | x - y | ----- ± | ----- - x | 2 | 2 | ``` Actually, the rightmost x can also be y, but we chose x for the simplicity of simplification. ``` x + y | x - y 2x | ----- ± | ----- - --- | 2 | 2 2 | = x + y | x - y - 2x | ----- ± | ---------- | 2 | 2 | = x + y | x - y | ----- ± --------- 2 2 And then, the formula becomes the current formula: x + y ± | x - y | ----------------- 2 ``` ``` ]
[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/206711/edit). Closed 3 years ago. [Improve this question](/posts/206711/edit) # Challenge In this challenge, the input will be an ordered set of numbers and the program should be able to tell if the set of numbers is an [Arithmetic Sequence](https://www.mathsisfun.com/algebra/sequences-sums-arithmetic.html). # Input * The input will be a list separated by `,`(comma) or `,` (comma+space). The minimum length of the list should be 3 elements. # Output * The Output can be a Boolean (True or False), or a number (1 for True, 0 for False). # Test cases ``` In: 1, 3, 5 Out: True In: 1,4, 7 Out: 1 In: 5, 9,10 Out: 0 In: 5,3,1 Out: False ``` # Rules * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code by bytes wins. * The input will be finite Best of Luck [Answer] # [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 5 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py) ``` ê│▀£┴ ``` Input `,`-delimited; outputs `1`/`0` for truthy/falsey respectively. [Try it online.](https://tio.run/##y00syUjPz0n7///wqkdTmh5Nazi0@NGULf//G@qY6JjrGBroGBrrGJpxGeoY65gCBSy5gEJGBjrGBjomBiC2hY4ZUKWRDpADJE2AfEMzHWMjHTMTLgOwAFAKAA) (MathGolf is able to execute multiple test cases at once for each line of STDIN input, but feel free to only use a single input if you'd like.) **Explanation:** ``` ê # Read the comma-delimited input-string as integer-list │ # Get the forward differences of each overlapping pair in this list ▀ # Uniquify these differences £ # Pop and push the length to get the amount of unique differences ┴ # Check that this length is equal to 1 (1 if 1; 0 if >= 2) # (after which the entire stack joined together is output implicitly as result) ``` [Answer] # [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 47 bytes ``` \d+ $* A`(1+),(?!\1) (?<=(1+),)\1 ^1*(,1*)\1*$ ``` [Try it online!](https://tio.run/##K0otycxL/P8/JkWbS0WLyzFBw1BbU0fDXjHGUJNLw97GFszXjDHk4ooz1NLQMdQCsrVU/v831DHRMdcxNNAxNNYxNAMA "Retina 0.8.2 – Try It Online") Only works on nondescending sequences of at least two integers. Explanation: ``` \d+ $* ``` Convert to unary. ``` A`(1+),(?!\1) ``` Check that the sequence is ascending. ``` (?<=(1+),)\1 ``` Compute the differences after the first value. ``` ^1*(,1*)\1*$ ``` Check that all of the differences are equal. [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 8 [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")) ``` 1=≢∪2-/⎕ ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKO94L@h7aPORY86Vhnp6j/qmwoS@68ABgVchjpGOsY6JjqmXHARAx0jAx1jAx0TAx1TA4SwDhRyoWoFauZCN8wYAA "APL (Dyalog Unicode) – Try It Online") `1=` Is 1 equal to `≢` the count of `∪` unique `2-/` pairwise differences `⎕` in the evaluated input? The `⎕` prompts for input and executes it. Luckily, `,` is APL's concatenation functions, so the required input format evaluates to a list. Spaces are ignored. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 5 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` ',¡¥Ë ``` Input `,`-delimited; outputs `1`/`0` for truthy/falsey respectively. [Try it online](https://tio.run/##yy9OTMpM/f9fXefQwkNLD3f//2@oY6JjrmNooGNorGNoBgA) or [verify a few more test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3lf3WdQwsPLT3c/V/nv6GOiY65jqGBjqGxjqEZl6GOsY4pUMCSCyhkZKBjbKBjYgBiW@iYAVUa6QA5QNIEyDc00zE20jEz4TIACwClAA). **Explanation:** ``` ',¡ '# Split the (implicit) input-string on "," ¥ # Get the deltas (forward differences) of each overlapping pair in this list Ë # Check if all differences are equal (1 if truthy; 0 if falsey) # (after which this result is output implicitly) ``` Of course, this would have been **2 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)** with default I/O rules by taking a list input: `¥Ë`. ]
[Question] [ <https://www.youtube.com/watch?v=6vAhPeqlODg> Ok—jig's up—this one's only related to smash in name, but it'll give you something to burn your time with while you wait 'til December 7th Given a color string `s` of form `#rgb`(in hex, so #000000 to #ffffff, dont worry about the three digit ones: ~~#123~~) you must average the rgb values, and turn it into a **flame** color(heyy see what I did there?) to turn an average hex number `n`(0-255) to a "flame color" you must return a string `#rgb`with: `r = n` `g = n - 144`(the 144 is decimal, hex is 0x90) or if `n - 144` is <0, then g = 0 `b = 0` Given this is smash, we have to have items off. So no using arrays, maps, or sets(don't get into semantics about how strings are just abstracted arrays, I don't want to hear it) 1. [Standard Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are prohibited 2. Acceptable answers: a function which takes input through one input string and returns one output string 3. If the input string doesn't match the requirements provided above, your code MUST error out(doesn't matter what kind of Exception or Error) 4. This is code-golf, so the shortest(valid)answer (in each language) wins! 5. Bonus points for a one-liner 😎 (Not really tho, just cool points) [Answer] # [Perl 6](https://github.com/nxadm/rakudo-pkg), 108 bytes ``` {[$!=S/^\#(<[\d|A..F]>**2)**3$/{"#"~[~] ((sum("0x"X~$0)/3 X-0,144,255)Xmax 0)>>.fmt("%02x")}/,1/0][$! eq$_]} ``` [Try it online!](https://tio.run/##Xc3PCoIwAIDxe0@x5optmJvzT0UprEMv0EXQFUJKhwaVRorpqy8vQXT8fpfvVjyuodEtmJcgAqZL0TQ6sGNm4W2and/ScfYqplQQSj3EOmjBIR0UwLh6agx5A5MBccI8kCy47fq@LYKAJDpvACdx7JS6xnDGRQNJz2yXcTUOQHFHJ9WbKm9BiaHFXeH5ASSbyVfC5Wotd78i5Z@8Lnk9pvkA "Perl 6 – Try It Online") Anonymous code block that takes a string and returns a string if it is in a valid format, or a div by zero error otherwise. Though I'm not really sure how you're defining `arrays`,`maps` or `sets`, since my code uses sequences (`Seq`) and `Match`s... [Answer] # [Red](http://www.red-lang.org), 96 bytes ``` func[s][c: hex-to-rgb do s n: c/1 + c/2 + c/3 / 3 to-hex/size n * 65536 +(256 * max 0 n - 144)6] ``` ## Note: It doesn't work in TIO (doesn't recognize `hex-to-rgb`- maybe it is not implemented for Linux yet). ## Tests within the Red console: (first 3 taken from Jo King - thanks!): ``` >> print f "#012345" #230000 >> print f "#6789AB" #890000 >> print f "#AA89AB" #9F0F00 >> print f "code golf" *** Script Error: code has no value *** Where: do *** Stack: f hex-to-rgb ``` ]
[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/7131/edit) Alice is a kindergarden teacher. She wants to give some candies to the children in her class. All the children sit in a line and each of them has a rating score according to his or her usual performance. Alice wants to give at least 1 candy for each child.Children get jealous of their immediate neighbors, so if two children sit next to each other then the one with the higher rating must get more candies. Alice wants to save money, so she wants to minimize the total number of candies. Input ``` The first line of the input is an integer N, the number of children in Alice's class. Each of the following N lines contains an integer indicates the rating of each child. ``` Ouput ``` Output a single line containing the minimum number of candies Alice must give. ``` Sample Input ``` 3 1 2 2 ``` Sample Ouput ``` 4 ``` Explanation ``` The number of candies Alice must give are 1, 2 and 1. ``` Constraints: ``` N and the rating of each child are no larger than 10^5. ``` **Language Restrictions:** **C++/Java/C#** [Answer] ## Java ``` import java.io.*; class Alice { public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(r.readLine()); int[] ratings = new int[n]; for (int i = 0; i < n; i++) ratings[i] = Integer.parseInt(r.readLine()); System.out.println(minCandies(ratings)); } private static int minCandies(int[] ratings) { int n = ratings.length; int[] reverseRatings = new int[n]; for (int i = 0; i < n; i++) reverseRatings[n-1-i] = ratings[i]; int[] forwardRun = findRunLengths(ratings); int[] reverseRun = findRunLengths(reverseRatings); int sum = 0; for (int i = 0; i < n; i++) sum += Math.max(forwardRun[i], reverseRun[n-1-i]); return sum; } private static int[] findRunLengths(int[] ratings) { int lastInRun = -1; int runLength = 0; int[] runs = new int[ratings.length]; for (int i = 0; i < ratings.length; i++) { int r = ratings[i]; if (r > lastInRun) { lastInRun = r; runLength++; } else { runLength = 1; lastInRun = r; } runs[i] = runLength; } return runs; } } ``` Uses the fact that a kid will need C candies iff there is a strictly increasing run of C ratings in either direction that ends at that kid. Just walks the array in each direction looking for runs and keeps the length of the run found ending at each kid. O(n) time. [Answer] # Clojure - 2495 ``` (ns alice) (defn invert-derivative [d] (cond (= d <=) >= :else <= )) (defn chunk-by-derivative [ivec] (loop [prev-seqs [] prev-els [(first ivec)] cur-derivative (if (<= (first ivec) (second ivec)) <= >=) remainder (rest ivec)] (let [cursor (first remainder) holds-trend (cur-derivative (last prev-els) (if (nil? cursor) 0 cursor))] (cond (empty? remainder) (conj prev-seqs prev-els) holds-trend (recur prev-seqs (conj prev-els cursor) cur-derivative (rest remainder)) :else (recur (conj prev-seqs prev-els) [cursor] (invert-derivative cur-derivative) (rest remainder)))))) (defn candy-delta [ivec] (reduce (fn [pr c] (let [{:keys [value candies] :as previous :or {:value 0 :candies 1}} (last pr)] (conj pr (cond (empty? pr) {:candies 1 :value c} (= value c) previous (> value c) {:value c :candies (inc candies)} (< value c) {:value c :candies (dec candies)})))) [] ivec)) (defn simple-min-candy [ivec] (let [m (apply min (map #(:candies %1) ivec))] (if (> 1 m) (map #(assoc %1 :candies (+ (:candies %1) (- 1 m))) ivec) ivec))) (defn subseq-concat [s1 s2] (let [s1-l-candies (:candies (last s1)) s1-l-value (:value (last s1)) s2-f-candies (:candies (first s2)) s2-f-value (:value (first s2))] (cond (and (> s1-l-value s2-f-value) (< s1-l-candies s2-f-candies)) (recur (let [delta (- s2-f-candies s1-l-candies)] (map #(assoc %1 :candies (+ delta (:candies %1))) s1)) s2) :else (concat s1 s2)))) (defn join-subseqs [subseqs] (if (<= 2 (count subseqs)) (reduce subseq-concat (first subseqs) (rest subseqs)) (first subseqs))) (defn pipeline [v] (->> v (chunk-by-derivative) (map candy-delta) (map simple-min-candy) (join-subseqs) (map #(:candies %1)) (apply +) (println))) (defn -main [& args] (let [line-count (read) v (map (fn [x] (read)) (range line-count))] (pipeline v))) (-main) ``` ### Assumptions * That the children numbered "2" rank **below** the child ranked "1" * That two adjacent children of equal number should receive the same number of candies. Easy to change but until the OP clarifies the spec I'm keeping it that way. ### General Algorithm This solution is based on problem decomposition and composition of functions via the ->> operator. The approach is to "chunk" the ordering of students into sub-orders which are increasing or decreasing. Using the simple approach outlined below which is correct in these cases, a partial candy count can be generated for each of these subsequences which is absolutely minimum for that sequence as argued below. Subsequences can then be joined by comparing the last value of the sequence to concatenate to and the first value of the sequence to be added, and if necessary adding a constant C to all elements of the sequence to be added to in order to ensure that the rank-based order property between children is maintained. This approach is correct for the multi-delta case as it will consider the ordering [3 2 1 4 4] to be the two sequences [3 2 1] which is strictly increasing and receive respectively [1 2 3] pieces of candy and the sequence [4 4] which will receive the candy [1 1]. The concatenation of [1 2 3] and [1 1] respects the order property that child 1 receive more candy than any child 4 so the order is correct. ### Algorithm for individual derivative constant sequences This algorithm first generates a series of pairs [d, v] starting with [1, (first input value)] where the first element is the candy count of that child, being +1, +0, -1 from the last child. Note that these are ordered by the input (or seating) order, and thus correctly represent the minimum correct candy change between any pair of consecutive children [c, c']. As the goal is to produce the number of total candies required, the first element of each pair is then taken to create a new sequence of numbers representing the candy count taken in comparison to the candy count of the child who happened to be seated first. The last step then is to compute the final number of candies with regard to the child seated first. There are three cases here, all of which can be identified by the minimum number of candies given out to any one child. 1. The minimum is less than one. As all children must receive one or more candies all the children must gain K candies where K is `1 - (min chindren)`, thus guaranteeing that the bottom child receives exactly one candy. 2. The minimum is greater than one. An unreachable case, as the worst possible cases in terms of candy consumed are the increasing and decreasing sorts by rank. The decreasing sort would be handled by case 1, and the increasing sort would have a minimum value of 1 and require no further analysis. 3. The case where the minimum is one, so no further processing is required. ### Correctness for all strictly increasing cases For any strictly increasing ordering of children `(c0 c1 c2 ... cn)` the ith [counting from 0th] child will receive `i + 1` pieces of candy. Consequently increasing the count of candy by one in the case of an increase in rank from [c -> c'] is necessarily correct. ### Correctness for all strictly decreasing cases By a similar argument, for any case where [c -> c'] is always decrease the subtraction of one candy from each child to the next is the minimum possible delta. The first biasing case then kicks in to ensure that the result guarantees one candy per child. ### Correctness for all mixed cases Any mixed sequence can be expressed as the composite of at least two sequences with different trends (being decreasing or increasing). By breaking such composite sequences into the trend-based subsequences, application of the known correct increasing/decreasing algorithm is trivially correct for all subsequences and a join of all subsequences which guarantees that the rank order property is preserved ensures that all resulting sequences are also minimal. ### Test Cases ``` 3 1 2 2 ``` => `4` being `[2 1 1]` ``` 7 1 2 3 4 3 4 5 ``` => `20` being `[5 4 3 2 3 2 1]` ``` 8 1 2 1 2 1 2 1 2 ``` => `12` being `[2 1 2 1 2 1 2 1]` ### Bugs If there are any please smack me upside the head for being a cocky jerk. This composition of functions *should* be generally correct but I do not doubt my capacity for overlooking my own errors. ]
[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/214731/edit). Closed 3 years ago. [Improve this question](/posts/214731/edit) Write the shortest possible code cause an error due to recursion too deep Example error in [python](/questions/tagged/python "show questions tagged 'python'") ``` RecursionError: maximum recursion depth exceeded ``` Example error in [c](/questions/tagged/c "show questions tagged 'c'") ``` Segmentation fault ``` My Python version (15 bytes): ``` def f():f() f() ``` [Answer] ## Python 3, 15 bytes ``` exec('()'*9999) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/P7UiNVlDXUNTXcsSCDT//wcA "Python 3 – Try It Online") An alternative that doesn't use functions. Unfortunately `RecursionError` does not exist in Python 2 so we can't cut the brackets in `exec`. ## Python 3.8, 18 bytes ``` exec(s:='exec(s)') ``` [Try it online!](https://tio.run/##K6gsycjPM7YoKPr/P7UiNVmj2MpWHcLQVNf8/x8A "Python 3.8 (pre-release) – Try It Online") [Answer] # [Python 3](https://docs.python.org/3/ "Python 3"), ~~20~~ 18 bytes ``` def f(x):x(x) f(f) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNo0LTqgJIcKVppGn@/w8A "Python 3 – Try It Online") [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 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")) ``` F F ``` A 1-byte header separated by a line break byte from by a 1-byte body which calls the function itself. This type of function doesn't have tail call optimisation, so this fails when memory runs out. Anonymous lambdas do have [tail recursion](https://stackoverflow.com/q/33923/5306507), but we can prevent that: ``` {-∇⍵}1 ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///v1r3UUf7o96ttYb//wMA "APL (Dyalog Unicode) – Try It Online") `{`…`}1` call an anonymous lambda with an argument of 1:  `⍵` the argument  `∇` recurse on that  `-` negate the result We never actually reach the negation before running out of memory, but it is needed to avoid the optimisation. ]
[Question] [ I'm looking for the shortest code to generate the following sequences: ``` Sequence A i | y x 0 | 0 0 1 | 0 1 2 | 1 0 3 | 1 1 ``` The best I have is `x = i % 2, y = i / 2`, there is probably no beating that. Those are coordinates of corners of a box in 2D, but they are not in a good order for drawing. To draw a box as line loop, one needs those coordinates: ``` Sequence B i | y x 0 | 0 0 1 | 0 1 2 | 1 1 3 | 1 0 ``` So far, I have `x = (i ^ i / 2) % 2, y = i / 2`. There is likely space for improvement there. Finally, how to generate directions towards the box edges (where the order does not matter, but `i` still must be 0 to 3): ``` Sequence C i | y x ? | 0 -1 ? | 0 1 ? | -1 0 ? | 1 0 ``` So far I have rather ugly `x = (1 | -(i % 2)) * (i / 2), y = (1 | -(i % 2)) * (1 - i / 2)`. Shortest code in any programming language wins (I actually plan to use these). The best solution will be used in a **closed-source** project, **no attribution** can be paid other than source code comment, so post only if you're ok with it. Submit solutions to any of the above sequences. Don't bother writing code that generates all of them, think of it like competition with three categories (and tree possible winners). [Answer] Short sequence C (20 characters): ``` x=1==i^-!i,y=i%3-!!i ``` This generates a permutation of the original sequence (as I said, the order does not matter): ``` x -1 1 0 0 y 0 0 1 -1 ``` Short sequence B (14 characters): ``` x=i>>~-i,y=i/2 ``` So how about that? I'd say it is not possible to do better than that. Anyone to prove me wrong? And yes, this answer is free. Use it as you want, sell it, no attribution needed. **EDIT**: Shorter sequence C (17 characters): ``` x=~-i%2,y=~-~-i%2 ``` This generates a permutation of the original sequence (as I said, the order does not matter): ``` x -1 0 1 0 y 0 -1 0 1 ``` Some other interesting solutions to short sequences: ``` was solving for {0, 0, 1, 1} in 1D {4 x 1 x 1} domain solution: '1 < i': score 3 solution: 'i > 1': score 3 solution: 'i / 2': score 3 was solving for {0, 1, 0, 1} in 1D {4 x 1 x 1} domain solution: '1 & i': score 3 solution: 'i & 1': score 3 solution: 'i % 2': score 3 was solving for {0, 1, 1, 0} in 1D {4 x 1 x 1} domain solution: 'i >> ~-i': score 6 solution: '!!(i % 3)': score 7 solution: 'i >> ~(-i)': score 8 was solving for {-1, 1, 0, 0} in 1D {4 x 1 x 1} domain solution: '!~-i - !i': score 7 solution: '!~-i + -!i': score 8 solution: '!~-i | -!i': score 8 was solving for {1, -1, 0, 0} in 1D {4 x 1 x 1} domain solution: '!i - !~-i': score 7 solution: '!i - !(~-i)': score 9 solution: '-!(~-i) + !i': score 10 was solving for {1, 0, 0, -1} in 1D {4 x 1 x 1} domain solution: '-~(~i / 2)': score 8 solution: '-~(-i >> 1)': score 9 solution: '-(~-i >> 1)': score 9 was solving for {-1, 0, 0, 1} in 1D {4 x 1 x 1} domain solution: '~-i >> 1': score 6 solution: '~(~i / 2)': score 7 solution: '~-i >> !!i': score 8 was solving for {0, 1, -1, 0} in 1D {4 x 1 x 1} domain solution: '~(~i % 3)': score 7 solution: '~(~i % ~2)': score 8 solution: '~(~i % -3)': score 8 was solving for {0, -1, 1, 0} in 1D {4 x 1 x 1} domain solution: '-~(~i % 3)': score 8 solution: '-~(~i % ~2)': score 9 solution: '-~(~i % -3)': score 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/162859/edit). Closed 5 years ago. [Improve this question](/posts/162859/edit) # Challenge : Given a string rotate every char by its index. `e.g --> 'Hello' should be 'Hfnos'`. --- # Input : Input is given as string `s` length of string is `2 < s ≤ 100`. Input will either be alphabet , number or one of the following whitespace , ! , @ , # , $ , % , ^ , & , \* , ( , ) --- # Output : Output will be a string with all characters rotated by their index. Example given above. --- # Examples : ``` Input Output Hello World! Hfnos%]vzun, Who Wiq PPCG PQEJ ``` --- # Note : This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest code in bytes in each language wins. [Answer] ## Haskell, ~~37~~ ~~36~~ 28 bytes ``` zipWith($)(iterate(succ.)id) ``` [Try it online!](https://tio.run/##y0gszk7NyfmfZhvzvyqzIDyzJENDRVMjsyS1KLEkVaO4NDlZTzMzRfN/bmJmnoKtQkFpSXBJkU@egopCmoKSB1BrvtL/f8lpOYnpxf91kwsKAA "Haskell – Try It Online") How it works ``` iterate(succ.)id -- starting with the identity function 'id' this -- creates an infinite list of function where the next -- element has one more 'succ' (the successor function) -- composed to it than the current element: -- -> [id, succ.id, succ.succ.id, succ.succ.succ.id, ...] zipWith ($) ( ) -- combine the above list and the input string -- elementwise with the function application operator '$'. -- 1st char c0: id $ c0 = c0 -- 2nd char c1: succ.id $ c1 = succ c1 -- 3rd char c2: succ.succ.id $ c2 = succ (succ c2) -- etc. ``` Edit: -8 bytes thanks to @Angs [Answer] # [Python 2](https://docs.python.org/2/), 47 bytes ``` lambda I:[chr(ord(c)+i)for i,c in enumerate(I)] ``` [Try it online!](https://tio.run/##JYyxDsIgFEV3vuJtQKwOjk3q4qDdujnUDggYnqE8QmiMX4@C27035574yY7CsfjhXrxaH0bB2M/aJUHJCC13KJ@UADsNGMCGbbVJZStGuRQMccswwMyv1nviHfwDvCl5U@vNtXWazhe@MNZM1dOePQOICUP@2YHvT5XkhxdhEF6glKx8AQ "Python 2 – Try It Online") [Answer] # Japt, 2 bytes ``` c+ ``` [Try it out here](https://ethproductions.github.io/japt/?v=1.4.5&code=Yys=&input=IkhlbGxvIFdvcmxkISI=) ]
[Question] [ ### Objective Write a program that outputs some printable ASCII characters. The trick is that if the program is reversed byte-by-byte, it must output the same thing in the reverse order, byte-by-byte, too. ### Rules * No standard loopholes. * The program must **not** be a palindrome, nor can it be 1 byte in length (or empty). No restriction for patterns of the output as long as: * The output is at least 2 bytes long. It must contain solely printable ASCII characters, including visible characters and newlines, tabs and spaces. It should not be empty. * **Outputs to standard error is ignored.** * **Quine programs are forbidden.** For example, the following program makes no sense (HQ9+) ``` AQ ``` ### Easy Mode Paired parentheses/brackets/curly brackets are swapped after reversing source, so a reverse may be: ``` print("Hello"); ;("olleH")tnirp # not ;)"olleH"(tnirp ``` **Make a note in your answer** if your program uses this "Easy Mode". ### Example These are theoretical examples and may not exist in any programming language. ``` input -> output program -> abcd margorp -> dcba () -> 10 )( -> 01 print('yes')tnirp -> yes print('sey')tnirp -> sey ``` This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the program with the shortest source code (in bytes) in each language wins! ## Leaderboard Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language. ``` /* Configuration */ var QUESTION_ID = 142801; // Obtain this from the url // It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author. /* App */ var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; if (/<a/.test(lang)) lang = jQuery(lang).text(); languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang > b.lang) return 1; if (a.lang < b.lang) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } } ``` ``` body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } 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] # [RProgN 2](https://github.com/TehFlaminTaco/RProgN-2), 2 bytes ``` Ai ``` Forwards, produces `ZYXWVUTSRQPONMLKJIHGFEDCBA`, backwards, produces `ABCDEFGHIJKLMNOPQRSTUVWXYZ`. `A` pushes the alphabet, and `i` reverses it, although if `i` doesn't have anything to reverse, it conveniently does nothing. [Try it online!](https://tio.run/##Kyooyk/P0zX6/98x8/9/AA "RProgN 2 – Try It Online") [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes ``` 22«33 ``` [Try it online!](https://tio.run/##y0rNyan8/9/I6NBqY@P//wE "Jelly – Try It Online") The first is `min(22, 33)` and the reverse is `min(33, 22)` # Also 5 bytes ``` .)25½ ``` [Try it online!](https://tio.run/##y0rNyan8/19P08j00N7//wE "Jelly – Try It Online") The `)` seems to discard everything before it. This is `sqrt(25)` which is `5.0` and the reverse is `.` which is `0.5`. [Answer] # [Rain-Flak](https://github.com/DJMcMayhem/Brain-Flak), ~~65~~ 59 bytes ``` ((((((#)])([))(}{)}{))}{)) ()()()()( )){})){}){})())#(((((( ``` [Try it online!](https://tio.run/##SypKzMzTTctJzP7/XwMMlDVjNTWiNTU1aqs1gQiMuTQ0oZBLU7O6FoyBSENTUxmi6f///7qORQA "Brain-Flak – Try It Online") This pushes ``` () ``` going forwards and ``` )( ``` going backwards. It needs to pad the front with a newline because Brain-Flak's output automatically gets a newline added to the end of the output. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 2 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` 0% ``` **[Try it online!](https://tio.run/##y0rNyan8/99A9f9/AA "Jelly – Try It Online")** ...or **[try `%0`](https://tio.run/##y0rNyan8/1/V4P9/AA "Jelly – Try It Online")** Both full programs output the palindromic `nan` as they both attempt to take a modulo of zero by zero and implicitly print the result. [Answer] # Brain-Flak, ~~35~~ 28+1=29 bytes ``` ((#)}{)) ()()()()( )){})#(( ``` 1 extra byte because of the flag `-A` to print ascii. This prints "\n\n" [Try it online!](https://tio.run/##SypKzMzTTctJzP7/X0NDWbO2WlOTS0MTCrkUNDWrazWVNTT@//@v6wgA "Brain-Flak – Try It Online") -6 bytes thanks to [Riley](https://codegolf.stackexchange.com/users/57100/riley) pointing out that I can cleverly use newlines in order to not duplicate as much code for the reversed program. This works because the pound sign only starts a single line comment. [Answer] # Excel VBA, 11 Bytes *(Ab)uses the fact that Excel has more than one STDOUT; Does not use Easy Mode* Anonymous VBE immediate window function that takes no input and outputs `12` to the VBE immediate window. ``` ?12'12=]1A[ ``` ### Reversed Anonymous VBE immediate window function that takes no input and outputs `21` to the the range `[A1]` on the ActiveSheet Object. ``` [A1]=21'21? ``` Note: `?12'12?` works as well but feels a bit too close to palindromic to be within the spirit of the challenge [Answer] # [Pyth](https://pyth.readthedocs.io/en/latest/), 4 bytes ``` "Jj" ``` Outputs [`Jj`](https://pyth.herokuapp.com/?code=%22Jj%22&debug=0) and [`jJ`](https://pyth.herokuapp.com/?code=%22jJ%22&debug=0) when reversed. [Answer] # Mathematica, 5 bytes ``` 44+55 ``` or... # Mathematica, 4 bytes ``` 11*9 ``` outputs `99` [Answer] # [Python 2](https://docs.python.org/2/), ~~43~~ ~~42~~ 52 bytes ### Source ``` #1.,"n\"tnirp:tpecxe #""" print"\n",\ 1.#"""cexe:yrt ``` [Try it online!](https://tio.run/##K6gsycjPM/r/X9lQT0cpL0apJC@zqMCqpCA1uSKVS1lJSYmroCgzr0QpJk9JJ4bLUA8klJxakWpVWVTy/z8A "Python 2 – Try It Online") ### Reversed source ``` try:exec"""#.1 \,"n\"tnirp """# except:print"\n",.1# ``` [Try it online!](https://tio.run/##K6gsycjPM/r/v6So0iq1IjVZSUlJWc@QK0ZHKS9GqSQvs6iACyTElVqRnFpQYlVQlJlXohSTp6SjZ6j8/z8A "Python 2 – Try It Online") --- Inspired by [i cri everytim's answer](https://codegolf.stackexchange.com/a/142823/73111). Does, however, not require 'easy mode'. The program's outputs now are true reverses of one another, not ignoring the new line character. Thanks to [@Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan) for pointing it out. [Answer] # [Japt](https://github.com/ETHproductions/japt), ~~4~~ 3 bytes *-1 byte thanks to @ETHproductions* ### Normal ``` 12C ``` [Try it online!](https://ethproductions.github.io/japt/?v=1.4.5&code=MTJD&input=) Prints `12`. ### Reversed ``` C21 ``` [Try it online!](https://ethproductions.github.io/japt/?v=1.4.5&code=QzIx&input=) Prints `21`. Only the last statement is printed, and `C` is the constant for `12`. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes ``` 1+³ ``` [Try it online!](https://tio.run/##y0rNyan8/99Q@9Dm//8B "Jelly – Try It Online") This is `1 + 100` which is `101`. The reverse is just `100 + 1` which is also `101`. Replacing `+` with `_` works too. # Also 3 bytes ``` 11» ``` [Try it online!](https://tio.run/##y0rNyan8/9/Q8NDu//8B "Jelly – Try It Online") The first is `max(11, 0)`. The reverse is just `max(0, 11)`. The argument is `0` by default if not present. [Answer] # [Perl 5](https://perl.org) / [Perl 6](https://perl6.org) / [Ruby](https://www.ruby-lang.org/), 17 bytes ``` print 12#12 tnirp ``` [Try it in Perl 5](https://tio.run/##K0gtyjH9/7@gKDOvRMHQSNnQSKEkL7Oo4P9/AA "Perl 5 – Try It Online") [Try it reversed in Perl 5](https://tio.run/##K0gtyjH9/7@gKDOvRMHIUNnIUKEkL7Oo4P9/AA "Perl 5 – Try It Online") [Try it in Perl 6](https://tio.run/##K0gtyjH7/7@gKDOvRMHQSNnQSKEkL7Oo4P9/AA "Perl 6 – Try It Online") [Try it reversed in Perl 6](https://tio.run/##K0gtyjH7/7@gKDOvRMHIUNnIUKEkL7Oo4P9/AA "Perl 6 – Try It Online") [Try it in Ruby](https://tio.run/##KypNqvz/v6AoM69EwdBI2dBIoSQvs6jg/38A "Ruby – Try It Online") [Try it reversed in Ruby](https://tio.run/##KypNqvz/v6AoM69EwchQ2chQoSQvs6jg/38A "Ruby – Try It Online") [Answer] # [Python 2](https://docs.python.org/2/), 20 bytes ``` print'\n';#'n\'tnirp ``` [Try it online!](https://tio.run/##K6gsycjPM/r/v6AoM69EPSZP3VpZPS9GvSQvs6jg/38A "Python 2 – Try It Online") `print'\n'` prints both the single newline it instructs and an implicit newline after. `print'\n';` does exactly the same - the `;` is just there to stop the program being a palindrome. The `#` marks the start of a comment. [Answer] ## Charcoal, 2 bytes ``` -¹ ``` The `-` is simply a string literal that implicitly prints itself. The `¹` is a numeric literal, and the default is to implicitly print one `-` too. Any ASCII character and non-zero Unicode superscript would work. ``` ²← ``` Forwards, this prints two `-`s, then moves the cursor back one step (but this does not affect the output). Backwards, this prints two `-`s leftwards, but the output remains the same. Any subscript from 2 to 9 would work here, as would a right arrow or the reflect operator `‖`. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes ``` ?RA? ``` [Try it online!](https://tio.run/##MzBNTDJM/f/fPsjR/v9/AA "05AB1E – Try It Online") or [Try it reversed!](https://tio.run/##MzBNTDJM/f/f3jHI/v9/AA "05AB1E – Try It Online") [Answer] # [Japt](https://github.com/ETHproductions/japt/), 2 bytes Both output `11`. `B` is the Japt constant for `11` and the `w` method, when applied to a number, returns the larger of that number and any number passed to it as an argument. ``` wB ``` [Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=d0I=&input=) ``` Bw ``` [Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=Qnc=&input=) [Answer] # Javascript (ES6), 12 bytes ``` _=>12//12>=_ ``` Reversed: ``` _=>21//21>=_ ``` Code snippet: ``` a=_=>12//12>=_ b=_=>21//21>=_ console.log(a()) console.log(b()) ``` [Answer] # Java 8, 132 bytes Dang full program requirements.. ``` interface M{static void main(String[]a){System.out.print("OK");}}//}};)"OK"(tnirp.tuo.metsyS{)a][gnirtS(niam diov citats{M ecafretni ``` [Try it here.](https://tio.run/##FY1BCsMgEAC/IjnpoeYBeUIJPXgMOSxmEzZFDboRgvh2a48zMMwJGV7hQn9u39bIM8YdLIq5JAYmK3KgTTggLw1H8seygirmSYxOh5v11SXL4fMe1FTrONY6qT9J9hQvzXfQDjk9pihYl6NLNtITOLFRyMJS36QyC7SwR@xRaz8) Prints `OK`. Reversed: ``` interface M{static void main(String[]a){System.out.print("KO");}}//}};)"KO"(tnirp.tuo.metsyS{)a][gnirtS(niam diov citats{M ecafretni ``` [Try it here.](https://tio.run/##FY1BCsMgEAC/IjnpoeYBeUIJPXgMOSxmEzZFDboRgvh2a48zMMwJGV7hQn9u39bIM8YdLIq5JAYmK3KgTTggLw1H8seygirmSYxOh5v11SXL4f0Z1FTrONY6qT9J9hQvzXfQDjk9pihYl6NLNtITOLFRyMJS36QyC7SwR@xRaz8) Prints `KO`. [Answer] # [Neim](https://github.com/okx-code/Neim), 2 bytes ``` γδ ``` Outputs 12. Reversed, outputs 21. [Try it online!](https://tio.run/##y0vNzP3//9zmc1v@/wcA "Neim – Try It Online") [Answer] # SmileBASIC, 4 bytes ``` ?12? ``` This will work in many BASIC dialects. Prints "12" forwards, and "21" backwards. [Answer] # [brainfuck](https://github.com/TryItOnline/brainfuck), ~~67~~ ~~23~~ 21 bytes * Saved two bytes thanks to [12Me21](https://codegolf.stackexchange.com/users/64538/12me21); using a tab instead of a new line. ``` +++++++++..+++++++++> ``` [Try it online!](https://tio.run/##SypKzMxLK03O/v9fGwb09OBMu///AQ "brainfuck – Try It Online") The program's ouput are two ~~spaces~~ ~~new lines~~ tabs. It is nearly a palindrome, apart from the trailing or leading cell shift (`>`). [Answer] # [Triangular](https://github.com/aaronryank/triangular), 6 bytes ``` %.%%%% ``` Prints `000`. Triangle looks like this: ``` % . % % % % ``` Reversed triangle looks like this: ``` % % % % . % ``` The IP starts travelling southeast from the topmost character, so in both triangles `%%%` is interpreted. [Answer] # [Zsh](https://www.zsh.org/), 16 bytes ``` printf 12 ftnirp ``` [Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhYbCooy80rSFAyNFNJK8jKLCiDCUFmYKgA) [Answer] # [shortC](//git.io/shortC), 18 bytes ``` AJ"hi")}//})"hi"JA ``` Prints `hi`. Exploits comments. [Try it online!](https://tio.run/##K87ILypJ/v/f0UspI1NJs1Zfv1YTxPJy/P//PwA) [Answer] # [rk](//github.com/aaronryank/rk-lang), 50 bytes ``` rk:start dne:kr print: "hi" :tnirp trats:kr rk:end ``` Reversed via [this tool](https://tio.run/##K87MLchJLS5JTM7@/1@jTk/TmktD19DBWvP//6JsK6B4UQlXSl6qVXYRV0FRZl6JlYJSRqaSglVJXmZRAVdJUWJJMUgOqDY1LwUA): ``` dne:kr rk:start print: "ih" :tnirp rk:end trats:kr ``` rk ignores everything before `rk:start` and `rk:end`. Of course, it ignores everything in the middle it doesn't understand anyway. [Try it online!](https://tio.run/##FcpBCgAgCATAu6@QnuFvgoJEkNj2/1bnGUQVwg47KCOnBWTDk6ZteVNjOrYQnefbuzNH1QU) vs [Try it reversed!](https://tio.run/##FcpBCgAgCATAu6@QnuFvgoJEkNj2/1bnGUTVyGkBQdhhB2XDk6bNV1NjOva3mUOIzvNu1QU) [Answer] # [Cubically 2.1](//github.com/aaronryank/cubically/releases/v2.1), 5 bytes ``` %0%1% ``` Prints `09`. [Try it online!](https://tio.run/##Sy5NykxOzMmp/P9f1UDVUPX///8A) or [Try it reversed!](https://tio.run/##Sy5NykxOzMmp/P9f1VDVQPX///8A) The top (0-indexed) face is initialized to 0 and the left (1-indexed) face is initialized to 9. So printing (`%`) 0 prints 0 and printing 1 prints 9. No longer works in Cubically 2.2 as `%` can be called implicitly. [Answer] # [Implicit](//git.io/sS), 2 bytes ``` À\ ``` Same as the winning RProgN 2 answer. [Try it online!](https://tio.run/##K87MLchJLS5JTM7@//9wQ8z//wA) ## You can use a [tool](https://tio.run/##HcqxCsIwFIbR3af4u7WDFucufZWQ@0GDJim5wdFXj8XxwPGUzzfeQ3yNMX8fy3ab7899W8agdJq8ZhSroYOGQjE5KHU1PjTHpnWdDP9TPQlcVoKufgirUeTqV@@FHw) in this language to print the reverse of your code. [Answer] ## Unix sh, 15 bytes ``` echo ab#ab ohce ``` Reversed: ``` echo ba#ba ohce ``` Outputs `ab` and `ba`, respectively. [Answer] ## [RProgN 2](https://github.com/TehFlaminTaco/RProgN-2), 3 bytes ``` 1 0 ``` Output: ``` 0 1 ``` [Try it online!](https://tio.run/##Kyooyk/P0zX6/9@Ay/D/fwA "RProgN 2 – Try It Online") --- Reversed source: ``` 0 1 ``` Reversed output: ``` 1 0 ``` [Try it online!](https://tio.run/##Kyooyk/P0zX6/9@Ay/D/fwA "RProgN 2 – 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/21758/edit). Closed 7 years ago. [Improve this question](/posts/21758/edit) Write a code to display "I Love You". Without using any built-in tools or functions like `echo`, `System.out.println`, `printf`, ... You are not allowed to directly call any function throughout the program execution, but the system environment or the compiler-generated code might do. This way, you can put your code in a `main` function or method that is called by the running environment, but your program should not further call any functions. By the way, a function is not an instruction, nor a command nor an operator. So calling `sum(a, b)` is not valid, but making `a = b + c` is, even if the compiler reduces this to internal function calls. This is a [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'"), so the valid answer with the most upvotes wins. [Answer] ## Html-asp- xhtml-tex-php..... I didn't use any functions ``` I Love You ``` [Answer] ## Brainfuck ``` ++++ ++++ ++[>+++ ++++>++ +>+++++++ ++++<<<-] >+++.>++.<+++.>>+.+++ ++++.-------------- ---.<.<++++++++ +++++.>>+++ +++++++.+ +++++ . ``` The heart looks horribly thin here, but it is a lot better on a text editor / terminal ![enter image description here](https://i.stack.imgur.com/LqqBU.png) Here's a nicely indented version: ``` +++++ +++++ [ > +++++ ++ > +++ > +++++ +++++ + <<< - ] > +++ . > ++ . < +++ . >> + . +++++ ++ . ----- ----- ----- -- . < . < +++++ +++++ +++ . >> +++++ +++++ . +++++ + . ``` [Answer] # Javascript: ``` var l='I love you.'; if(window)window.status=l; if(document)if(document.readyState=='complete')document.innerHTML=document.title=l; else document.onload=function(){document.innerHTML=document.title=l;}; throw new l; ``` The part where it says 'function' is as ASSIGNMENT! There is nothing in the question saying I can't assign functions and trigger events. And the 'throw new l;' will say "I love you" in the error message. This will show 'I love you' in the console, document, title and in the status bar. [Answer] # C ``` void main( ) { char *string="I Love You"; volatile char *video = (volatile char*)0xB8000; while( *string != 0 ) { *video++ = *string++; *video++; } } ``` [Answer] # Mathematica, GolfScript, Python Interpreter, bc This outputs the sentence: ``` "I love you" ``` [Answer] # PHP Quite rule bending maybe... ``` <? ?>I Love You ``` [Answer] # HTA - HyperText Application ``` I Love You ``` Microsoft says any plain text is valid HTA. They even mention in their official documentation that their "Hello, World." can be as simple as: ``` Hello, World. ``` Although most examples that you see on the web go the "official" route. [Answer] ## Shell Script ``` mkdir "I Love You" cd I\ Love\ You/ pwd | grep -o '/I Love You' | cut -c2- ``` [Answer] # Smalltalk as there is a read-eval-print-loop, and strings are self evaluating, this is trivial. From the command line, type this: `stx -P "'I love you'` A workspace, which is a basically a graphical wrapper for the `eval`, type in a string and select the "printIt" menu function. [Answer] # DOS Command Prompt ``` C:> prompt I Love You I Love You ``` ]
[Question] [ ## Challenge You must choose one number `x` (`y = x + 9`) and create ten unique programs which each print out one of the numbers in the range `x` to `y` inclusive. However, there are three twists: * Each program's score is the difference between length of your program in bytes and `n` (where `n` is the number that the program outputs). i.e. If a program is 12 bytes long and it outputs the number 15, its score is 3 (`|15-12| = 3`). + You must not use comments to achieve this byte count. * Your program must not contain any number which is contained within the number which the program outputs. i.e. If a program outputs `1659`, the program cannot contain 1, 6, 5 or 9 * Your program must not contain any of the characters which are the first letters of the number which the program outpts. i.e. If the program outputs `1659`, the program cannot contain o, s, f or n (**o**ne, **s**ix, **f**ive and **n**ine) ## Rules If any number is impossible, this is counted as a DNP. You should declare all DNPs in your range. The following is a list of numbers and their spellings. The disallowed characters for each are highlighted in bold: * 0: **Z**ero * 1: **O**ne * 2: **T**wo * 3: **T**hree * 4: **F**our * 5: **F**ive * 6: **S**ix * 7: **S**even * 8: **E**ight * 9: **N**ine ## Scoring Your overall score is the sum of all your programs' scores. ## Winning The person with the lowest score with the fewest DNPs wins. In the event of a tie, the person whose last edit was earliest wins. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/), score = 0 Chosen **x = 1** **Programs** **1**: Variable initialized as 1 ``` X ``` **2**: zeroth prime number ``` 0Ø ``` **3**: first digit of 2^15 ``` žG¬ ``` **4**: integer root of 16 ``` žvtï ``` **5**: first digit of pi + 2 ``` žqS¬Ì ``` **6**: first digit of 2nd to last set from the powerset of 256 ``` žzœ¨¤¬ ``` **7**: the (e // e)th primeth prime ``` žržr÷ØØ ``` **8**: the first 2 digits of the sum of the 10 first multiples of 3, divided by 2 ``` TLx+O¨Y÷ ``` **9**: ceil(sqrt(sum(range[1..10])))+2 XOR 1st prime ``` TLOtîÌXØ^ ``` **10**: int(prod([1..9])/2^15)-1 ``` žmS¨PžG/ï< ``` [Answer] # [brainfuck](http://esolangs.org/wiki/Brainfuck), score = 0 Chosen **x = 15** **15** ``` +++[>+++++<-]>. ``` **16** ``` +++[>+++++<-]>+. ``` **17** ``` >+[>-[-<]>>]>+-+. ``` **18** ``` +++[>++++++<-]>+-. ``` **19** ``` +++[>++++++<-]>++-. ``` **20** ``` ++++[>+++++<-]>+-+-. ``` **21** ``` +++[>+++++++<-]>++--. ``` **22** ``` +++[>+++++++<-]>+--++. ``` **23** ``` >-[++++[<]>->+]<+++---. ``` **24** ``` +++++[>+++++<-]>++----+. ``` Output is in byte values. [Answer] # Jelly, score 0 **x=3**, using ten completely different methods ``` 2ÆN - 3: second prime 6ḃ2S - 4: sum of digits of 6 in bijective-base 2 2*4BL - 5: number of bits in 16 2+1R+/ - 6: third triangle number ⁵×ØeḞDṪ - 7: 1st decimal place of Euler's number 12,6_/+2 - 8: Number of vertices on a cube ȷ*4×ØPḞDṪ - 9: the 12th decimal place of pi 9999b9999Ḍ - 10: decimal of 9999 base 9999 45683g38654 - 11: greatest common divisor of 45683 and its reverse 6RLRL×7RLÆfS - 12: sum of the prime factors of 42 (6*7 is the ultimate question) ``` Run all ten at [**TryItOnline**](http://jelly.tryitonline.net/#code=MsOGTgo24biDMlMKMio0QkwKMisxUisvCuKBtcOXw5hl4bieROG5qgoxMiw2Xy8rMgrItyo0w5fDmFDhuJ5E4bmqCjk5OTliOTk5OeG4jAo0NTY4M2czODY1NAo2UkxSTMOXN1JMw4ZmUwrigbXCucKj4oKs&input=&args=CgoKCg) --- Previous (just another boring answer) **x=2** ``` 1‘ - 1 incremented 1+1 = 2 1‘‘ - 1 incremented twice 1+1+1 = 3 1‘‘‘ - 1 incremented thrice 1+1+1+1 = 4 1‘‘‘‘ - ... 1+1+1+1+1 = 5 1‘‘‘‘‘ - ... 1+1+1+1+1+1 = 6 1‘‘‘‘‘‘ - ... 1+1+1+1+1+1+1 = 7 1‘‘‘‘‘‘‘ - ... 1+1+1+1+1+1+1+1 = 8 1‘‘‘‘‘‘‘ - ... 1+1+1+1+1+1+1+1+1 = 9 3‘‘‘‘‘‘‘‘’ - 3 incremented eight times then decremented 3+1+1+1+1+1+1+1+1-1 = 10 3‘‘‘‘‘‘‘‘‘’ - 3 incremented nine times then decremented 3+1+1+1+1+1+1+1+1+1-1 = 11 ``` --- If tie-break is on lowest **x** then for **x=0** ``` - 0: empty program returns zero ¬ - 1: logical not ¬‘ - 2: logical not then increment ¬‘‘ - 3: logical not then increment twice ¬‘‘‘ - 4: logical not then increment thrice ¬‘‘‘‘ - 5: logical not then increment four times ¬‘‘‘‘‘ - 6: logical not then increment five times ¬‘‘‘‘‘‘ - 7: logical not then increment six times ¬‘‘‘‘‘‘‘ - 8: logical not then increment seven times ¬‘‘‘‘‘‘‘‘ - 9: logical not then increment eight times ``` Run all ten at [**TryItOnline**](http://jelly.tryitonline.net/#code=CsKsCsKs4oCYCsKs4oCY4oCYCsKs4oCY4oCY4oCYCsKs4oCY4oCY4oCY4oCYCsKs4oCY4oCY4oCY4oCY4oCYCsKs4oCY4oCY4oCY4oCY4oCY4oCYCsKs4oCY4oCY4oCY4oCY4oCY4oCY4oCYCsKs4oCY4oCY4oCY4oCY4oCY4oCY4oCY4oCYCuKBtcK5wqPigqw&input=) [Answer] # Python 2, score 0 x = 14 ``` print +2*3+3+5 print 6+2*3+3+0 print 7+2*3+3+00 print 6+2*3+5+0+0 print-~6+2*3+5+0+0 exec"pri\x6et 22-3" exec"prin\164 9+8+3" exec"prin\x74 9+9+03" exec"prin\164-~9+8+04" exec"prin\164-~9-~8+04" ``` [Answer] # [Emotinomicon](//conorobrien-foxx.github.io/Emotinomicon/int.html), 205 bytes x = 16 ``` 😒😉😘😨 😭71😲 ⏬⏬ 😭81😲 ⏬ ⏬ 😭91😲⏪⏬⏩ 😭02😲⏬⏬ ℹ 😭12😲⏬⏬ ℹ 😭22😲⏪⏬⏬⏩ 😭32😲 ⏪⏬⏬⏩ 😭42😲⏬⏬😊😊 😗😣😨ℹℹ➕😊 ``` Pro tip: Prepend a `😷` before each snippet to clean the output. [Answer] ### Pyke, x=2, score 0 ``` 1h 1hh 1hhh 1hhhh 1hhhhh 1hhhhhh 1hhhhhhh 1hhhhhhhh ZOhhhhhhhh ZOhhhhhhhhh ``` [Answer] # Mathematica, *x* = 4, score 0 ``` 3+1& 4+01& 5+001& 6+0001& 7+00001& 8+000001& 8+2+22-22& 9+00000002& 9+000000003& 9+0000000004& ``` Anonymous functions. Take no input and return numbers as output. [Answer] ### Pyth, x=2, score 0 ``` h1 hh1 hhh1 hhhh1 hhhhh1 hhhhhh1 hhhhhhh1 hhhhhhhh1 hhhhhhyyld hhhhhhhyyld ``` [Answer] # PHP 7 , x=4,score=0 ``` 2+2; 11-6; 18-12; 3+2**2; 2+2+2+2; 3+2**2+2; 2+2+2+2+2; 3+2**2+2+2; 3*3+3+6-3-3; 4**2-5+2+0*2; ``` [Answer] ## [Ru](https://github.com/tuxcrafting/ru), score = 0 `x = 2` ``` ’1 ’’1 ’’’1 ’’’’1 ’’’’’1 ’’’’’’1 ’’’’’’’1 ’’’’’’’’1 →’’’’’’’’2 →’’’’’’’’’2 ``` [Answer] ## dc, x = 5, score 0 ``` # Note: in dc all numbers typed in use the input radix. By default it is 10, which #means that a number like CF is not 207, but 12*10^1 + 15*10^0 = 135. CCDap # 5 print character with the ASCII code (1333 % 256 =) 53 CCEadp # 6 print character with the ASCII code (1334 % 256 =) 54 CCFaddp # 7 print character with the ASCII code (1335 % 256 =) 55 ACBAaddp # 8 print character with the ASCII code (11320 % 256 =) 56 ACBBadddp # 9 print character with the ASCII code (11321 % 256 =) 57 Addddddddp #10 print 10 (A) Bdddddddddp #11 print 11 (B) Cddddddddddp #12 print 12 (C) Ddddddddddddp #13 print 13 (D) Eddddddddddddp #14 print 14 (E) ``` Comments were added for a better understanding. All the above 10 programs are standalone, but you could have a bonus program that prints all the numbers from 5 to 14, by copy-pasting each code into one single file. ]
[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/11997/edit). Closed 7 years ago. [Improve this question](/posts/11997/edit) ## Challenge: You Are The Teacher Everyone knows that simple task of receiving a grade, and telling if the student: > > * is approved, > * will attend the summer school, or > * failed. > > > In this challenge, you must write a program that does that, but using the maximum of one `if` statement (also ternary operators count as `if`). The grade will be an integer from 0 to 10. ``` situation outputs ------------------------- grade >= 7: Approved grade >= 3: Summer School grade < 3: Failed ``` You can do **whatever** you want, write in any language. Fastest working answer wins. [Answer] ### Ruby Using regular expressions: ``` puts "Failed012Summer School3456Approved78910"[/\D*(?=\d*#{gets.chomp})/] ``` Plain array indexing: ``` puts ["Failed","Summer School","Approved"][(gets.to_i+1)/4] ``` [Answer] ### Ruby ``` def x(mark) possible_results = ['','Failed', 'Failed', 'Summer school', 'Approved'] index = (mark + 1).to_s(2).length possible_results[index] end ``` This uses the fact that the length of the binary representation of the numbers 0-10 is pretty close to the required classification. Online test: <http://ideone.com/y0kLqY> [Answer] **Python2: 65** Bonus: it doesn't use *any* conditional expression. ``` g=input();print("Approved","Summer School","Failed")[(g<7)+(g<3)] ``` Example output: ``` >>> g=input();print("Approved","Summer School","Failed")[(g<7)+(g<3)] 10 Approved >>> g=input();print("Approved","Summer School","Failed")[(g<7)+(g<3)] 7 Approved >>> g=input();print("Approved","Summer School","Failed")[(g<7)+(g<3)] 6 Summer School >>> g=input();print("Approved","Summer School","Failed")[(g<7)+(g<3)] 3 Summer School >>> g=input();print("Approved","Summer School","Failed")[(g<7)+(g<3)] 2 Failed ``` [Answer] # C ``` #include <stdio.h> #include <stdlib.h> int min(int a, int b) { return (a < b) * a + (a >= b) * b; } const char *grade_to_string(int grade) { const char * grades[3] = { "Failed", "Summer school", "Approved" }; return grades[min(((grade + 1) >> 2), 2)]; } int main(int argc, char *argv[]) { int grade = atoi(argv[1]); printf("%d = %s\n", grade, grade_to_string(grade)); return 0; } ``` Test: ``` $ gcc -Wall -O3 grade.c $ time for i in $(seq -1 20) ; do ./a.out $i ; done -1 = Failed 0 = Failed 1 = Failed 2 = Failed 3 = Summer school 4 = Summer school 5 = Summer school 6 = Summer school 7 = Approved 8 = Approved 9 = Approved 10 = Approved 11 = Approved 12 = Approved 13 = Approved 14 = Approved 15 = Approved 16 = Approved 17 = Approved 18 = Approved 19 = Approved 20 = Approved real 0m0.120s user 0m0.025s sys 0m0.042s $ ``` [Answer] ## Perl ``` sub f { my $grade = shift; my $result = 0; for (++$grade ; $grade > 1; $grade >>= 1) { ++$result; } return ("Failed", "Failed", "Summer school", "Approved")[$result]; } ``` (The for-loop test constitutes the program's one permitted "if statement".) [Answer] # R ``` g=function(x)cut(x,c(0,3,7,10), labels=c("Failed","Summer school","Approved"), right=FALSE, include=TRUE) ``` Usage: ``` > g(2) [1] Failed Levels: Failed Summer school Approved > g(7) [1] Approved Levels: Failed Summer school Approved > g(3) [1] Summer school Levels: Failed Summer school Approved ``` Function `cut` in R converts a numeric into a factor (categorical) according to the interval in which it falls. It is vectorized: ``` > g(0:10) [1] Failed Failed Failed Summer school Summer school Summer school Summer school [8] Approved Approved Approved Approved Levels: Failed Summer school Approved ``` [Answer] # Awk ``` { print check($1,0,2,"Failed") check($1,3,6,"Summer School") check($1,7,10,"Approved") } function check(grade,lower,upper,result) { if (grade>=lower && grade<=upper) return result } ``` (There are enough clever solutions, so I felt the need to post a brute force one too.) Sample run: ``` bash-4.1$ for i in {0..10}; do echo -n $i\ ; awk grade.awk <<< $i; done 0 Failed 1 Failed 2 Failed 3 Summer School 4 Summer School 5 Summer School 6 Summer School 7 Approved 8 Approved 9 Approved 10 Approved ``` [Answer] ## APL ``` 'Failed' 'Summer School' 'Approved'⌷⍨+/⎕≥0 3 7 ``` Explanation: * `⎕≥0 3 7`: read input, see if it is bigger or equal to 0, 3 and 7 (this gives a vector of bits, i.e. if the input is `5` this gives `1 1 0`) * `+/`: sum the vector (giving an index into the list) * `⌷⍨`: select the corresponding string from the list [Answer] Using Javascript, Thanks to @Bakuriu ``` function decision(g) { var d = ["Approved","Summer School","Failed"]; return d[(g<7)+(g<3)] } console.log(decision(2)); ==> Failed console.log(decision(5)); ==> Summer School console.log(decision(9)); ==> Approved console.log(decision(1)); ==> Failed console.log(decision(4)); ==> Summer School ``` [Answer] # Java ``` public static String getFeedback(int grad) { String str = grad>=7? "Approved" : grad>=3 ? "Summer School" : grad<3 ? "Failed" : ""; return str; } ``` ]
[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/63519/edit). Closed 8 years ago. [Improve this question](/posts/63519/edit) **Your Task** Write a program using ASCII characters. Five alphanumeric (0-9, A-Z, a-z) characters will be inserted at random into your program's source code. Your task is to detect and output these characters inserted into your program. **Conditions** * Your code cannot use any form of backup file. * Your code may produce any unnecessary error messages, provided these are distinguishable from the actual output. * The output may be on the screen or into a file. * The output may also contain unnecessary characters, but no extra alphanumeric characters (excluding error messages). **Winning** The post with the largest vote count wins. [Answer] # PHP, 0 bytes PHP will simply echo the source until it sees an opening code tag `<?`. ]
[Question] [ # Introduction In most interpreted languages, there is an operation that will run code generated at runtime. It generally requires alphanumeric characters to refer to this operation. Write a program, using as few alphanumeric characters as possible, that is able to download and execute any string in the language you're working with, using as few alphanumeric characters as possible. Informal bonus points for commonly used languages where this is a very difficult task, such as python. # Challenge Inputs: a url to code in your language of choice, via either stdin or argv. Outputs: output of executing the downloaded code. Your program must generate the string to execute and call the eval/exec function/operator without reading from any existing files (excluding the file readings done by your interpreter of choice on startup and reading of standard library files by your language's import mechanism). Winning entries must be written using only printable ascii characters. Compiled languages are allowed, if you can find a way to invoke the same compiler at runtime with the same settings. Submissions will be scored, per-language, based on who uses the fewest executable alphanumeric characters. Non-alphanumeric characters do not count towards your score, nor do comments - try to make your non-alphanumeric code readable. # Input and Output example Contents of my [example target gist](https://gist.githubusercontent.com/lahwran/77e94ef11493d4f36c726efe030f58e4/raw/5f7a0483a9fe7928ae2cf3f786d6d35f9d7870b9/example.py) for python: ``` print("run by no-alphanum code exec") ``` example run: ``` $ python noalpha.py https://gist.githubusercontent.com/lahwran/77e94ef11493d4f36c726efe030f58e4/raw/5f7a0483a9fe7928ae2cf3f786d6d35f9d7870b9/example.py run by no-alphanum code exec $ ``` [Answer] # [Python 2](https://docs.python.org/2/), 5 alphanumerics ``` __=-~-~([]==[]) __*=__ _=__*-~-~-~__ exec('%c'*~-~-~-(__*~-~-__))%(~-~-~-_,-~_,-~-~-~-~_,-~-~-~_,-~-~-~-~-~-~_,-~-~-~-~-~-~-~-~_,' ',_+__,-~-~-~-~-~-~_,_,_,~-~-~-_,~-_-__,' ',~-~-_-__,-~-~-~-~-~-~-~_,' ',_+__,',',-~-~-~-~-~-~-~_,-~-~-~-~_+__,-~-~-~-~-~-~-~_,';',~-~-~-~-~-~-~-_,-~-~-~_+__,~-~-~-~-~-~-~-_,_-__,' ',_+__,'.',_+__,-~-~-~-~-~-~_,_,-~-~-~_,-~-~-~-~_,~-~-~-~-~-~-~-_,-~-~_,'(',-~-~-~-~-~-~-~_,-~-~-~-~_+__,-~-~-~-~-~-~-~_,'.',~-~-_-__,-~-~-~-~-~-~_,~-~-~-~-~-_,-~_+__,'[','_','=','=','_',']',')','.',-~-~-~-~-~-~_,~-~-~-~-~-~-~-_,~-~-_-__,~-~-~-~-~-~-~-~-_,'(',')') ``` [Try it online (with print not exec)](https://tio.run/##lVHbjoIwEH33K/bFFBQocivshi8hZFKhFRIFAjWuL/w6W0DRRXkwzbTTM9NzTqbVVWRlYXUdQKi3eqtEcRhGsboC2IQAK5Dbpi/orbxVdV4IBa0TtBkgXZHV/gRQ1bUyYqDJXm1888geyOttRNAX0mAL88Z@3YllSKmhcwB0mBM90SC55sUp2757@YO0/64m8337vDRZGdWMBfcv0m81JIHyqV1jYQrPCsNnDP4iOQ@QEd6iz2MZKhqYlgjug7/pzH5NH31LErXrukyIqvnG@JA3wjjkIjvvzw2rk7IQrBBGUp7wkWaXmhaYEBY4jO92TmCnDre9hFge48y0Te76zME1vWCXE2o6vk0Dzkhg@ZRZCbc58b3US22XBynxibkPMPulp@rIjOr6Bw) It helps with a bit of experience with [Symbolic Python](https://github.com/FTcode/Symbolic-Python), where alphanumerics are banned anyway. This is rather lazily golfed and could probably be a few dozen bytes shorter, but hey, this isn't [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). The 5 alphanumerics here are the `exec` and the `c` of `%c`. If we were allowed unprintables, the `%c` could be bypassed with the help of the repr operator ```. The executed format string translates to `import urllib as u,sys;exec u.urlopen(sys.argv[_==_]).read()`, which fetches the resource and executes it. ### Explanation: Python can use variables with names entirely composed of underscores, which really helps us. It also treats `True/False` as `1/0`, which means we can compose numbers entirely without alphanumerics. For example, the first part of the code does: ``` __=-~-~([]==[]) # Set __ to 3 __*=__ # Square it to 9 _=__*-~-~-~__ # Set _ to 9*12 = 108 ``` Here's where we reach the unavoidable letters. To make letter in a string, we can use `%c` in a format string to take a number and return the character with that ordinal value. We can then pass this string into the `exec` statement and voila! We can execute arbitrary code with only 5 alpha-numerics. The majority of the rest of the code is just repeating the `%c` enough times, then creating the numbers representing each letter. [Answer] # Javascript, 0 Alphanumerics This is my first answer, so hopefully I haven't accidentally broken a rule :) Here's the code before extreme obfuscation: ``` var str = prompt("Enter relative URL of code to exec:", ""); var xhr = new XMLHttpRequest(); xhr.open('GET', str, true); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { eval(xhr.responseText); } }; xhr.send(null); ``` It isn't verified, and neither is the obfuscated (and de-alphanumerized) version. I used a form of obfuscated JS which you can find [here](http://patriciopalladino.com/blog/2012/08/09/non-alphanumeric-javascript.html). The actual solution is more than 220,000 characters long. It does have to be run in a browser. Also, there are no comments in the obfuscated code, but the de-obfuscated code speaks for itself if you have JS experience. There are several online translators. It takes the input URL through a prompt. You have to run it in a web browser while on the domain that the code is on. Here's a link to the file, since pastebin lagged out after I pasted it: [Source file](https://drive.google.com/file/d/19MdTpREMScTmxHIctf19XmetqV-o9EDt/view?usp=sharing) [Answer] # [Bash](https://www.gnu.org/software/bash/), 4 alphanumerics ``` wget $@ . ${@##*/} ``` No TIO link because TIO doesn't have hostname resolution. ]
[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/75899/edit). Closed 7 years ago. [Improve this question](/posts/75899/edit) * Your program must contain all your language's keywords. Ideally, you should have each one exactly once (see Scoring). Of course, this means your language must actually have keywords, so esoteric languages are probably excluded, but just in case... * Any language used must have a dedicated Wikipedia article created more than one month ago. * The keywords in your program must be lexed as keywords and parsed as keyword statements or expressions (i.e. no containing them within strings or comments). A "keyword" is defined according to the language's specification or documentation if it has no specification, and must additionally have a defined purpose within the language (Java programmers need not include `goto` and `const`). Your language might distinguish "keywords" from "reserved identifiers" or something similar; only those lexemes designated as keywords are required. # Scoring So as not to punish languages with more keywords, your score is `l - k + 3r` Where l is the length of your program in bytes, k is the combined length of all the keywords you used, and r is the combined length of any keywords that occurred more than once. So if your language has only one keyword, `for`, and your solution is `for for for`, your score is 11 - 9 + 3(6) = 20. [Answer] # Python 3.4, 110 ``` from os import* def k(z): def c():return None;nonlocal z class F:pass global b with open(devnull)as b: while b: if 1and 0is 0:continue elif 1:0 else: for d in[]:yield not d;del d;break try:raise 1or False except:assert True finally:(lambda j:0) ``` Uses every keyword once. Note, in Python 3, `exec` and `print` are functions, not keywords. [Answer] # [Brainfuck](https://esolangs.org/wiki/Brainfuck), 0 ``` +-[]><,. ``` Score: ``` l = 8 k = 8 r = 0 l - k + 3r = 0 ``` This program takes an input from the user and then prints it. ]
[Question] [ **This question already has answers here**: [Implement Minceraft](/questions/224365/implement-minceraft) (91 answers) Closed 2 years ago. # Your task Randomly pick and print "Joe Mama" or "Joe Biden" in as little bytes as possible. ## Rules * No trailing lines, spaces, or anything else weird like that * No election fraud! Both "Joe Mama" and "Joe Biden" must have equal chaces of winning ## Prize The winner will get a spot in <https://github.com/Sid220/joe-mama-or-joe-biden>, even if that language is already there. ## Example (not code golfed) ``` var joe = Math.random() < 0.5; if (joe <= 0.5){ joe = true; } else{ joe = false; } if (joe == true) { console.log('Joe Mama'); } else { console.log('Joe Biden'); } ``` [Answer] # [Vyxal](https://github.com/Vyxal/Vyxal), ~~18~~ ~~17~~ 16 bytes ``` ‛ɾ∷«W≤ḂΠǔ«½ǐ℅"Ṅ₴ ``` [Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLigJvJvuKIt8KrV+KJpOG4gs6gx5TCq8K9x5DihIVcIuG5hOKCtCIsIiIsIiJd) Explanation: ``` ‛ɾ∷ # "Joe" «W≤ḂΠǔ« # "bidenmama" ½ # Split in half ǐ # Title Case ℅ # Random choice " # Wrap with "Joe" Ṅ # Join by space ₴ # Print without newline ``` If trailing newlines were allowed, this could be ~~14~~ 13 bytes: [Try it Online!](https://vyxal.pythonanywhere.com/#WyLhuaEiLCIiLCLigJvJvuKIt8KrV+KJpOG4gs6gx5TCq8K9x5DihIUiLCIiLCIiXQ==) [Answer] # HTML/Javascript ~~61~~ ~~60~~ ~~58~~ 49 bytes ``` <script>alert('Joe '+(new Date%2?"Mama":"Biden")) ``` -9 thanks to [Makonede](https://codegolf.stackexchange.com/users/94066/makonede) (and me being dumb) -2 thanks to [Unmitigated](https://codegolf.stackexchange.com/users/99986/unmitigated) ## HTML/Javascript, 60 bytes ``` <script>alert('Joe '+(new Date()%2?"Mama":"Biden"))</script> ``` -1 thanks to Redwolf Programs ## HTML/Javascript, 61 bytes ``` <script>alert('Joe '+["Mama","Biden"][new Date()%2])</script> ``` Haven't ever submitted anything before so not sure if I did it right [Answer] # [PHP](https://php.net/), 27 bytes ``` Joe <?=time()%2?Biden:Mama; ``` [Try it online!](https://tio.run/##K8go@P/fKz9VwcbetiQzN1VDU9XI3ikzJTXPyjcxN9H6/38A "PHP – Try It Online") Not that bad for good ole PHP NOTE: I kinda disapprove political tones in code golf. If you use my answer in the Git, please do not cite my name [Answer] # [Gol><>](https://github.com/Sp3000/Golfish), 29 bytes ``` x"amaM eoJ"H> >"nediB eoJ"H V ``` [Try it online!](https://tio.run/##S8/PScsszvj/v0IpMTfRVyE130vJw47LTikvNSXTCcLlCvv/HwA "Gol><> – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 18 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` '›¸.•GŠ‰[ö•#Ωðý™? ``` Could be 1 byte less if trailing newlines are allowed by removing the trailing `?`. [Try it online.](https://tio.run/##yy9OTMpM/f9f/VHDrkM7Dm/Qe9SwyP3ogkcNG6IPbzvcBOQpn1vp9ahlkf3//wA) **Explanation:** ``` '›¸ '# Push dictionary string "joe" .•GŠ‰[ö• # Push compressed string "biden mama" # Split it on spaces: ["biden","mama"] Ω # Pop and push a random item from this pair ðý # Join the stack with newline delimiter ™ # Titlecase each word ? # Print it without trailing newline ``` [See this 05AB1E tip of mine (sections *How to use the dictionary?* and *How to compress strings not part of the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `'›¸` is `"joe"` and `.•GŠ‰[ö•` is `"biden mama"`. [Answer] # [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 18 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py) ``` ùJoe ûma∞╕╘Ç'n+αwδ ``` [Try it online.](https://tio.run/##ASkA1v9tYXRoZ29sZv//w7lKb2Ugw7ttYeKInuKVleKVmMOHJ24rzrF3zrT//w) **Explanation:** ``` ùJoe # Push string "Joe" # Push a space character " " ûma # Push string "ma" ∞ # Double it to "mama" ╕╘Ç # Push compressed string "bide" 'n+ '# "Append an "n": "biden" α # Pair the top two values: ["mama","biden"] w # Pop and push a random item δ # Titlecase it # (after which the entire stack joined together is output # implicitly as result) ``` [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes ``` Joe ‽⪪BidenMama⁵ ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvREPJKz9VQUnTmgvCDUrMS8nP1QguyMkEyjllpqTm@SbmJirpKJhqampa////X7csBwA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: ``` Joe Literal string `Joe ` Implicitly print BidenMama Literal string `BidenMama` ⪪ ⁵ Split into substrings of length 5 ‽ Random choice of substring Implicitly print ``` [Answer] # [Retina](https://github.com/m-ender/retina/wiki/The-Language), 22 bytes ``` Biden ?)` Mama ^ Joe ``` [Try it online!](https://tio.run/##K0otycxLNPz/n8spMyU1j8teM4HLNzE3kSuOyys/VeH/fwA "Retina – Try It Online") Explanation: ``` Biden ``` Replace the empty input with `Biden`. ``` Mama ``` Replace the empty input with `Mama`. ``` ?)` ``` Random choice of one of the two replacements. ``` ^ Joe ``` Prefix `Joe` to the above. [Answer] ## Batch, 76 bytes ``` @set/ar=%random%%%2 @if %r%==1 (set/p=Joe Biden<nul)else set/p=Joe Mama<nul ``` Alternative approach, also 76 bytes: ``` @set/ar=%random%%%2 @set s=Mama @if %r%==1 set s=Biden @set/p=Joe %s%<nul ``` Explanation: ``` @set/ar=%random%%%2 ``` Set `r` equal to either `0` or `1` with equal probability. ``` @set s=Mama ``` Set `s` equal to `Mama`. ``` @if %r%==1 set s=Biden ``` But if `r` is `1`, then change `s` to `Biden`. ``` @set/p=Joe %s%<nul ``` Output `s` prefixed by `Joe` and without a trailing newline. [Answer] # [JavaScript (V8)](https://v8.dev/), 46 bytes ``` print(Math.random()<.5?"Joe Mama":"Joe Biden") ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/v6AoM69EwzexJEOvKDEvJT9XQ9NGz9ReySs/VcE3MTdRyQrMdMpMSc1T0vz/HwA "JavaScript (V8) – Try It Online") Good catch of AlanBagel and 2 byte save by arnauld # [JavaScript (V8)](https://v8.dev/), 54 bytes ``` console.log("Joe "+(Math.random()<0.5?"Mama":"Biden")) ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/Pzk/rzg/J1UvJz9dQ8krP1VBSVvDN7EkQ68oMS8lP1dD08ZAz9ReyTcxN1HJSskpMyU1T0lT8/9/AA "JavaScript (V8) – Try It Online") [Answer] # [Python 2](https://docs.python.org/2/), 57 bytes ``` import time print"Joe "+["Mama","Biden"][time.time()%2<1] ``` [Try it online!](https://tio.run/##K6gsycjPM/r/PzO3IL@oRKEkMzeVq6AoM69EySs/VUFJO1rJNzE3UUlHySkzJTVPKTYapEIPRGhoqhrZGMb@/w8A "Python 2 – Try It Online") # [Python 3](https://docs.python.org/3/), 66 bytes ``` import time print("Joe "+["Mama","Biden"][time.time()%2<1],end='') ``` [Try it online!](https://tio.run/##K6gsycjPM/7/PzO3IL@oRKEkMzeVq6AoM69EQ8krP1VBSTtayTcxN1FJR8kpMyU1Tyk2GqRED0RoaKoa2RjG6qTmpdiqq2v@/w8A "Python 3 – Try It Online") Assuming no new trailing whitespace allowed [Answer] # [Python 2](https://docs.python.org/2/), 63 bytes ``` from random import* print"Joe "+["Mama","Biden"][randint(0,1)], ``` [Try it online!](https://tio.run/##K6gsycjPM/r/P60oP1ehKDEvBUhl5hbkF5VocRUUZeaVKHnlpyooaUcr@SbmJirpKDllpqTmKcVGg9QCpTUMdAw1Y3X@/wcA "Python 2 – 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/134960/edit). Closed 1 year ago. [Improve this question](/posts/134960/edit) This challenge is as follows. (Uhoh no! Now everyone is going to use reciprocal division. Now all the answers are going to look the same and lose originality, ugh!) Given two integers multiply them, ... but you can't use the multiplication symbols "\*" and "x". As you probably know multiplication is just an extension of successive additions, so this challenge is definitely feasible, as for instance the product of 8 and 5 is five sums of 8 or eight sums of 5: 8 \* 5 = 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5, & also ... = 8 + 8 + 8 + 8 + 8 = 40 Restrictions/Conditions: 1) The two numbers are allowed to be any two integers. 2) The calculation should work on both positive and negative integers. 3) The multiplication product should be correct no matter the order in which the two integer factors are presented. 4) You cannot import any installable modules/libraries not native to the base functions of your programming language. 5) There is no need to worry about expanding the scope of either of the integer sizes as it is highly unlikely that either of the integers would overload your system memory. 6) You cannot use either of the operators "\*" or "x" as multiplication operators. 7) In case anybody asks, this is multiplication in base 10, exclusively. 8) New Restriction: One multiplication function/operators are now banned. Sorry Jonathon. Creating a new operator is fine, but using any built in one function multiplication operators are banned. Desired output is the following: ``` a x b=c ``` Again, "x" here is not to be used as an operator, just a character. So if a is 5 and b is 8, then c should be 40, and vice-versa. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins! Good luck! Finally, if you could give a brief description of how your program works, everyone will appreciate that, I'm sure. Thanks. [Answer] # J, 2 bytes ``` %% ``` *x* \* *y* = *x* / (1 / *y*) ``` %% Input: x (LHS), y (RHS) % Reciprocal of y % Divide x by 1/y ``` Also, multiplication is addition after log, then computing the power using base *e*. ## 5 bytes ``` +&.^. ``` *x* \* *y* = *e*^(log(*x* \* *y*)) = *e*^(log(*x*) + log(*y*)) ``` +&.^. Input: x (LHS), y (RHS) & ^. Natural log of x and y + Add them &.^. Apply inverse of natural log to the sum NB. e^sum ``` [Answer] # [Python 2](https://docs.python.org/2/), 31 bytes ``` lambda x,y:y and x/(1/float(y)) ``` [Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaFCp9KqUiExL0WhQl/DUD8tJz@xRKNSU/N/QVFmXolCmoaumY655n8A "Python 2 – Try It Online") Old approach was longer, but then I remembered Math!: # [Python 2](https://docs.python.org/2/), 49 bytes ``` lambda x,y:sum([x,-x][y<0]for i in range(abs(y))) ``` [Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaFCp9KquDRXI7pCR7ciNrrSxiA2Lb9IIVMhM0@hKDEvPVUjMalYo1JTU/N/QVFmXolCmoaZjq655n8A "Python 2 – Try It Online") [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), ~~12~~ 3 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) Uh turns out this works - port of [Mile's J answer](https://codegolf.stackexchange.com/a/134966/53748) ``` İ÷@ ``` A dyadic link taking the two integers **[Try it online!](https://tio.run/##y0rNyan8///IhsPbHf7//2/wX9cYAA "Jelly – Try It Online")** ### How? ``` İ÷@ - Link: a, b İ - inverse a (i.e. 1/a - note: if a is 0 this yields inf) ÷@ - divide with reversed arguments (if a was 0, this is b divided by inf, which yields 0) ``` --- ...which sure beats this: ``` Aẋ/SN¹⁸ṠSỊ¤? ``` A monadic link taking a list of the two integers and returning their product. ### How? ``` Aẋ/SN¹⁸ṠSỊ¤? - Link: list [a, b] e.g. [-7, -3] [3, -7] [7, 3] or [3, 0] A - absolute values [ 7, 3] [3, 7] [7, 3] [3, 0] ẋ/ - reduce by repetition [ 7, 7, 7] [3,3,3,3,3,3,3] [7, 7, 7] [] S - sum 21 21 21 0 ? - if: ¤ - nilad followed by link(s) as a nilad: ⁸ - chain's left argument [-7, -3] [3, -7] [7, 3] [3, 0] Ṡ - sign [-1, -1] [1, -1] [1, 1] [1, 0] S - sum -2 0 2 1 Ị - abs(v) <= 1? 0 1 0 1 N - then: negate -21 negate(0)=0 ¹ - else: do nothing 21 21 ``` [Answer] # [Ly](https://esolangs.org/wiki/Ly), 17 bytes ``` n1-<ns>[<l+>1-]<u ``` A more difficult golf than I imagined... [Answer] ## JavaScript (ES7), 14 bytes ``` (x,y)=>x/y**-1 ``` [Answer] # Brainfuck, 32 bytes ``` ,>,[-<[->>+>+<<<]>>[-<<+>>]<]>>. ``` ``` ,>, take ascii input and put it in the first and second cells [- until the second cell is zero <[->>+>+<<<]> move the first cell value into the third and fourth cells >[-<<+>>]< move the third cell to the first one again ] end loop. This layers the first value onto the fourth cell, as many times as the value in the second cell (= product of 1st & 2nd) >>. print the fourth cell ``` [Answer] # [Japt](https://github.com/ETHproductions/japt/), 4 bytes ``` /VpJ ``` [Test it](http://ethproductions.github.io/japt/?v=1.4.5&code=L1ZwSg==&input=Nywz) --- ## Explanation Same as Neil's JS solution; divides (`/`) the first integer (`U`, implicit) by the second integer (`V`) raised to the power (`p`) of -1 (`J`). [Answer] # [R](https://www.r-project.org/), 20 bytes ``` function(a,b)a/(1/b) ``` in R, `a/Inf` is `0`. Moreover, in the R, we can actually see define `*` to be this operation instead of `.Primitive("*")` which is the standard multiplication operator. The TIO link shows the old and new values and demonstrates that we can use our new `*` operator as the infix multiplication operator. [Try it online!](https://tio.run/##K/qfnFiioZ5flJmemZeYo5BbmlOSWZCTCRTNzM9TyC9ILUosyS@yUlDXtE7QSrAGq47JU9fkAvJs/6eV5iWDFGok6iRpJuprGOonaUJMzEstJ80wDQMdA00uXWMFLQVdo/8A) ### 3 Bytes: ``` %*% ``` the matrix multiplication operator. Implicitly converts numbers into matrices, so it returns a `1x1` matrix as a result, but that's stored as a length-1 vector in R, just like a single number is. OR ``` %o% ``` Which is an alias for `outer(x,y,'*')` which also computes the correct value for numbers. [Answer] # Forth, 7 bytes ( But it's a cheat. ) ``` : m * ; ( Renaming it is still using it. ) use: 10 11 m . 110 ok ``` # Forth, 37 bytes ( the suggested loop ) ``` : c 0 swap 0 ?do over + loop . drop ; Use: 2 2 c 4 ok 0 0 c 0 ok 0 1 c 0 ok 1 0 c 0 ok 1 1 c 1 ok 1 2 c 2 ok 2 1 c 2 ok 1001 2002 c 2004002 ok ``` ]
[Question] [ It's easier to put this into coding terminology, so here we go: 1. First find the average, median, mode, and range. 2. Then, put those values in another array, then find the new average, median, mode, and range. 3. Bonus -10 bytes (yeah, negative bytes, because there's already answers) for programs that can handle this many times (repeat the first steps N times with an extra parameter) 4. Then average those numbers. If there are multiple medians or modes, simply average them! ## Test cases: ``` [1, 2, 3, 4, 5] -> 2.5625 [1, 1, 1, 1, 1] -> 0.9375 [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] -> 48.5 [0, 5, 10, 50] -> 24.375 [4, 4, 8, 10, 16, 24, 100, 150, 200, 200, 250] -> 136.7045454545454545454545454545... (it's fine if there's floating-point inaccuracies) ``` As this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest code in bytes wins! [Answer] # [Vyxal](https://github.com/Vyxal/Vyxal), 28 - 10 = 18 bytes ``` (λṁn∆ṁwfṁnDvOÞMİṁn₌Gg-WW;†)ṁ ``` [Try it Online!](https://vyxal.pythonanywhere.com/#WyLhuItBIiwiIiwiKM674bmBbuKIhuG5gXdm4bmBbkR2T8OeTcSw4bmBbuKCjEdnLVdXO+KAoCnhuYEiLCIiLCIzLCBbMSwgMiwgMywgNCwgNV1cbjMsIFsxLCAxLCAxLCAxLCAxXVxuMywgWzIsIDMsIDUsIDcsIDExLCAxMywgMTcsIDE5LCAyMywgMjksIDMxLCAzNywgNDEsIDQzLCA0NywgNTMsIDU5LCA2MSwgNjcsIDcxLCA3MywgNzksIDgzLCA4OSwgOTddXG4zLCBbMCwgNSwgMTAsIDUwXVxuMywgWzQsIDQsIDgsIDEwLCAxNiwgMjQsIDEwMCwgMTUwLCAyMDAsIDIwMCwgMjUwXSJd) A horrible mess of `n`s, `ṁ`s and other letters. ## Explained ``` (λṁn∆ṁwfṁnDvOÞMİṁn₌Gg-WW;†)ṁ ( ) # first inputh times λ ;† # do to argument n: ṁ # mean of n n∆ṁwfṁ # average of medians of n nDvOÞMİṁ # average of modes of n. If it was smallest mode or first mode, this could just be ∆M ₌Gg- # range of n WW # wrap into a list ṁ # average of that ``` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), score: 14 (24 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) - 10 bonus) ``` ƒD©Åm®Ð¢ZQÏ®Zsß-)ε¸˜ÅA]н ``` First input is \$n\$, second is the list. [Try it online](https://tio.run/##AT0Awv9vc2FiaWX//8aSRMKpw4Vtwq7DkMKiWlHDj8KuWnPDny0pzrXCuMucw4VBXdC9//8yClswLDUsMTAsNTBd) or [verify all test cases](https://tio.run/##LY0xCsJAEEWvErYTvpLZ3WSzVRC8gI1FQgoFCwuxCAg5QGyV1IJgZ5NOsLHZBRtBPIMXiRMIwwzvD3/@7MrlarPu9lUqgt@hCURaSdG9mpm7@XrrWn9y12zuj67NSn8Zjz5393iffT0tvs9OTBbo8pwgoaARFWAeirnfRjAglgrEYCEVpIUiKANN0HxnELHPIibEBoZgFIxFopBYWMNBIccQj5BZ86OkVxRDagamKIQMh2ZT8Qc). **Explanation:** ``` ƒ # Loop the first (implicit) input + 1 amount of times: D # Duplicate the current list # (which will be the second implicit input-list in the first iteration) © # Store it in variable `®` (without popping) Åm # Pop and get its mean ® # Push list `®` again Ð # Triplicate it ¢ # Pop both copies, and get the count of each value Z # Push the maximum (without popping the list of counts) Q # Check which counts are equal to this maximum Ï # Only keep the values at those truthy values ® # Push list `®` yet again Z # Push its maximum (without popping the list) s # Swap so the list is at the top of the stack ß # Pop and push its minimum - # Subtract the minimum from the maximum ) # Wrap all four items on the stack into a list ε # Map over this quadruplet: ¸ # Wrap it in a list (for the fourth item; and optionally the mean) ˜ # Flatten it (in case it was already a list) ÅA # Get the average of this ] # Close both the map and loop н # Pop and push the first item (the average of the extra iteration) # (after which the result is output implicitly) ``` ]
[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 2 years ago. [Improve this question](/posts/241755/edit) Here is the program to return `[[0, 0, 0], [0, 1, 0], [0, 0, 0]]` ``` [[0]*3,[0,1,0],[0]*3] ``` [Try it online!](https://tio.run/##K6gsycjPM/6faBvzPzraIFbLWCfaQMdQxyBWB8yL/V9QlJlXopGo@R8A "Python 3 – Try It Online") Can you shorten this code? [Answer] # [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 20 bytes ``` [b:=[0]*3,[0,1,0],b] ``` [Try it online!](https://tio.run/##K6gsycjPM7YoKPqfaBvzPzrJyjbaIFbLWCfaQMdQxyBWJyn2f0FRZl6JRqLmfwA "Python 3.8 (pre-release) – Try It Online") Note that modifying the first subarray also modifies the third subarray, so this would not be suitable in that case. ]
[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 8 years ago. [Improve this question](/posts/5743/edit) There is an array of integer values to be sorted.During the sorting process, the places of two numbers can be interchanged. Each interchange has a cost, which is the sum of the two numbers involved. You must write a program that determines the minimal cost to sort the sequence of numbers. [Answer] ### Scala: ``` def minimalCostToSortArray (daArray: Array[Int]) = 0 ``` Why is the cost always zero? Because I don't change numbers at all: ``` def arrsort (a: Array[Int], pos:Int = 0): Array[Int] = { if (pos >= a.length -1) a else { if (a(pos) > a(pos+1)) { val diff = a(pos) - a(pos+1) a (pos) -= diff a (pos+1) += diff arrsort (a) } else arrsort (a, pos+1) } } ``` ]
[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 4 years ago. [Improve this question](/posts/190892/edit) Programming problem: In BotLand, Robots can understand all words of any combination of letters and letters with leading or trailing (not both) numeric value. Given a word W (string of alphanumeric). Write a function to check if W is Bot word. Don't use library functions/ regex. Example: Input: BotLand Output: Bot word Input: BotLand77 Output: Bot word Input: 1Bot2Land3 Output: Non Bot word [Answer] # [Python 3](https://docs.python.org/3/), 33 bytes ``` lambda s:1-(s[0]+s[-1]).isdigit() ``` [Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUaHYylBXozjaIFa7OFrXMFZTL7M4JTM9s0RD839BUWZeiUaahrpTfolPYl6KuqYmF7qYuTmKqCE2pSBBI5CoMVD4PwA "Python 3 – Try It Online") -8 bytes thanks to Grimy and A \_ ]
[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/8785/edit) A three-color traffic light must switch lights in the following order: red, green, yellow, red. To indicate when crossing slowly without a stop is permitted, the yellow signal may be flashed. To indicate when crossing immediately after a full stop is permitted, the red signal may be flashed. Either flash sequence may only be started after the red light is lit and must be followed with a red. All lights are initially off. All sequences must begin a red light. Lighting any light causes all other lights to turn off. No color may be repeated: e.g., red, red is not allowed. Task: Write a program that checks a sequence of light codes and determines if that sequence follows or violates the traffic light rules. Input Read from STDIN a sequence of the follow codes: R (red), Y (yellow), G (Green), P (Pause - flash red), C (Caution - flash yellow), and X (off). Each code must be separated with a space. The entire sequence is submitted by an end-of-line (e.g., pressing the Enter key.) A sequence must have no more than 15 codes in total. Winning criteria: Output Write to STDOUT an evaluation of the sequence: ACCEPT >> The entire input sequence meets all rules. REJECT >> The input sequence violates any sequence constraint; for example G Y. ERROR >> The input is malformed – undefined code, too short, too long, etc. ``` EXAMPLES: 1 - Input: R G Y R C R G Y R Output: ACCEPT 2 - Input: G Y R G Y R Output: REJECT 3 - Input: R Y G P Output: REJECT 4 - Input: R G Y Output: ERROR 5 - Input: X 8 S Output: ERROR 6 - Input: R G Y R C R P R G Y R G Y R G Y R Output: ERROR ``` You do not have to worry about the reasons listed below, they are only used a reference as to why the input strings have either been Accepted, Rejected or Erroneous. Reasons: 1. Correct 2. Doesn’t start with R 3. Invalid sequence 4. Undefined code 5. Undefined Codes e.g. X is not part of the grammar 6. The input is malformed – undefined code, too short, too long, etc. [Answer] ## Perl, 83 chars good grief, halfway through golfing this thing i realized its a code-*challenge* ``` $_=<>;chop;print/.{30}|[^RYGPCX ]|\S\S/?ERROR:s/^(R (C|P|G Y) )+R?$//?ACCEPT:REJECT ``` [Answer] ^^ Neat line ardnew, but check yourself for cases ``` 1: R G Y R P 2: R G Y C ``` This was one of the questions from the IEEE contest To determine the next light in the sequence its simply (let c = color of light) ``` (c == 'R') ? ('G', 'P', 'C') : (c == 'G') ? ('Y') : ('R') ``` Those conditions follows from the question statement * If the light is RED, the next light can only be (GREEN, PAUSE, CAUTION) * If the light is GREEN, the next light can only be (YELLOW) * Else (light is (YELLOW, PAUSE, CAUTION)) the next light is RED The first conditions follow from the fact that its always RED GREEN YELLOW The flashing lights PAUSE and CAUTION require there be a RED immediately before and after ]
[Question] [ Create A "Hello, World!" program but without any vowels. Winner is the program with the least bytes. **Rules:** * No vowels are allowed in the code. * Must print to STDOUT * Must be a full program. * Submissions are measured in Bytes Any language goes as long as there aren't any vowels Edit: Y is only a vowel if there aren't any other vowels in the same word. [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 18 bytes ``` ⍘I”)¶iτCφ(≦$χ≕G&”γ ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMpsTg1uATITNdwTiwu0VAyMjIwNDQxNzG2NLEwNDA0MzG0NDcxNbUwM1TS1FFI19S0/v//v25ZDgA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: ``` I”...” Cast compressed string `22011474394810164197455861` to integer ⍘ γ Convert to base 95 using printable ASCII Implicitly print ``` Best I could do without compression was 19 bytes: ``` ⭆Pmttw4(_wztl)℅⁻℅ι⁸ ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRCO4BEil@yYWaCgF5JaUlJtoxJdXleRoKukoOAOVJiaXpBZp@GbmlRZr@BelZOYl5mhkauooWGgCgfX///91y3IA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: Subtracts `8` from the ASCII codes of each character in the string constant. (Other values such as `2` can also be used.) [Answer] Got it, MetaGolfScript-695337743287229800148806645588258 solution is 0 bytes [Answer] # [Thunno 2](https://github.com/Thunno/Thunno2) / [Vyxal](https://github.com/Vyxal/Vyxal) (polyglots), 2 bytes ``` kH ``` [Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faMGCpaUlaboWi7I9lhQnJRdDuTBhAA) or [Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyIiLCIiLCJrSCIsIiIsIiJd) Making this a CW because it's very boring and exactly the same as the normal Hello, World! submissions in Thunno 2 and Vyxal. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) Always remember to “;ṇTry HARD ``` “;ṇṪṙẏHȦ»Ḋ ``` A full program which prints the result (also a niladic Link yielding it). **[Try it online!](https://tio.run/##ASEA3v9qZWxsef//4oCcO@G5h@G5quG5meG6j0jIpsK74biK//8 "Jelly – Try It Online")** ### How? Without the restriction, we could have the compressed string `“3ḅaė;œ»` for \$8\$ bytes. ``` “;ṇṪṙẏHȦ»Ḋ - Main Link: no arguments “;ṇṪṙẏHȦ» - compressed string = "\nHello, World!" Ḋ - dequeue -> "Hello, World!" - implicit print ``` --- #### Other \$10\$ byters (...with nothing that could be considered a vowel, like `Ȧ`) ``` “¿ṃ{+ṀH“£» - Main Link: no arguments “......“.» - list of compressed strings: ¿ṃ{+ṀH - "Hello, World" £ - "!" -> ["Hello, World", "!"] - implicit, smashing print ``` [TIO](https://tio.run/##y0rNyan8//9Rw5xD@x/ubK7WfrizwQPEW3xo9///AA "Jelly – Try It Online") ``` “Ṣc çsṢƑ»Ṗ - Main Link: no arguments “Ṣc çsṢƑ» - compressed string = "Hello, World!$" Ṗ - pop -> "Hello, World!" - implicit print ``` [TIO](https://tio.run/##y0rNyan8//9Rw5yHOxclKxxeXgykj008tPvhzmn//wMA "Jelly – Try It Online") [Answer] # [Retina](https://github.com/m-ender/retina/wiki/The-Language), 21 bytes ``` K`H1ll3, W3rld! T`d`v ``` [Try it online!](https://tio.run/##K0otycxLNPz/3zvBwzAnx1hHIdy4KCdFkSskISWh7P9/AA "Retina – Try It Online") Explanation: ``` K`H1ll3, W3rld! ``` Start with the string constant `H1ll3, W3rld!`. ``` T`d`v ``` Change `1` to `e` and `3` to `o`. [Answer] # [GolfScript](http://www.golfscript.com/golfscript/), 19 bytes ``` 'Gdkkn+Vnqkc '{)}% ``` [Try it online!](https://tio.run/##S8/PSStOLsosKPn/X909JTs7T1s@LK8wO1lBvVqzVvX/fwA "GolfScript – Try It Online") ``` 'Gdkkn+Vnqkc ' Hello world but -1 applied to each character {)}% Add back 1 to each character ``` [Answer] # NASM (linux x32), 66 bytes The source code in hexadecimal ``` 64 62 22 04 04 43 E8 0E 22 2C 30 2C 30 2C 30 2C 37 32 2C 31 30 31 2C 22 6C 6C 22 2C 31 31 31 2C 22 2C 20 57 22 2C 31 31 31 2C 22 72 6C 64 21 22 2C 31 30 2C 22 5A B1 0E 87 D1 CD 80 B0 01 4B CD 80 22 ``` Printed out it looks like this: ``` db"C�",0,0,0,72,101,"ll",111,", W",111,"rld!",10,"Z�K̀" ``` This basically encodes the following assembly: ``` add al, 4 inc ebx call _f data db "Hello, World!", 10 _f: pop edx mov cl, 14 xchg edx, ecx int 0x80 mov al, 1 dec ebx int 0x80 ``` The instruction pointer is used to make the code position independent. Unfortunately `pop ecx` corresponds to the character `Y`, so I had to add an exchange. To compile, run ``` nasm -f elf32 golf.S -o golf.o ld -m elf_i386 -o golf.out golf.o ./golf.out ``` where `golf.S` contains the source code [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 7 (or 23) [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` ”Ÿ™,‚ï! ``` [Try it online.](https://tio.run/##yy9OTMpM/f//UcPcozsetSzSedQw6/B6xf//AQ) If we want to get rid of vowels like `Ÿ` and `ï` as well, it would be **23 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)** (most likely golfable some more, though..): ``` 'H.•7¤p³mƶG•¦#`™„, s'!J ``` [Try it online.](https://tio.run/##yy9OTMpM/f9f3UPvUcMi80NLCg5tzj22zR3IObRMOeFRy6JHDfN0FIrVFb3@/wcA) **Explanation:** ``` ”Ÿ™,‚ï! # Push dictionary string "Hello, World!" # (which is output implicitly as result) ``` ``` 'H '# Push "H" # STACK: "H" .•7¤p³mƶG• # Push compressed string "jello world" # STACK: "H","jello world" ¦ # Remove the first letter: "ello world" # STACK: "H","ello world" # # Split it on spaces: ["ello","world"] # STACK: "H",["ello","world"] ` # Pop and push both separated to the stack # STACK: "H","ello","world" ™ # Titlecase the top word: "World" # STACK: "H","ello","World" „, # Push string ", " # STACK: "H","ello","World",", " s # Swap it with "World" on the stack # STACK: "H","ello",", ","World" '! '# Push "!" # STACK: "H","ello",", ","World","!" J # Join all strings on the stack together # STACK: "Hello, World!" # (after which the result is output implicitly) ``` [Answer] # [Japt](https://github.com/ETHproductions/japt), 11 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) ``` `HÁM, Wld! ``` [Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=YEjBTSwgV45sZCE&input=Cg) [Answer] # [YASEPL](https://github.com/madeforlosers/yasepl-esolang), 48 bytes ``` =d#"H"$101›#"ll"+10›-67›#" W"+67›#"rld"-78› ``` i <3 character codes ]
[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/133332/edit). Closed 6 years ago. [Improve this question](/posts/133332/edit) # Problem Build an octal calculator that can do the following operations: * Add (+) * Subtract (-) * Multiply (\*) * Divide (/) * Check is prime Counting in octal is like this with decimal ``` (Octal) (Decimal) 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 10 8 11 9 ``` and so on... So given input `a` `b` `c` * `a` being a number in octal * `b` being an operator (+, -, \*, /) not is prime * `c` being a number in octal Output the expression evaluated as `abc = Output (Is prime)` Test cases: `a=3, b='+', c=3 -> 6 (false)` `a=5, b='+', c=5 -> 12 (false)` `a=1, b='*', c=5 -> 5 (true)` `a=7, b='+', c=6 -> 15 (true)` `a=31, b='-', c=11 -> 20 (false)` `a=25, b='/', c=3 -> 7 (true)` # Rules: * The output just needs to contain the answer and a truthy/falsey value of whether it is prime so `[4,0]` is fine. * The inputs will always be a case that outputs an integer (integer division) * This is code golf so shortest answer wins [When is an octal number a prime](https://web.archive.org/web/20171214093725/http://mathforum.org/library/drmath/view/55880.html) [Answer] # Mathematica, 38 bytes ``` {a=#@@(#~FromDigits~8&)/@#2,PrimeQ@a}& ``` Anonymous function. Takes input in the form `... &[Plus, {"7", "12"}]` (with both numbers as octal strings and the operator being `Plus`, `Subtract`, `Times`, or `Divide`) and returns output in the form `{17, True}` (with the number in decimal.) Did this based on my own, possibly incorrect, interpretation of the rules; please comment if I did something wrong. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 13 bytes ``` ‚8ö`³.VDps8B‚ ``` [Try it online!](https://tio.run/##MzBNTDJM/f//UcMsi8PbEg5t1gtzKSi2cALy//834zI24NIGAA "05AB1E – Try It Online") Input format: ``` c a b ``` Output format: ``` [Is prime, 'Output'] ``` Note that strings and numbers are equivalent datatypes in 05AB1E. [Answer] # JavaScript, 82 bytes ``` (a,b,c,k=m=eval((v=0)+a+b+v+c))=>{while(k-->3)m%k||(v=1);return[m.toString(8),!v]} ``` # [JSFiddle](https://jsfiddle.net/8rt1mzcf/) Input is in octal base, output is also in octal base. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes ``` Dḅ8jVµb8V,ÆP ``` [Try it online!](https://tio.run/##y0rNyan8/9/l4Y5Wi6ywQ1uTLMJ0DrcF/P//P9rYQEfBLPb/4e0A "Jelly – Try It Online") Uses `×` for `*` and `÷` or `:` for `/` (approved by OP in chat). Argument 1: ``` [a, c] ``` Argument 2: ``` b ``` Output: ``` [Output, Is prime] ``` [Answer] # [Python 2](https://docs.python.org/2/), ~~89~~ 67 bytes *A whopping -22 bytes thanks to suggestions by Rod.* ``` n=eval(''.join(input())) print[oct(n),all(n%i for i in range(2,n))] ``` [Try it online!](https://tio.run/##FcQ9CoQwEAbQfk8xzTIzEkSFLfckYhHEn5HwJYQoePqIr3jpLnvEUCv@y@WDMLdHNIghnUVU9ZOyoYxxLgJ1PgTB12iNmYwMlD22RQYH1anWkbueHXHz1v14egA "Python 2 – Try It Online") Takes input as: ``` ['01', '*', '05'] ``` Prints a list like: ``` ['05', True] ``` [Answer] # PHP, 104 bytes ``` for(eval("\$i=\$n=octdec($argv[1])$argv[2]octdec($argv[3])|0;");--$i>1&&$n%$i;);echo decoct($n),_,$i==1; ``` Run with `-nr` or [try it online](http://sandbox.onlinephpfunctions.com/code/e7901d3f1259fa63b8ae3296bb032bf8eb6fad64). Output format: `Result_1` for primes; `Result_` for non-primes. Output for negative results is faulty; replace the `echo` part with `echo$n<0?-decoct(-$n):decoct($n),_,$i==1;` (+17 bytes) to fix. ]
[Question] [ A prime number is a positive integer that has exactly two divisors 1 and the number itself. For example number 7 is a prime since it is divisible by 1 and 7. Number 1 is not a prime since it has only one divisor. Write a program or function that produces all even prime numbers. This is a code golf challenge, shortest answer per language wins. [Answer] # [Visual Basic .NET (VBC)](http://www.mono-project.com/docs/about-mono/releases/5.12.0/#vbnet-compiler), 0 bytes They added this neat function that an empty program outputs a list of the even primes via the exit code. [Try it online!](https://tio.run/##K8ssLk3M0U1KLM5M1s1LLdEtS0r@DwQA "Visual Basic .NET (VBC) – Try It Online") [Answer] # [Noxan](https://github.com/TheSecondComing123/Noxan), 1 byte ``` 2 ``` Implicitly prints out 2. [Answer] # [brainfuck](https://github.com/TryItOnline/brainfuck), 14 bytes ``` -[>+<-----]>-. ``` `-[>+<-----]>` is a script to generate 50 (which is the ascii code of 2) from <https://esolangs.org/wiki/Brainfuck_constants#50>, and then `.` outputs it [Try it online!](https://tio.run/##SypKzMxLK03O/v9fN9pO20YXBGLtdPX@/wcA "brainfuck – Try It Online") [Answer] # [Lost](https://github.com/Wheatwizard/Lost), 11 bytes ``` v<<>> >(%2@ ``` [Try it online](https://tio.run/##y8kvLvn/v8zGxs6Oy05D1cjh/38A) or [verify that it's deterministic](https://tio.run/##y8kvLvn/v8zGxs6Oy05D1cjh////umEA). ### Explanation: **Explanation of the language in general:** Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that ***both the start position AND starting direction it travels in is completely random***. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky. A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up/north, down/south, left/west, or right/east. In Lost you therefore want to lead everything to a starting position, so it'll follow the designed path you want it to. In addition, you'll usually have to clean the stack when it starts somewhere in the middle. **Explanation of the program:** All arrows will lead the path towards the `>` on the second line. From there, the program flow is as follows: * `>`: Travel in a east/right direction. * `(`: Pop the top of the stack (and push it to the scope). This is to clean a potential 2 that was already pushed. * `%`: Put the safety 'off'. In a Lost program, an `@` will terminate the program, but only when the safety is 'off'. When the program starts, the safety is always 'on' by default, otherwise a program flow starting at the exit character `@` would immediately terminate without doing anything. The `%` will turn this safety 'off', so when we now encounter an `@` the program will terminate (if the safety is still 'on', the `@` will be a no-op instead). * `2`: Push a 2 * `@`: Terminate the program if the safety is 'off' (which it is at this point). After which all the values on the stack will be output implicitly with space separator, which in this case is just the `2`. Note that the top line could have been `v<<<<`, but that the reversed part `>>` will wrap-around to the other side, making the path shorter and therefore the performance slightly better. The byte-count remains the same anyway, so why not. [Answer] # [Malbolge](https://github.com/TryItOnline/malbolge), 8 bytes ``` D'<;:^"J ``` [Try it online!](https://tio.run/##y03MScrPSU/9/99F3cbaKk7J6/9/AA "Malbolge – Try It Online") [Answer] # [Width](https://github.com/stestoltz/Width), 3 bytes Curious and hoping to try it. Not short at all, since it's designed for [restricted-source](/questions/tagged/restricted-source "show questions tagged 'restricted-source'"). Unfortunately in Width, numbers don't have the privilege of being implicitly printed. :( ``` Gfm ``` [Try it online!](https://tio.run/##K89MKcn4/989Lff/fwA "Width – Try It Online") ## Explanation ``` G Start a string fm Codepoint 18 in the custom code page ('2') Implicit end quote Implicit print ``` [Answer] # Java 8, 4 bytes ``` v->2 ``` [Try it online.](https://tio.run/##LY2xDoMwEEN3vuLGZCBDV1T@oCxIXaoO15BWoeFA5BKpqvj2NKEslvws2yNGrMfhnbRD7@GClr4VgCU26xO1ga7YHYAW19kOEGWT0VZl8YxsNXRAcE6xbk@pKXgJD5fxkcZSmvKw6Hm19LrdAeV/tf94NpOaA6slRyxIaUHBOXl8bOkH) **Explanation:** ``` v-> // Method with empty unused parameter and integer return-type 2 // Return 2 ``` [Answer] ## [+-=](https://esolangs.org/wiki/%2B-), 3 bytes ``` ++= ``` Add the accumulator by 3, then output the number. [Answer] # [Nandy](https://github.com/EdgyNerd/Nandy), 12 bytes -2 Thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen). ``` ::#oo>oo>o>o ``` [Try it online!](https://tio.run/##y0vMS6n8/9/KSjk/3w6E7PL//wcA "Nandy – Try It Online") # Explanation ``` ::# Generate a 1 bit oo Output 1 twice > Roll the stack oo Output 0 twice >o>o Output 1 and 0 This makes the binary codepoint of ASCII 2. 110010 ``` [Answer] # [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 10 bytes ``` [S S S T S N _Push_2][T N S T _Print_as_integer] ``` Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only. `[..._some_action]` added as explanation only. [Try it online](https://tio.run/##K8/ILEktLkhMTv3/X0FBgVOBi5NLgfP/fwA) (with raw spaces, tabs and new-lines only). **Explanation in pseudo-code:** ``` Integer n = 2 Print n as integer to STDOUT ``` [Answer] # [Python 3](https://docs.python.org/3/), 7 bytes ``` exit(2) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/P7Uis0TDSPP/fwA "Python 3 – Try It Online") [Answer] # [C (gcc)](https://gcc.gnu.org/), ~~15~~ ~~14~~ 12 bytes Saved a byte thanks to [petStorm](https://codegolf.stackexchange.com/users/92069/petstorm)!!! Saved 2 bytes thanks to [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)!!! ``` a;f(){a|=2;} ``` [Try it online!](https://tio.run/##S9ZNT07@/z/ROk1DszqxxtbIuvZ/bmJmHpBXUJSZV5KmoaSaoqQDlNUEygAA "C (gcc) – Try It Online") [Answer] # [Python 3](https://docs.python.org/3/) without literals, 15 bytes ``` exit(-~-~int()) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/P7Uis0RDt063LjOvRENT8/9/AA "Python 3 – Try It Online") [Answer] # [Enlist](https://github.com/alexander-liao/enlist), 1 byte ``` 2 ``` [Try it online!](https://tio.run/##S83LySwu@f/f6P9/AA "Enlist – Try It Online") Just picked a random language on TIO and it worked. Oh well, it's another language to add to the list. [Answer] # [TrumpScript](https://github.com/samshadwell/TrumpScript), 3 bytes ``` a b ``` [Try it online!](https://tio.run/##KykqzS0oTi7KLCj5/z@RK@n/fwA "TrumpScript – Try It Online") The error message in the output contains all even prime numbers and no other numbers. Well no-one said the output couldn't include other non-numeric text. The exception message is a bit special: **Exception: Trump will ensure that 'America is great'** As a (not very much) more serious effort (without errors): # [TrumpScript](https://github.com/samshadwell/TrumpScript), 36 bytes ``` say 1000002-1000000 America is great ``` [Try it online!](https://tio.run/##KykqzS0oTi7KLCj5/784sVLB0AAEjHQhtAGXY25qUWZyokJmsUJ6UWoiUBUA "TrumpScript – Try It Online") [Answer] # [Gol><>](https://github.com/Sp3000/Golfish), 2 bytes ``` 2h ``` [Try it online!](https://tio.run/##S8/PScsszvj/3wiIAQ "Gol><> – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 1 byte ``` 2 ``` it pushes 2 into the stack and then implicitly outputs it, pretty boring [Try it online!](https://tio.run/##yy9OTMpM/f/f6P9/AA "05AB1E – Try It Online") [Answer] # [Python 2](https://docs.python.org/2/), 7 bytes ``` print 2 ``` ## Explaination prints 2 [Try it online!](https://tio.run/##K6gsycjPM/r/v6AoM69EAcgAAA "Python 2 – Try It Online") [Answer] # [Bash](https://www.gnu.org/software/bash/), 6 bytes ``` echo 2 ``` [Try it online!](https://tio.run/##S0oszvj/PzU5I1/B6P9/AA "Bash – Try It Online") [Answer] # [JavaScript (Node.js)](https://nodejs.org), 4 bytes ``` v=>2 ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/M1s7of3J@XnF@TqpeTn66RpqGpuZ/AA "JavaScript (Node.js) – Try It Online") [Answer] # [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 12 bytes ``` END{print 2} ``` [Try it online!](https://tio.run/##SyzP/v/f1c@luqAoM69Ewaj2/38A "AWK – Try It Online") [Answer] # [Lenguage](https://esolangs.org/wiki/Lenguage), 979,674,373,772 bytes # [Unary](https://esolangs.org/wiki/Unary), 2,063,923,527,196 bytes Programs consists of 2063923527196 and 979674373772 amount of characters of your own choosing. Port of [*CommandMaster*'s brainfuck answer](https://codegolf.stackexchange.com/a/203237/52210). [Try it online in brainfuck.](https://tio.run/##SypKzMxLK03O/v9fN9pO20YXBGLtdPX@/wcA) Byte-counts generated by [this program](https://tio.run/##yy9OTMpM/f9fKTQvsajSSkHJXsnORltXTyc6VskzOPvQmvhMJb/8EoXEnJz88tQUhZJ8heKSxKIShfLMkgyFRAU7pcOrLc5tqtXhUvJJzUsvTUxPBRuirWtnQ7Qh2jBD/v/XjbbTttEFgVg7XT0A) I wrote in [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands). [Answer] # [naz](https://github.com/sporeball/naz), 4 bytes ``` 2a1o ``` Simply adds 2 to the register and outputs. [Answer] # [J](https://jsoftware.com), 1 byte ``` 2 ``` ## Explanation ``` 2 NB. 2 ``` [Answer] # [Uselesslang](https://github.com/Fmbalbuena/Uselesslang), 4 bytes ``` >>. ``` (There is trailing space) [Answer] # [><>](https://esolangs.org/wiki/Fish), 3 bytes ``` 2n; ``` [Try it online!](https://tio.run/##S8sszvj/3yjP@v9/AA "><> – Try It Online") [Answer] # [CellTail](https://github.com/mousetail/CellTail), 8 bytes ``` I=2;O=N; ``` [Try it](https://mousetail.github.io/CellTail/#ST0yO089Tjs=) Explanation: * `I=2` sets the initial state to 2. * `O=N` sets the output format to numbers. I should really get around to setting up these things as flags. ]
[Question] [ For this challenge, the objective is to take a list of integers, and output the sum of every unique integer in that list, i.e. count multiples of the same integer only once. Your input will be a string in the format `"{1,2,3,4}"` with any amount of elements. The string will never have whitespace or be in a format that does not match the example above. **A list with 0 elements should return `0`.** ## Examples ``` "{1,2,3,4}" -> 10 "{5,2,5}" -> 7 "{13,13,13}" -> 13 "{-5,5,5}" -> 0 "{12,12,13,13,14,14}" -> 39 "{}" -> 0 "{3}" -> 3 ``` This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins. Good luck! [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 1 [byte](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` S ``` **[TryItOnline](http://jelly.tryitonline.net/#code=Uw&input=&args=ezEyLDEyLDEzLDEzLDE0LDE0fQ)** Since command line arguments are passed as a string to Python, it evaluates as a set\*. `S` then sums the resulting list Jelly will receive. \* except in the empty case (as pointed out by @Dennis) when `"{}"` evaluates to an empty dictionary, but this gets cast to a list of it's keys, which is an empty list. [Answer] ## Python 2, ~~21~~ 18 bytes: ``` print sum(input()) ``` [Answer] # [MATL](http://github.com/lmendo/MATL), 4 bytes ``` Ugus ``` String delimiter in MATL is `'`. [Try it online!](http://matl.tryitonline.net/#code=VWd1cw&input=J3sxMiwxMiwxMywxMywxNCwxNH0n) ### Explanation ``` U % Implicitly input string and evaluate it. Gives a cell array g % Convert to vector u % Unique s % Sum. Implicitly display ``` [Answer] ## Actually, 2 bytes ``` ≡Σ ``` [Try it online!](http://actually.tryitonline.net/#code=4omhzqM&input=InsxLCAxLCAyLCAzfSI) `≡` (`eval`) evaluates the input, which is thankfully specified in Python's set literal syntax. `Σ` then sums the set elements. [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 9 bytes ``` 0E¦¨',¡ÙO ``` [Try it online!](http://05ab1e.tryitonline.net/#code=MEXCpsKoJyzCocOZTw&input=ezEyLDEyLDEzLDEzLDE0LDE0fQ) **Explanation** ``` 0 # push 0 E # push evaluated input ¦¨ # remove brackets ',¡ # split on "," Ù # remove duplicates O # sum ``` `0E` is needed as sum doesn't work on an empty list. [Answer] ## Pyke, ~~9~~ 4 bytes ``` F )s ``` [Try it here!](http://pyke.catbus.co.uk/?code=F+%29s&input=%7B1%2C2%2C3%2C3%7D) Yes, I have to spend 3 bytes converting a set to a list because Pyke's sum function errors out on sets. The space is required because the default behavior for a for-loop in Pyke is to print out the arguments [Answer] ## JavaScript (ES6), 61 bytes ``` s=>[...new Set(s.slice(1,-1).split`,`)].reduce((s,n)=>+n+s,0) ``` Without the unreasonable input format it's only 39 bytes: ``` f=a=>[...new Set(a)].reduce((s,n)=>s+n,0) ``` The `,0` is necessary to work with an empty array. [Answer] # PHP, 34 Bytes ``` <?=array_sum(array_unique($argv)); ``` [Answer] # Octave, 29 bytes ``` @(x)sum(unique([eval(x){:}])) ``` This creates an anonymous function named `ans` can be called using `ans('{1, 2, 3}')`. [Online demo](http://ideone.com/MMGDG5) **Explanation** The `eval(x)` converts the input string into a cell array of numbers. The `[x{:}]` converts the cell array of numbers into a normal array of numbers. Then we compute the `unique` elements and `sum` the result. [Answer] # Ruby, 36 bytes ``` $><<eval(gets.scan(/-?\d+/).uniq*?+) ``` Search for all unique "integer-looking" strings in the input and join this list on the string `+`, then evaluate the resulting string and print the result. [Answer] # Mathematica, ~~8~~ 9 bytes ``` Tr@*Union ``` `Union` deletes duplicates (and sorts), and `Tr` totals a list. A rare case when Mathematica can actually compete with golfing languages! [Answer] # Perl, 28 bytes Includes +1 for `-p` Give input on STDIN ``` #!/usr/bin/perl -p s%-?\d*%$a{$&}//=$_+=$&%reg ``` Surprisingly hard to support the empty set and go below 29 bytes [Answer] ## Bash + coreutils, 38 bytes ``` bc<<<0$(tr ,}{ \\n|sort -u|paste -sd+) ``` [**Try it on ideone.com!**](https://ideone.com/Uxn6I8) **Explanation:** using `{1,2,1,4}` as test case ``` tr ,}{ \\n # replace commas and braces with newlines (\n1\n2\n1\n4\n) |sort -u # sort and print unique lines (\n1\n2\n4) |paste -sd+ # merge lines with '+' as delimiter (+1+2+4) bc<<<0$( ) # prepend '0' and calculate sum (7) ``` Note how prepending a '0' will also help to give a correct answer when the input list is empty (`{}`). **Run examples:** ``` me@LCARS:/PPCG$ ./sum_unique.sh <<< "{}" 0 me@LCARS:/PPCG$ ./sum_unique.sh <<< "{3}" 3 me@LCARS:/PPCG$ ./sum_unique.sh <<< "{-5,5,5}" 0 me@LCARS:/PPCG$ ./sum_unique.sh <<< "{12,12,13,13,14,14}" 39 ``` [Answer] # BASH + CoreUtils + sed + bc 75 68 50 bytes Saved a bunch thanks to Digital Trauma and seshoumara ``` sed '/{}/c0 s:[}{,]:\n:g'|sort -u|xargs|tr \ +|bc ``` [Answer] # [Zsh](https://www.zsh.org/), ~~41~~ 34 bytes ``` <<<$[${${(us:,:)${1/\{}/\}}// /+}] ``` ~~[Try it online!](https://tio.run/##qyrO@J@moanxPy2/SCFTQUOlWqO02ErHStNQXz@6uja2VlNDI0/bNlNTk8vGxkYlOi/2vyZXmoJ6taGOoY4REBrrmNSqg0WgFEgYiGvV/wMA "Zsh – Try It Online")~~ [Try it online!](https://tio.run/##qyrO@J@moanx38bGRiVapVqlWqO02ErHSlOl2lA/prpWP6a2Vl9fQV@7Nva/Jleagnq1oY6hjhEQGuuY1KqDRaAUSBiIa9X/AwA "Zsh – Try It Online") `${ / / }` is replacement, `${ // / }` is global replacement, `(s:,:)` splits the string on commas, `(u)` keeps the unique elements. [Answer] ## R, 51 bytes ``` s=scan;sum(unique(s(t=gsub("\\{|}|,"," ",s(,""))))) ``` [Answer] # Groovy (81 Bytes) ``` z={x->Eval.me(x.replaceAll("\\{","\\[").replaceAll("\\}","\\]")).unique().sum()} ``` Try it online: <https://groovyconsole.appspot.com/edit/5074458091978752> *28 Bytes if you Use [] as brackets...* `z={Eval.me(it).unique().sum()}` [Answer] # Bash + GNU utilities, 54 ``` eval printf '0%s\\n' $1|tr -d {}|sort -u|paste -sd+|bc ``` Input is given as a command-line parameter. Note that the input must be quoted to prevent expansion by the calling shell (this would be handy, and save some bytes, but I feel like that would be cheating a bit). The input format is mostly a [bash brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html), but it doesn't expand as we want it to for a 0 or 1 element list, so a bit more preprocessing is required before piping to `sort -u`. [Ideone](https://ideone.com/8fb9xy). [Answer] # Pyth, 3 bytes Unfortunately, the sum builtin doesn't work in Pyth with sets. I have to convert to a list first... ``` s[F ``` Explanation: ``` [ Construct list F By splatting in the elements of the input s Sum up ``` Taking input as a list-type form would actually be a byte shorter: ``` s{ ``` Which is the `s`um of the `{`de-duplicated input. [Answer] # [Perl 6](https://perl6.org), 29 bytes ``` *.comb(/<[-\d]>+/).unique.sum ``` ## Example: ``` # give the Whatever lambda a name for clarity my &code = *.comb(/<[-\d]>+/).unique.sum; say code '{1,2,3,4}'; # 10 say code '{5,-5,5}'; # 0 say code '{}'; # 0 ``` [Answer] ## C#, 103 bytes ``` (i)=>i[1]=='}'?0:Regex.Match(i,"{(.*)}").Groups[1].Value.Split(',').Select(int.Parse).Distinct().Sum(); ``` this challange its pretty pointless really [Answer] ## [ListSharp](https://github.com/timopomer/ListSharp), 134 bytes ``` STRG s=INPUT[""] AS STRG SHOW=ROWSPLIT STRG["0"+GETRANGE s FROM [2] TO [s LENGTH-1]] BY [","]<c#.Select(int.Parse).Distinct().Sum()c#> ``` ]
[Question] [ This question was profoundly inspired by [Joe Z's question](https://codegolf.stackexchange.com/questions/17005/produce-the-number-2014-without-any-numbers-in-your-source-code?answertab=active#tab-top). But, with a twist... So, now that it's almost 2017, it's time for a code question involving the number 2017. Your task is to make a program that **counts up from 0, printing each number until it reaches 2017.** without using any of the characters `012345678` or `9` in your code; and without using any variables such as the date or time or a random number. # Acceptable Output The output of your code must follow the following format: ``` [number] [number] [number] etc. ``` A number, then a line feed, then repeat. > > The shortest code (counting in bytes) to do so in any language in which numbers are valid tokens wins. > > > # Example Output: ``` 0 1 2 3 4 ... 2016 2017 ``` [Answer] ## PowerShell v2+, 15 bytes ``` ''..+[char]'ߡ' ``` UTF-8 code point `2017`, `ߡ`, functions as our upper bound. We turn it from a string into a `char` with `['']`, then to an int with `+`. The lower bound `''` is implicitly cast to `0`. Thus, this is the range operator `..` from `0` to `2017`. Default `Write-Output` prints each number with newlines between. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes ``` “¬×’ḶY ``` [Try it online!](https://tio.run/nexus/jelly#@/@oYc6hNYenP2qY@XDHtsj//wE "Jelly – TIO Nexus") Explanation: ``` “¬×’ḶY Main link. Arguments: 0 “¬×’ 2018 Ḷ Range [0..z) Y Join z by newlines ``` [Answer] ## Java, 99 bytes Hobbyist programmer here. This is my first golf so apologies if I mess things up. Of course since I wrote in Java my code is going to be very large, but I think this may be as far as Java can go. Golfed: ``` interface D{static void main(String[]z){for(int i='a'-'a';i<'ÿ'*''+'é';)System.out.println(i++);} ``` Ungolfed: ``` interface D{ static void main(String[]z){ for(int i='a'-'a';i<'ÿ'*''+'é';) //Between the seemingly empty quotes is an enquiry character with an ASCII value of 7, which has been included in the byte count and post. System.out.println(i++); } } ``` Explanation: This solution abuses the interaction Java's compiler has with chars. Since Java interprets ASCII characters as bytes, I can use that fact to do arithmetic without actually ever using a number. The y with a diaeresis ASCII 255, enquiry is 7, and the acute e is 233 (so I can have 2017 be included). Hopefully this isn't too cheaty to do! [Answer] # [APL (Dyalog APL)](http://dyalog.com), 13 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319) Requires `⎕IO←0` which is default on many systems. ``` ⍳⎕UCS'ߢ' ``` [TryAPL online!](http://tryapl.org/?a=%u2395IO%u21900%20%u22C4%20%u2373%u2395UCS%27%u07E2%27&run) `⍳` N first indices, where N is `⎕UCS` the Unicode code point of `'ߢ'` this character [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 8 bytes ``` žCžw<-Ý» ``` [Try it online!](http://05ab1e.tryitonline.net/#code=xb5Dxb53PC3DncK7&input=) [Answer] # [Labyrinth](http://github.com/mbuettner/labyrinth), 49 43 40 bytes ``` ))::+:#:*: @ ( (\"))****( { } )!: ``` [Try it online!](http://labyrinth.tryitonline.net/#code=KSk6Ois6IzoqOgpAICAgICAgICAoCihcIikpKioqKigKeyB9CikhOg&input=) [Answer] # [7](https://esolangs.org/wiki/7), 29 bytes, 78 characters Not going to win, but I had fun writing it. 7 uses a 3-bit character set that packs 8 characters into 3 bytes. Here's the program in octal encoding (which is most natural for the language): ``` 770267133177162277266362217240522405240540562240540554240524052405052405405513 ``` and here's how it looks on disk (via an `xxd` dump); looking on the right, we can verify that the file contains no digits: ``` 00000000: fc2d cb67 f392 fd6c f247 a82a 5055 0582 .-.g...l.G.*PU.. 00000010: e4a0 b05b 1415 4154 1455 0582 d2 ...[..AT.U... ``` [Try it online!](https://tio.run/nexus/7#PYrbDcAwDAL/PUVHCDiG/SdzHlUrcQidaHtQfpAZsCHSppQKEuYcxVubnWPfVTE/f/gfUcjuWg "7 – TIO Nexus") [Underload](http://esolangs.org/wiki/Underload) is the brainfuck of stack-based languages, and 7 is a variant of Underload modified to provide I/O capabilities and to reduce the size of the command set. (The command set had to be modified to allow for things like outputting mismatched parentheses.) So this is an example of how to write this program in a very primitive and low-level language. Here's how the program works: ``` 77026 ``` We start by pushing the stack element `02`, escaped once (thus it'll still appear as `02` on the stack; normally there's one level of unescaping). To push a stack element in 7, you precede it with a `7`, and enclose any parts you want to escape in `7`…`6`. ``` 7 133 17 716 22 77266 36 ( ( ) (( )) ) ``` The rest of the program is all stored in one large stack element. (In 7, there's no way to write code that runs immediately; you have to start by pushing it as a literal to the stack, then rely on it getting appended to the program implicitly when the program runs out of space.) We start by discarding the large stack element in question (`13`), then outputting the element below (`3`); that's `02`. The first output of the program sets the output format the program uses. In this case, we're using output format 0, "integers". That accounts for (and removes) the zero. The output format we're using works by counting the number of 7s and 1s in the output string, and subtracting the number of 6s and 0s, to produce the integer to output; in this case, the string `2` has no 0s, 1s, 6s, or 7s, so it outputs `0`. Finally, a trailing 2 (in this output format) produces a newline (the output would "naturally" be space-separated). After that, we push a large literal to the stack. This will eventually be used as a loop body, so we'll consider it when it runs. ``` 22 1724052240524054056 2240540554240524052405052405405 ``` Some people here may be used to [Underload numerals](https://codegolf.stackexchange.com/q/26207/62131) from a previous challenge. 7 numerals are fairly similar. In the linked challenge, the only characters used were `:` and `*`; numbers represented like that can translate into 7 directly, with `2` serving the role of `:` and `405` serving the role of `*` (note that it's actually equivalent to Underload's `~*`, but the two act identically in this context). Thus, given a number *n*, you can add 1 to it using `2*n*405`, and you can multiply two numbers by appending them to each other; the null string is 1. One thing the linked challenge *didn't* mention, though, is exponentiation. This works a little differently in 7 than in Underload, but the same basic principles are in use in each case. Additionally, in 7, you can handle addition via putting code between the `4` and `05` (something that's more verbose in Underload because you can't put code *inside* the `*`). So we can restructure this part of the program like this: ``` 2 2 17 start a new number (=1) 2405 ×2 (=2) 2 ×(1 (=1) 2405 ×2 (=2) 2405 ×2 (=4) 405 +1 (=5)) (=10) 6 end of the new number 2 ×(1 (=1) 2405 ×2 (=2) 405 +1 (=3)) (=3) 5 exponentiate (10 ^ 3 = 1000) 4 +(1 (=1) 2405 ×2 (=2) 2405 ×2 (=4) 2405 ×2 (=8) 05 ) (=1008) 2405 ×2 (=2016) 405 +1 (=2017) ``` The rest of the program is: ``` 5 13 ``` The `5` starts a loop, running the stack literal we pushed earlier 2017 times. Finally, the `13` pops the top stack element, meaning that the stack is now empty and the program ends. So what does the loop body do? Here's how it decodes: ``` 716 Append a 1 to TOS 22 Make two more copies of the TOS 77266 Append a 2 to TOS 3 Output TOS, discard top two stack elements ``` Appending a 1 will increase the numerical value (initially zero) that numeric output will see the stack as having. We make two temporary copies, and append a 2 (to provide the newline required by the question). Then we output it, discarding the temporary copies in the process. Doing this 2017 times will thus count from 1 to 2017. We outputted the 0 earlier, thus completing the program. [Answer] # ><> (Fish) 19 bytes ``` iaa,+:n:"#:"*d-=?;ao! ``` very simple, uses ascii chars to generate the number 2017 then compares to an increasing counter that gets printed. i is input but without one becomes -1 a = 10 so aa, is 1 (10 div 10) "#:" becomes (# multiply :) which makes 2030 which we take 13 (d) from to make 2017 (This number is a prime so we can't save bytes here). [Answer] ## Java, 147 bytes Call with no `cmd` args ``` class t{public static void main(String[]a){int i=a.length,j=++i,h;j+=i--;h=j*j*j*j*j;j=h*j*j*j*j*j*j-(--h);j++;for(;i<j;)System.out.println(i++);}} ``` [Answer] # MATL, ~~15~~ 11 bytes *4 bytes saved thanks to @Luis* ``` '? 'pQQ:q"@ ``` [**Try it Online!**](http://matl.tryitonline.net/#code=Jz8gJ3BRUTpxIkA&input=) [Answer] ## Python 3, 32 bytes ``` print(*range(ord('ߢ')),sep='\n') ``` [Answer] ## [(K+R)eg](https://github.com/JonoCode9374/Keg), 9 bytes ``` ߡï(.\ , ``` Explanation: ``` ߡ # Push 2017 ï # Count all the way from 0 # Due to the irritating output-without-newline: ( # Repeat the length of the stack times: . # Output the top of the stack \ ,# Output 1 newline ``` [TIO](https://tio.run/##y05N/////sLD6zX0Yrh0/v8HAA) [Answer] ## JavaScript (ES6), 52 bytes ``` for(n=x=+[],i=++x+x+''+n;n<i+i-x-x;)console.log(n++) ``` There's not much to say about it: ``` for( n = x = +[], // n = x = 0 i = ++x + x + '' + n; // i = 1 + 1 + '' + 0 = "20" n < i + i - x - x; // n < "2020" - 1 - 1 <=> n < 2018 ) console.log(n++) ``` [Answer] # [Stax](https://github.com/tomtheisen/stax), 6 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax) ``` ÇîHtUá ``` [Run and debug it](https://staxlang.xyz/#p=808c487455a0&a=1) Use packing to avoid appearance of the digits. [Answer] # [Japt](https://github.com/ETHproductions/japt) [`-R`](https://codegolf.meta.stackexchange.com/a/14339/), ~~5~~ 4 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) ``` #ߢo ``` [Test it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=I1x1MDdlMm8) [Answer] ## [W](https://github.com/A-ee/w) `n` `d`, 7 bytes ``` ♦kb-╖úÜ ``` ## Explanation Uncompressed: ``` 2018 M % Foreach in the range 1..2018: a1- % Return the current item - 1 Flags:n % Join the output with newlines ``` ``` ]
[Question] [ **This question already has answers here**: [Minecraft Mirrored](/questions/53925/minecraft-mirrored) (24 answers) [Are my eyes open or closed?](/questions/79053/are-my-eyes-open-or-closed) (7 answers) Closed 7 years ago. You are trying to guess my emotion. I will give you an adjective, as the input to the function/program. Your task is to output my emotion, either `:)` for happy, or `:(` for sad. # Details For these adjectives, you must output the happy face `:)` ``` contented delighted merry overjoyed pleased blessed chipper content convivial gleeful gratified intoxicated jolly light peppy perky playful sparkling sunny ``` For these adjectives, you must output the sad face `:(` ``` melancholy bitter somber dismal mournful blue dejected despairing despondent disconsolate distressed down downcast gloomy glum heavyhearted lugubrious morbid morose troubled bereaved ``` Other adjectives are undefined. You may output whatever you want for other adjectives. # Specs * All in lowercase. All matches regex `^[a-z]+$`. # Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest solution in bytes wins. # Tips There is a trick. [Answer] ## CJam, 9 bytes ``` ':q,"()"= ``` The "trick" is the parity of the word lengths. [Test it here.](http://cjam.aditsu.net/#code=qN%2F%7B%3AQ%3B%0A%0A'%3AQ%2C%22()%22%3D%0A%0A%5DoNo%7D%2F&input=contented%0Adelighted%0Amerry%0Aoverjoyed%0Apleased%0Ablessed%0Achipper%0Acontent%0Aconvivial%0Agleeful%0Agratified%0Aintoxicated%0Ajolly%0Alight%0Apeppy%0Aperky%0Aplayful%0Asparkling%0Asunny%0Amelancholy%0Abitter%0Asomber%0Adismal%0Amournful%0Ablue%0Adejected%0Adespairing%0Adespondent%0Adisconsolate%0Adistressed%0Adown%0Adowncast%0Agloomy%0Aglum%0Aheavyhearted%0Alugubrious%0Amorbid%0Amorose%0Atroubled%0Abereaved) ### Explanation ``` ': e# Push character ':'. q, e# Get length of input. "()"= e# Using length as cyclic index into "()", giving '(' for even lengths e# and ')' for odd lengths. ``` [Answer] # Brainfuck, 71 bytes ``` +[--------->+<]>+.>,+[[-]>[->+<]+>[<->-]<<,+]>[<<+>>-]<+++[<------>-]<. ``` Assumes that `EOF = -1`. Explaination: The first part, `+[--------->+<]>+.`, prints `:` and stores its ascii value (58) in `cell #2`. The second part, `>,+[[-]>[->+<]+>[<->-]<<,+]`, is a bit more complicated. For each character in the input, it moves the value in `cell #4` into `cell #5`, it adds one to `cell #4`, and sets `cell #4 = cell #4 - cell #5`. Basically, what this does is it changes `cell #4` into `1 - cell #4`. When every character has been read, cell #4 is `length of input % 2`. The third part, `>[<<+>>-]` adds the value of `cell #4` to `cell #2`. The last part, `>,+[[-]>[->+<]+>[<->-]<<,+]` subtracts 18, which is the difference in the ascii table from the colon and the left parentesens from `cell #2` and prints it. [Answer] # J, 15 bytes ``` ':',"0'()'{~2|# ``` `':',"0` concats `':'` with the 0-cells of the string `'()'`, making an array of `:(` and `:)`. `{~` is get with switched argument order, `2|` is the parity of the length `#` of the RHS. ``` p =: ':',"0'()'{~2|# p 'happy' :) p 'somber' :( ``` Use `(>;p)"0` to test a list of words and compare their output. [Answer] # Reng v.3.3, 12 bytes ``` ":("k2,+roo~ ``` This puts `58, 40` on the stack, gets the length of the input stack, `2,` modulos by 2, `+` adds it to the `(`, `r` reverses, `oo` outputs two characters, and `~` terminates the program. [Try it here!](https://jsfiddle.net/Conor_OBrien/avnLdwtq/) Input is like `"somber"`. I don't think we need a GIF for this ;) [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 10 bytes Code: ``` ':žuâ`¹gÉ@ ``` Dammit, also 10 bytes: `gÉ40+ç':sJ`. Uses **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=JzrFvnXDomDCuWfDiUA&input=ZGVsaWdodGVk). [Answer] # [Jelly](http://github.com/DennisMitchell/jelly), 8 bytes Code: ``` ”:³Lị“)( ``` Explanation: ``` ”: # The ":" character ³L # Get the length of the input ị“)( # Find the index of the length in the ")(" string. # Uses cyclic indexing for indices exceeding the length of the string. ``` Uses the [**Jelly-encoding**](https://github.com/DennisMitchell/jelly/wiki/Code-page). [Try it online!](http://jelly.tryitonline.net/#code=4oCdOsKzTOG7i-KAnCko&input=&args=Ymxlc3NlZA). [Answer] # MATL, ~~11~~ 10 bytes ``` 58')('jn)h ``` 1 byte saved thanks to @Luis's tip to just rely upon modular indexing rather than an explicit modulus. [**Try it Online!**](http://matl.tryitonline.net/#code=NTgnKSgnam4paA&input=Y29udGVudGVk) **Explanation** ``` 58 % Number literal (ASCII for ':') ')(' % String literal j % Explicitly grab input as string n % Compute the length of the input string ) % Index into ')(' using modular indexing h % Horizontally concatenate ':' with the result % Implicitly display resulting string ``` [Answer] # Retina, ~~21~~ ~~18~~ 14 bytes ``` (..)+ :( \(. ) ``` 3 bytes saved thanks to [Martin Büttner](https://codegolf.stackexchange.com/users/8478/martin-b%C3%BCttner). Another 4 saved thanks to [Kenny Lau](https://codegolf.stackexchange.com/users/48934/kenny-lau). [Try it online!](http://retina.tryitonline.net/#code=JShHYAooLi4pKwo6KApcKC4KKQ&input=Y29udGVudGVkCmRlbGlnaHRlZAptZXJyeQpvdmVyam95ZWQKcGxlYXNlZApibGVzc2VkCmNoaXBwZXIKY29udGVudApjb252aXZpYWwKZ2xlZWZ1bApncmF0aWZpZWQKaW50b3hpY2F0ZWQKam9sbHkKbGlnaHQKcGVwcHkKcGVya3kKcGxheWZ1bApzcGFya2xpbmcKc3VubnkKbWVsYW5jaG9seQpiaXR0ZXIKc29tYmVyCmRpc21hbAptb3VybmZ1bApibHVlCmRlamVjdGVkCmRlc3BhaXJpbmcKZGVzcG9uZGVudApkaXNjb25zb2xhdGUKZGlzdHJlc3NlZApkb3duCmRvd25jYXN0Cmdsb29teQpnbHVtCmhlYXZ5aGVhcnRlZApsdWd1YnJpb3VzCm1vcmJpZAptb3Jvc2UKdHJvdWJsZWQKYmVyZWF2ZWQ) (The first line is just to make it run for all test cases). Uses the same approach as [Martins answer](https://codegolf.stackexchange.com/a/79023/34543). [Answer] # Fuzzy Octo Guacamole, 22 bytes ``` ^!_2rm{':('0}i{':)'1}_ ``` Gets input, finds `length%2`, prints `:)` vs `:(` for on a remainder of `1` or `0`. [Answer] # Lua, ~~35~~ ~~34~~ 30 bytes ``` print(#(...)%2>0 and":)"or":(") ``` [Answer] # Jolf, ~~12~~ 11 bytes ``` +':."()"mρl ``` I ~~might (might) be~~ was able to golf it down a byte by joining the faces. [Try it here!](http://conorobrien-foxx.github.io/Jolf/#code=Kyc6LiIoKSJtz4Fs&input=InNvbWJlciI) ## Explanation ``` +':."()"mρl +': ":" + ."()" the member from "()" mρl that is the parity of the length of the implicit input ``` [Answer] # Javascript 30 bytes ``` a=>alert(a.length%2?":)":":(") ``` # Javascript return version 23 bytes ``` a=>a.length%2?":)":":(" ``` Try it out: ``` b=a=>a.length%2?":)":":(" alert(b(prompt("Please enter how you feel!"))); ``` [Answer] # JavaScript ES6, 23 bytes ``` x=>":"+"()"[x.length%2] ``` Simple anonymous function. ## Test ``` f = x => ":" + "()" [x.length % 2]; makeRow = (x, y) => t.innerHTML += `<tr><td>${x}</td><td>${y}</td></tr>`; `contented delighted merry overjoyed pleased blessed chipper content convivial gleeful gratified intoxicated jolly light peppy perky playful sparkling sunny`.split(`\n`).forEach(e => makeRow(e, f(e))); t.innerHTML += "<tr><th colspan=2>Sad cases</th></tr>"; `melancholy bitter somber dismal mournful blue dejected despairing despondent disconsolate distressed down downcast gloomy glum heavyhearted lugubrious morbid morose troubled bereaved`.split(`\n`).forEach(e => makeRow(e, f(e))); ``` ``` html { font-family: Consolas, monospace; } table { border-collapse: collapse; } td, th { padding: 10px; border: 1px solid; } ``` ``` <table id="t"> <tr> <th>Word</th> <th>Output</th> </tr> <tr> <th colspan=2>Happy cases</th> </tr> </table> ``` [Answer] ## [Labyrinth](https://github.com/mbuettner/labyrinth), 14 bytes ``` 4 1 #$ ;,98..@ ``` [Try it online!](http://labyrinth.tryitonline.net/#code=NAoxCiMkCjssOTguLkA&input=bWVsYW5jaG9seQ) ### Explanation Labyrinth primer: * Labyrinth has two stacks of arbitrary-precision integers, *main* and *aux*(iliary), which are initially filled with an (implicit) infinite amount of zeros. * The source code resembles a maze, where the instruction pointer (IP) follows corridors when it can (even around corners). The code starts at the first valid character in reading order, i.e. in the top left corner in this case. When the IP comes to any form of junction (i.e. several adjacent cells in addition to the one it came from), it will pick a direction based on the top of the main stack. The basic rules are: turn left when negative, keep going ahead when zero, turn right when positive. And when one of these is not possible because there's a wall, then the IP will take the opposite direction. The IP also turns around when hitting dead ends. * Digits are processed by multiplying the top of the main stack by 10 and then adding the digit. If the top of the stack is negative, the digit is subtracted instead. The code starts in the top left corner, with the IP moving south. The `41` simply turns the top `0` on the main stack into `41`, the character code of `)`. We now enter a 2x2 (clockwise) loop which reads one character at a time, and toggles the top of the stack between `40` (`(`) and `41` (`)`): ``` # Push the stack depth, which is 1. $ XOR the top two values on the stack, toggling between 40 and 41. , Read a character (positive value) or -1 at EOF. At EOF, we exit the loop. ; Discard the character. ``` At the end of the loop, the main stack has the correct character code for either `(` or `)` and a `-1` on top of that. The rest of the code is linear. ``` 98 Turn the -1 on top of the stack into -198. . Print the top of the stack, modulo 256. -198 % 256 == 58, the character code of ':'. . Print the top of the stack, i.e. the mouth of the emoticon. @ Terminate the program. ``` ]
[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 3 years ago. [Improve this question](/posts/219173/edit) You have to print out your username, by only using the characters in your username. Standard loopholes are forbidden This is not [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest does not win Don't modify your username please And each language be used one time [Answer] # [Swap](https://github.com/splcurran/Swap), 39 bytes ``` 'n'e'i'r'B'''O' 'r'o'n'o'Cooooooooooooo ``` [Try it online!](https://tio.run/##Ky5PLPj/Xz1PPVU9U71I3UldXd1fXQHIygeK5as75yOD//8B "Swap – Try It Online") I thought it would make sense for me to participate in this challenge, considering I have both spaces and the `'` character at my disposal. Terminates, I think, by crashing. Doesn't use the Swapping nature of the language. [Answer] # [V (vim)](https://github.com/DJMcMayhem/V), 7 bytes ``` iDingus ``` [Try it online!](https://tio.run/##K/v/P9MlMy@9tPj/fwA "V (vim) – Try It Online") Yep, I sure am. [Answer] # Charcoal, 4 bytes ``` Wezl ``` I hope I remembered how Charcoal works? [Answer] # Text, 6 bytes ``` hakr14 ``` --- Yucky bad trivial solution. Basically, every program in Text is a quine. [Answer] # [///](https://esolangs.org/wiki////), 22 bytes ``` caird coinheringaahing ``` [Try it online!](https://tio.run/##K85JLM5ILf7/PzkxsyhFITk/My8jtSgzLz0xMQNI/v8PAA "/// – Try It Online") I may have chosen the wrong username to win this :/ ]
[Question] [ Your challenge is to write a program or function to output [this](https://pastebin.com/MX3Sjirk) sequence of numbers. Output requirements: * Must contain numbers specified above * Must be in order as specified * Numbers must be delimited by whitespace Shortest code in bytes wins. [Answer] # Python, 76 bytes ``` from math import* s=2**32-5 for i in range(6499):print((s-factorial(i+1))%s) ``` [A033312](https://oeis.org/A033312). # Python, 84 bytes ``` from math import* k=s=2**32-6 for i in range(6499):s-=i*factorial(i);s%=k+1;print(s) ``` [A001563](https://oeis.org/A001563). [Answer] # [Python 3](https://docs.python.org/3/), 148 bytes ``` a=[1] n=6499 N=2**32-5 exec("a+=[a[-1]*len(a)%N];"*n) a=[i*a[i]for i in range(n)] for i in range(1,n):a[i]=(a[i]+a[i-1])%N print([N-i-1 for i in a]) ``` [Try it online!](https://tio.run/##XYxBCsIwEEX3c4pQEJLULNJqoUqukAsMsxgkakCmJXShp4/pxoWbt3j899fP9lxkrJUDegIJ02meIYbB2nFwZ0jvdNMd9wEZnSf7SqLZHCJdOysGWpUtY6b7UlRWWVRheSQthuBP@aOYyz4Nemff0A7bFawly6YxuibUr2IytX4B "Python 3 – Try It Online") Surely this can be golfed. [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 39 bytes ``` A⁻X²¦³²¦⁵σA¹φA¹κF⁶⁴⁹⁹«⁺﹪⁻σφσ¶A⁺κ¹κA×φκφ ``` [Try it online!](https://tio.run/##S85ILErOT8z5///9noWPGne/37Pj0KZDyw5tBpGPGreebwaKH9p5vg1Mndv1fg9QdNujxi2PGncC0aHVjxp3vd@5CqjzfPP5tvPNh7aBzdl1bhdE9cLD08@3ndt1vu3/fwA "Charcoal – Try It Online") ## Explanation ``` A σ Assign to s ⁻X²¦³²¦⁵ 2 ** 32 - 5 A¹φ Assign 1 to f (factorial) A¹κ Assign 1 to k F⁶⁴⁹⁹« For i from 0 to 6498 ⁺﹪⁻σφσ¶ (s - f) % s + "\n" (implicitly printed) A⁺κ¹κ k = k + 1 A×φκφ Assign f * k to f ``` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 19 bytes ``` žJ5-6499FDN>!-sDŠ%, ``` [Try it online!](https://tio.run/##MzBNTDJM/f//6D4vU10zE0tLNxc/O0XdYpejC1R1/v//mpevm5yYnJEKAA "05AB1E – Try It Online") Only checked first and last numbers. If you run it TIO will probably take a while to print them all --- Explanation ``` žJ5- # (2 ** 32) - 5; call this x 6499F # for N in 0 .. 6498. Stack entering loop: [x] D # duplicate. Stack: [x, x] N> # N + 1. Stack: [x, x, N + 1] ! # factorial. Stack: [x, x, (N + 1)!] - # subtract. Stack: [x, x - (N + 1)!] s # swap. Stack: [x - (N + 1)!, x] D # duplicate. Stack: [x - (N + 1)!, x, x] Š # cycle last three items. Stack: [x, x - (N + 1)!, x] % # modulus. Stack [x, (x - (N + 1)!) % x)] , # pop and print. Stack: [x] ``` ]
[Question] [ You are trying to guess my emotion. I will give you an adjective, as the input to the function/program. Your task is to output the state of my eyes, either `O_O` for open, or `._.` for closed. # Details For these adjectives, you must output open eyes `O_O` ``` animated breezy brisk driving enterprising fresh indefatigable industrious snappy spirited sprightly spry stalwart strenuous strong sturdy unflagging untiring ``` For these adjectives, you must output closed eyes `._.` ``` beat bored collapsing consumed distressed empty fagged faint fatigued finished jaded wasted worn ``` Other adjectives are undefined. You may output whatever you want for other adjectives. # Specs * All in lowercase. All matches regex `^[a-z]+$`. # Scoring This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest solution in bytes wins. # Tips There is a trick. The adjectives that correspond to closed eyes are all related to "tired". The adjectives that correspond to open eyes are all related to "active". [Answer] # CJam, 17 bytes ``` q1=1^'n>".O"='_1$ ``` Second letters. This would have been much more fun without any "tricks" in the test cases :/ [Try it online](http://cjam.aditsu.net/#code=q1%3D1%5E'n%3E%22.O%22%3D'_1%24&input=beat). [Answer] # JavaScript, ~~151~~ ~~123~~ ~~113~~ ~~54~~ ~~50~~ ~~47~~ 45 bytes ``` a=>["beat","bored","collapsing","consumed","distressed","empty","fagged","faint","fatigued","finished","jaded","wasted","worn"].includes(a)?"._.":"O_O" ``` Long, but it's a good start. ``` a=>/(beat|bored|collapsing|consumed|distressed|empty|fagged|faint|fatigued|finished|jaded|wasted|worn)/.test(a)?"._.":"O_O" ``` Still pretty long. ``` a=>(/beat|(bor|consum|distress|finish|jad|wast)ed|collapsing|empty|fa(gged|int|tigued)|worn/).test(a)?"._.":"O_O" ``` Eliminated some redundancy. ``` a=>/^(be|bo|c|di|en|fa|fi|j|w)\w+/.test(a)?"._.":"O_O" ``` Shorter. ``` a=>/^(a|br|dr|en|fr|i|s|u)\w+/.test(a)?"O_O":"._." ``` Switched to the other(even shorter) regex for open eyes, instead of closed ones. ``` a=>/^(a|br|dr|en|fr|i|s|u)/.test(a)?"O_O":"._." ``` Better. ``` a=>/^(a|[bdf]r|en|i|s|u)/.test(a)?"O_O":"._." ``` [Answer] # Python (2.x), ~~95~~ 94 bytes ``` import re print('O_O','._.')[len(re.findall('^a|(br)|(dr)|(en)|(fr)|i|s|u.*',raw_input()))==0] ``` Regex! If it starts with: `a` `br` `dr` `en` `fr` `i` `s` `u` then it is on the eyes-open list. **EDIT:** Removed 1 byte because I didn't know how `wc` worked on `bash`. :P [Answer] # MATL, ~~22~~ 16 bytes ``` 2)2\?'._.'}'O_O' ``` [Try it online](http://matl.tryitonline.net/#code=MikyXD8nLl8uJ30nT19PJw&input=J2ZpbmlzaGVkJw) 22 byte version, `2)'ntpr'=a?'O_O'}'._.'`. [Answer] # TI-Basic, 34 bytes ``` "._. If inString("nrpt",sub(Ans,2,1:"O-O Ans ``` 39-byte oneliner: ``` sub("._.O-O",1+3inString("nrpt",sub(Ans,2,1)),3 ``` [Answer] # [rs](https://github.com/kirbyfan64/rs), 45 bytes ``` ^(.*[^t]ed|[cbwef](?![rn]).*)$/._. [^_.]+/0_0 ``` [Live demo.](http://kirbyfan64.github.io/rs/index.html?script=%5E%28.*%5B%5Et%5Ded%7C%5Bcbwef%5D%28%3F!%5Brn%5D%29.*%29%24%2F._.%0A%5B%5E_.%5D%2B%2F0_0&input=animated%0Abreezy%0Abrisk%0Adriving%0Aenterprising%0Afresh%0Aindefatigable%0Aindustrious%0Asnappy%0Aspirited%0Asprightly%0Aspry%0Astalwart%0Astrenuous%0Astrong%0Asturdy%0Aunflagging%0Auntiring%0Abeat%0Abored%0Acollapsing%0Aconsumed%0Adistressed%0Aempty%0Afagged%0Afaint%0Afatigued%0Afinished%0Ajaded%0Awasted%0Aworn) [Answer] # GameMaker Language, 72 bytes ``` a="._."if string_count(string_copy(argument0,2,1),"nrpt")a="O_O"return a ``` ]
[Question] [ Given integers 0<x<10106 and 0<n<106, work out x(1/n) under 15 seconds(TIO or your computer), 1GB memory. You can assume the result is integer smaller than 50000. Shortest code in bytes in each language win. Sample: ``` x n result 121 2 11 123 1 123 1024 10 2 ``` A larger sample can be seen [here](https://paste.ubuntu.com/p/kGmvW5NDzw/) [Answer] # [Pari/GP](http://pari.math.u-bordeaux.fr/), 12 bytes ``` x->n->x^n^-1 ``` [Try it online!](https://tio.run/##K0gsytRNL/ifZvu/QtcuT9euIi4vTtfwf0FRZl6JRpqGoZGhpoaRpiYXQsBYU8MQWcDAyAQoYoCqxiQORJiaaWpAac3/AA "Pari/GP – Try It Online") All test cases, including the sample test case (1234^123456) and case x=10^10^6-1 & n=10^6-1, finish in under 50ms. [Answer] # [JavaScript (Node.js)](https://nodejs.org), 59 bytes ``` n=>x=>10**((x.length+Math.log10('.'+x.slice(0,99)))/n)+.5|0 ``` [Try it online!](https://tio.run/##Fc2xDoMgFEDR3a9gA2qLoFVrDI5u7q5EidIQnhHaatJ/t3a8yUnuU72VH1azhJuDUR@tPJxsNtkIfrkQsjGr3RTmuFNhZhYmwQlmON6Yt2bQhF@rilKaOBqz/MuPOuolTvOsTHku0lKUOMYcs1UvWgWSPUSRcVqjJEHdjjzYVzDg0AjaOxzQqu2Ozg4AyMIHjWYywUcDuJPq/560RKTZPS8o6Smtjx8 "JavaScript (Node.js) – Try It Online") ]
[Question] [ ### Introduction We all love StackExchange, therefore it would be essential to download all gems hidden on Stack Overflow repositories in the simplest possible way. ### Challenge/Task Your task is to write a script or program which would: 1. Fetch the list of all (within current page) repositories under [Stack Overflow GitHub](https://github.com/StackExchange) account. This can be achieved either by using direct link, or by using API callback (in JSON format). Example URLs for public access: ``` https://github.com/StackExchange https://api.github.com/users/StackExchange/repos ``` 2. Parse the list either from HTML, JSON or whatever format you would have into standard git URL format (recognised by `git`), such as: ``` https://github.com/StackExchange/foo.git https://github.com/StackExchange/foo [[email protected]](/cdn-cgi/l/email-protection):StackExchange/foo.git ``` The last one assumes that your public key is already added. 3. For each repository, `git clone` needs to be executed/invoked, for example: ``` git clone URL_to_1st_repo git clone URL_to_2nd_repo ... ``` 4. All repositories are cloned (destination doesn't matter) and should be present (not just echoed or silently processed). ### Assumptions * We're assuming all necessary standard tools are installed (e.g. `git` command) and it's in your PATH.. * Assume that `github.com` fingerprint is already added into your system, e.g. ``` ssh-keyscan -H github.com >> ~/.ssh/known_hosts ``` * Assume that your public key to access the remote repository has been added to the system (this is only required when accessing via `git@`). * We are not assuming any page or API rate limits. ### Rules & Requirements * Smallest working/reproducible code with positive score wins. * After execution, all repositories should be cloned and the script/program must exit without crashing. * You can import libraries, but they must be made before the challenge. However, you're not allowed to alias libraries to make them shorter to use in your code. All libraries/tools which are provided by [ubuntu/vivid64](https://atlas.hashicorp.com/ubuntu/boxes/vivid64) sandbox (specified below) are not necessary to mention. * All used languages or tools needs to be at least 1 year old to prevent too narrow submissions. ### Examples You can find some useful examples at: [How to clone all repos at once from Git](https://stackoverflow.com/q/19576742/55075). ### Sandboxes * if you've got [Vagrant](https://www.vagrantup.com/downloads.html) installed, try running: ``` vagrant init ubuntu/vivid64 && vagrant up --provider virtualbox && vagrant ssh ``` * [OpenRISC OR1K Javascript Emulator](https://s-macke.github.io/jor1k/) - Running Linux With Network Support However the `curl` doesn't always seems to work there (e.g. `curl -v ifconfig.co`). [Answer] # Bash, 81 bytes ``` curl https://api.github.com/users/StackExchange/repos|tr -d ,|xargs -n1 git clone ``` Git will be fed a lot of invalid repos, but it will happily clone the valid ones. [Answer] ### `sh` (92 characters) Example using Linux shell: ``` curl https://api.github.com/orgs/StackExchange/repos|grep -o 'git@[^"]*'|xargs -L1 git clone ``` And alternative version `sh`, but 94 characters: ``` grep -o 'git@[^"]*'|xargs -L1 git clone<(curl https://api.github.com/orgs/StackExchange/repos) ``` **Explanation** Downloads API page via `curl`, extracts URLs which starts with `git@`, then execute `git clone` for each match. ]
[Question] [ The aim is to create an algorithm to detect that one of the string in a small list of strings contains `%s`, `%d`, `%f`, or `%r`. All sub-string will start by '%' and be 2 characters longs. Input string will be from 1 to 500 characters with a median of around 20 characters and contain zero to multiple of the possible sub-strings. the number of string in a batch is small, 2 to 5 strings. Here's the naive python implementation: ``` SUBSTRING_TO_SEARCH_FOR = ["%s", "%d", "%f", "%r"] def any_substring_in_inputs(inputs: list[str]) -> bool: for input in inputs: for substring in SUBSTRING_TO_SEARCH_FOR: if substring in input: return True return False ``` The way the values are recovered in inputs isn't important, the algorithm is. The best execution time in a language agnostic environment and in the specified condition win. There is real world application in pylint, a static analysis tool for python. The best algorithm will be ported to it to detect string with missing formatting parameter automatically. [Answer] # [C (clang)](http://clang.llvm.org/), About 25ms for 10 million strings. ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #include <time.h> typedef struct { char* ptr; size_t len; } string; int func(const string* sa, const int n) { int found = 0; #pragma omp parallel for for (int i = 0; i < n; i++) { if (!found) { const string* s = sa + i; char* ptr = memchr(s->ptr, '%', s->len); while (ptr) { char c = *++ptr; if (c == 's' || c == 'd' || c == 'f' || c == 'r') { found = 1; break; } ptr = memchr(ptr, '%', s->len - (ptr - s->ptr)); } } } return found; } void showElapsed(struct timeval start) { struct timeval stop; gettimeofday(&stop, NULL); printf("%lu ms\n", ((stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec) / 1000); } int main() { srand(time(0)); struct timeval start, stop; int ret; int count = 10000000; puts("creating input..."); gettimeofday(&start, NULL); string* test = malloc(count * sizeof(string)); for (int i = 0; i < count; i++) { const char* txt = "rkjewj%q werhkhr"; test[i].ptr = strdup(txt); test[i].len = strlen(txt); test[i].ptr[15] = 65 + rand() % 60; } showElapsed(start); puts("test false"); gettimeofday(&start, NULL); ret = func(test, count); gettimeofday(&stop, NULL); printf("%d, expected = 0\n", ret); showElapsed(start); puts("test true"); test[count - 1].ptr[7] = 'd'; gettimeofday(&start, NULL); ret = func(test, count); gettimeofday(&stop, NULL); printf("%d, expected = 1\n", ret); showElapsed(start); } ``` [Try it online!](https://tio.run/##xVRNc9owEL37V2zJUCQwBA5JD05y6y3TW09pJqPIMlawZVeSIWmT305XEgYMdIae6oMtrZ724@1b8zEvmJqv1xdS8aJJBdwYm8pqkt9FHVMhnw9tWqr5ge3NXFpZiq61tUT2rRapyACvNtxGvyPAh@dMD6G2OvFbI3@JJwuFUEn0ASFIEkVSWcgaxQmvlLEb@xAMiyFYHEDRjU@PrhqVwi1Mk@ii1mxeMqjKGmqmWVGIAs@1x@IXiLsgPRg/N6DwMxpRfx48eq8ZkE/eLd3adqe@lm5y6NAwGIFMuqi2YjwvRclzTcz4DvcxDPqDGHCD5dPupVUuCwEEUbRj7ybQugeOvoej0ZbW/cfVgee3MDADeH@HsE731tneWg/okYfjoIHJwPgsOXn8rAVbHB99HFk6zBzSAmNPAn4CZ/SAp527sApvLWyjVcgQdRVFy0qmYPJq9bVgtREpCZoEp9UlK7CHTNtWTkdnVR2CzoV1xipL2Rv57OwxfPt@f7/JqUYd2Iz0@kUDpfmhejEQ4lATu3wygrsiXJzNlsIQZlP/oGhaXHMAbDzy0iOpr8WJt2RSkW2@mqmUuMzItOXnVH3xXinOCbK023DkyrpuhoxwjEJNjTWkx7GXFkWOSDRMJpMePc2Ij7JHSTsbVhjnvMRZrNxQu1hDP/xVRgKozfzUgPoLJ4c0jGAYMfvqYvT04kWsXvo/YSV0vsh1b6cYl8aDfJwEyWHctKkJXqPHEKc9D8HFXyDo5WF29Yiw6yvsoO8ChT5cT5M9LXZV52TWodYzk7HCiHM5xbZhSP93dJfjwA79N4mmMYjXWnAr/E/TixUdt207I2cU2DZlz0jo6hhmgZkvjhj8zfy3omZnFPWxXv8B "C (clang) – Try It Online") [Answer] # [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), takes about 150ms for 1 million lines of input *Edit: messed-up the initial timing by 20x. Sorry.* ``` /%[adfs]/ ``` [Try it online!](https://tio.run/##S0oszvifWJ6toO7k6u7pV52WX6RhnWljaAAG1pna2prVBUWZeSUKSolJySmpaekZmVmqKdk5uXn5BYVFSrW16gp2CiWpxSV6JRUlXCWZuakKIONi/qvrq0YnpqQVx@qrA3kwFUDF@impZfp5pTk5/wE "AWK – Try It Online") Outputs the line itself (truthy) if it contains `%a`,`%d`,`%f` or `%s`. Outputs nothing (falsy) if it doesn't. This could be considered a baseline answer: I'm assuming that the regex matching is pretty-well optimized, and [AWK](https://www.gnu.org/software/gawk/manual/gawk.html) doesn't add much overhead onto it (as is probably apparent from the rather minimal program). Note that this is 10x faster on my MacBook with solid-state storage than on [Try it online!]. [Answer] # Python 3, about 3 microsecs for 1000 strings ``` lambda x:bool([y for y in x if bool([z for z in ["%s", "%d", "%f", "%r"]if z in y])]) ``` I don't have the time right now to check for a million strings. [Answer] don't short change `awk` - using a `12.5 mn rows` uncompressed `.txt` test file spanning `1.85 GB`, filled to the brim with multi-byte `UTF-8` characters — (`349,725,658` multi-byte `Unicode` code points to be exact). ``` rows = 12494275. | UTF8 chars = 1285316715. | bytes = 1983544693. ``` `awk` finished scanning in `887 ms` (and keep in mind that's inclusive of actually reading `/dev/stdin` instead of just spinning test cases within the program itself) ``` Sun Dec 18 23:26:35 2022 1671423995.300214000 in0: 219MiB 0:00:00 [2.15GiB/s] [2.15GiB/s] [>] 11% ETA 0:00:00 out9: 1.36KiB 0:00:00 [1.58KiB/s] [1.58KiB/s] [<=> ] in0: 1.85GiB 0:00:00 [2.16GiB/s] [2.16GiB/s] [========>] 100% ( pvE 0.1 in0 < "${m3t}" | mawk2 '/%[dfrs]/'; ) 0.58s user 0.44s system 115% cpu 0.887 total rows = 7. | UTF8 chars = 1086. | bytes = 1388. Sun Dec 18 23:26:36 2022 1671423996.195609000 ``` ]
[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/55027/edit). Closed 8 years ago. [Improve this question](/posts/55027/edit) There is an app called [Hard Puzzle](https://www.youtube.com/watch?v=CQ5cw33sYH4) which is a game where there is a red circle, and you have to fill all of the surface area with five smaller white circles[![The Challenge](https://i.stack.imgur.com/RcrYZ.png)](https://i.stack.imgur.com/RcrYZ.png) it may seen easy, but it's harder than it looks (it just takes a while to figure out). The circle dimensions change from device to device in the image above the red circles area is `41990 pixels` although on my device it is `40496 pixels` this is not important though. So the challenge is to create the fastest algorithm (in any language) that solves this puzzle, by outputting the coordinates of where each white circle should be. Puzzle info: Red circle area = `40496 pixels`. each white circle's area = `15656 pixels (38.661% of red circle)` Your time starts now there is 3 days for completion of the task **GO!!** [Answer] ## Python 2.7, runs almost instantly (0.02 seconds on my laptop) ``` import math, cProfile def optimize(): _WHITE_SURFACE = 15656 white_radius = math.sqrt(_WHITE_SURFACE/math.pi) print "Assuming the red circle has its centre at (0,0), place the white circles at (x,y):" for i in range(5): print " * Circle {0}: ({1:.5f}, {2:.5f})".format(i+1, white_radius*math.cos(i*math.pi/2.5), white_radius*math.sin(i*math.pi/2.5)) cProfile.run("optimize()") ``` ]
[Question] [ **This question already has answers here**: [Obfuscated Hello World](/questions/307/obfuscated-hello-world) (145 answers) Closed 10 years ago. The challenge is to write the string `hello world` to your processes standard output, using as few characters of code as possible. The following restrictions apply: * The following words may not appear anywhere in the code in any casing (this includes as part of another word) 1. Console 2. Debug 3. Write 4. Print 5. Line 6. Put * Your code must compile as C# 4/4.5 * No external libraries are permitted. * Your process may not spawn any new processes. A working (but not necessarily the shortest) solution will be provided after a number of answers have been provided. The winner is the author of the shortest code by character count that satisfies the above criteria. [Answer] # 75 chars New answer, new approach. ``` class M{static void Main(){System.\u0043onsole.\u0057rite("hello world");}} ``` It looks like you can hide every character with a `\uXXXX` sequence. Which makes this thing... Easy. [Answer] Ok, I try my luck: ## 118 chars ``` class M{static void Main(){System.Type.GetType("System.\x43onsole").GetMethods()[78].Invoke(0,new[]{"hello world"});}} ``` Based on [this](https://codegolf.stackexchange.com/questions/5550/shortest-hello-world-program-with-no-semi-colons/5560#5560) solution. [Idone](http://ideone.com/IFZHrF) As noted in the original answer, the index of the Write method might be different on your system. [Answer] Here's my current best that runs anywhere: ## 158 Characters ``` using System;class M{static void Main(){Type.GetType("System.\x43onsole").GetMethod("\x57rite\x4cine",new[]{typeof(string)}).Invoke(0,new[]{"hello world"});}} ``` `.Invoke` ignores the first param entirely if its a static method, so you can use `0` instead of `null` to save 3 characters. Additionally, a variation that bans the use of the `\` character: ## 234 Characters ``` using System;using System.Linq;class M{static void Main(){Func<string,string>f=(i)=>new string(i.Reverse().ToArray());Type.GetType(f("elosnoC.metsyS")).GetMethod(f("eniLetirW"),new[]{typeof(string)}).Invoke(0,new[]{"hello world"});}} ``` [Answer] # 183 chars Without reflection "cheats"! (but using the deprecated overload of FileStream to avoid using SafeFilePointer) ``` using System;using System.IO;public class M{static void Main(){new MemoryStream(Convert.FromBase64String("SGVsbG8gV29ybGQ=")).CopyTo(new FileStream(new IntPtr(-11),(FileAccess)2));}} ``` ]
[Question] [ Write code to generate a PDF file containing 6 bingo cards. Winner is the one that uses the shortest code and needs no actions except for installing a library and running the code. (No Save As PDF). Rules are as follows. * The generated PDF file should display accurately in Adobe's PDF reader, Google Chrome and Moxilla Firefox. * Page size should be either Letter or A4. * Cards should be arranged in 3 rows and 2 columns. * Each card should be 3 inches in width and height. * Each card should contain numbers 1 to 25 in random order, arranged in 5x5 squares. The numbers in all 6 cards should be generated independently. * Text size should be 20 points. * Text font should be Helvetica, Arial, Calibri or Open Sans. Text should be centered in each cell. * The bingo cards should have borders with lines having thickness either 0.5 or 1 points. * You can use a pre-existing, publicly available library or package to create a PDF file but the code to generate and arrange bingo cards should be your own. * These is a margin of 20% allowed in each dimension, but all cards should be strictly equal in size. # Reference Answer Install `reportlab` using `pip install reportlab` ``` from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter from random import shuffle my_canvas = canvas.Canvas("Bingo Cards.pdf", pagesize=letter) my_canvas.setLineWidth(1) my_canvas.setFont('Helvetica', 20) a = [i for i in range(1, 26)] for row in range(0, 3): for col in range (0, 2): shuffle(a) rowplace = 252*row colplace = 276*col my_canvas.line(60+colplace, 36+rowplace, 276+colplace, 36+rowplace) my_canvas.line(276+colplace, 36+rowplace, 276+colplace, 246+rowplace) my_canvas.line(60+colplace, 36+rowplace, 60+colplace, 246+rowplace) my_canvas.line(60+colplace, 246+rowplace, 276+colplace, 246+rowplace) for grid in range(0, 5): gridplace = grid*43.2 my_canvas.line(60+colplace, 36+rowplace+gridplace, 276+colplace, 36+rowplace+gridplace) my_canvas.line(60+colplace+gridplace, 36+rowplace, 60+colplace+gridplace, 246+rowplace) for i in range(0, 5): my_canvas.drawCentredString(81.6+colplace+gridplace, 47.6+rowplace+i*43.2, str(a[i+5*grid])) my_canvas.save() ``` The result is shown in the following image. [![Sample bingo cards PDF](https://i.stack.imgur.com/faqrp.png)](https://i.stack.imgur.com/faqrp.png) [Answer] # [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 380 bytes Requires `reportlab`. Install `reportlab` using `pip install reportlab`. Default A4 pagesize, the margin on the dimensions allows for the rounding on the cards' positions. Save the pdf file as "b". ``` from reportlab.pdfgen import canvas import random b=canvas.Canvas('b') b.setLineWidth(1) b.setFont('Helvetica',20) n=list(range(25)) w=216 d=43 for y in(48,313,577): for x in(54,325): random.shuffle(n);b.lines([(x,y,x+w,y),(x,y,x,y+w)]) for i in range(25):f,g=x+d*(i%5),y+d*(i//5);b.lines([(x,g+d,x+w,g+d),(f+d,y,f+d,y+w)]);b.drawCentredString(f+22,g+12,str(n[i]+1)) b.save() ``` --- # [Python 3.8 (pre-release)](https://docs.python.org/3.8/), fully parametrized, 551 bytes Default A4 pagesize. All the dimensions are parametrized: * font size * numbers in each card * number of cards in the page, arranged in rows and columns * size of card Save the pdf file as "b". ``` from reportlab.pdfgen import canvas from reportlab.lib.units import inch import random b=canvas.Canvas('b') b.setLineWidth(1) t=20 b.setFont('Helvetica',t) k=25 q=int(k**.5) n=list(range(k)) r=3 c=2 w=3*inch h=3*inch d=w/q e=h/q o=(b._pagesize[0]-w*c)/(c+1) v=(b._pagesize[1]-h*r)/(r+1) for y in range(r): y=y*(v+h)+v for x in range(c): x=x*(o+w)+o;random.shuffle(n);b.lines([(x,y,x+w,y),(x,y,x,y+h)]) for i in range(k):f,g=x+d*(i%q),y+e*(i//q);b.lines([(x,g+e,x+w,g+e),(f+d,y,f+d,y+h)]);b.drawCentredString(f+d/2,g+(e-t)/2,str(n[i]+1)) b.save() ``` --- *Code with comments* ``` from reportlab.pdfgen import canvas from reportlab.lib.units import inch import random # pdf canvas, default A4 b=canvas.Canvas('b') b.setLineWidth(1) t=20 b.setFont('Helvetica',t) # numbers in each card k=25 # numbers in cards are arranged in perfect squares q=int(k**.5) n=list(range(k)) # cards in page, arranged in rows and columns r=3 c=2 # width and height of cards w=3*inch h=3*inch # size of cells d=w/q e=h/q # spacing between cards o=(b._pagesize[0]-w*c)/(c+1) v=(b._pagesize[1]-h*r)/(r+1) # loop on rows in page for y in range(r): # bottom position of card y=y*(v+h)+v # loop on columns in page for x in range(c): # left position of card x=x*(o+w)+o # randomize numbers random.shuffle(n) # draw the bottom and left line of card b.lines([(x,y,x+w,y),(x,y,x,y+h)]) # loop on numbers for i in range(k): # orizontal and vertical position of the lines # as offset from the initial position of the card f,g=x+d*(i%q),y+e*(i//q) # draw lines b.lines([(x,g+e,x+w,g+e),(f+d,y,f+d,y+h)]) # draw number as text, centered in the cell b.drawCentredString(f+d/2,g+(e-t)/2,str(n[i]+1)) # save pdf canvas as file b.save() ``` ]
[Question] [ Using the shortest JS (ES5) code possible, as measured in number of characters, gather all the ids on a page for `foobar` elements into a comma-delimited string. For example: ``` <div> <foobar id="456"></foobar> <foobar id="aaa"></foobar> <foobar id="987"></foobar> <div> ``` Should give `"456,aaa,987"` You cannot use ES6 or any libraries. The `foobar` elements will not ever be nested. My current shortest solution is ``` [].map.call(document.querySelectorAll("foobar"),function(a){return a.id}).join() ``` Can anyone beat it? [Answer] I don't *think* it's going to get shorter than this: ``` [].map.call(document.querySelectorAll("foobar"),function(a){return a.id})+"" ``` Hopefully someone can prove me wrong! ]
[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/259321/edit). Closed 11 months ago. [Improve this question](/posts/259321/edit) Write a program that has at least one byte that, when run, does absolutely nothing. I thought this would be done by now, but I can't find any other challenges like this. How to tell if it does nothing: * No variables are declared * Nothing is returned * Input does nothing * You could run a program after it and it would run normally * It's like you never ran it in the first place That's it. [Answer] # Polyglot, 1 byte ``` ``` Just a newline. This program does nothing in many languages, including [JavaScript](https://tio.run/##y0osSyxOLsosKNHNy09J/Q8EAA "JavaScript (Node.js) – Try It Online"), [Python 3](https://tio.run/##K6gsycjPM/4PBAA "Python 3 – Try It Online"), the list goes on ]
[Question] [ So what might be the shortest language for this simple task? ## Task: You are given an input of type `String` - the string is a `valid` hexadecimal number (`[0-9A-F]`). Convert it to a decimal number and print it to the console. ## Tests: ``` HEX -> DEC 1 -> 1 98 -> 152 539 -> 1337 1337 -> 4919 A5F9 > 42489 F -> 15 ``` ## Win Condition: This is code golf - shortest code wins. ## Rules: * You **must** take the input(like function parameter) as String. * You **must** return the result as String. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 1 byte ``` H ``` [Try it online!](https://tio.run/##MzBNTDJM/f/f4/9/S1cA "05AB1E – Try It Online") --- Am I missing something? I feel like... I feel like I am. --- If "print as a string" implies "surround result with quotes": # [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes ``` H'".ø ``` [Try it online!](https://tio.run/##MzBNTDJM/f/fQ11J7/CO//8tXQE "05AB1E – Try It Online") --- 05AB1E is based in Python, so it doesn't really matter if it's a string, integer or whatever; `H` will convert an integer, a string, a Ferrarri or 27 gnomes on patrol into hex. Given, the latter two aren't valid, it will error upon trying to execute or return the original string with no function applied. [Answer] # [JavaScript (Node.js)](https://nodejs.org), 18 bytes My first JS golf! ``` x=>''+eval('0x'+x) ``` [Try it online!](https://tio.run/##HYvRCsIgFEDf/ZGrrKQxRi3YoJdBnyF6DUOupm4Mom@31svhcOA81aqyTi6WIwWD1Y51GyeABlflOZw2aDZRE74Wl5BDQmW8IwQh9c8L3qlgskojfzuKS7nGFDTmLHMxjj5CBuLwPw47x0kHysGj9OHBLd@bEKK2bLiwvhtY23Vnduvngc1f "JavaScript (Node.js) – Try It Online") Just prepends `0x` to the input and evaluates that, since it then represents a hexadecimal number in JS. Finally, we need to concatenate the empty string to convert to string. [Answer] # [Python 2](https://docs.python.org/2/), 20 bytes ``` lambda s:`int(s,16)` ``` [Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaHYKiEzr0SjWMfQTDPhf0ERkKOQpqFuaGxsrq75HwA "Python 2 – Try It Online") [Answer] # [J](http://jsoftware.com/), 6 bytes ``` ":@dfh ``` [Try it online!](https://tio.run/##TZDBToQwEIbvPMXIwS6Jkt3FjS5Gg5pwMh72atQUmLJVaLGUZPfiq@MUUPbQmX@mk@/PzGfvh8AE3MXA4AKWENO7DOFp95z2fpwUYt8H3stjCAZ5wbMKwR4b1AJEp3IrtfKmmggLlmldIVfslrXWSFWSkMpiiYaUqDS3lHNdNxUeSGX6gIXLslRdTcJwh@SVAzTctAgnxLFRSYvmdGI2mBp/PlM52/0jR9f2WGfagSbkepZXLIBG5l8/sIb3EKKzeOl5hXVLvsErYL7XyeK70xbpaAxkC3y433iLwPMstsP0MMmY/5EUNhEUxq/z8B7Yivy2NxQ20ZbiKoquKT1sUlelrP8F "J – Try It Online") (Contains a test suite, including type checking the parameters and the return value.) This is pretty simple: ``` ":@dfh dfh obtain *d*ecimal *f*rom *h*ex @ then ": format the result (cast to string) ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes ``` ⁾0x;ŒVṾ ``` This is a monadic link that takes a string as argument and returns a string. [Try it online!](https://tio.run/##y0rNyan8//9R4z6DCuujk8Ie7tz3/1HDHEMgtrQAEqbGliCusbE5kHI0dQPx3B41zD3c/qhpTeR/LgA "Jelly – Try It Online") ### How it works ``` ⁾0x;ŒVṾ Monadic link. Argument: s (string) ⁾0x; Prepend "0x" to s. ŒV Eval as Python code. This returns the result as an integer. Ṿ Uneval; turn the integer into its string representation. ``` [Answer] # [JavaScript (Node.js)](https://nodejs.org), ~~20~~ ~~15~~ 14 bytes Thanks to l4m2 for catching my stupid mistake and saving me a byte. :) ``` x=>'0x'+x-0+'' ``` [Try it online!](https://tio.run/##HcvRCoIwFIDh@z2Fd2fDFEWiLCZ0I/QYY57FQnZsm2GIz76ym5/v5n@qtwra2ykWjgZMRqZFdlAtkC9FlQMkj6/ZeuTgUQ2jdQii1D9HvLuI3iiNfLVumuNl8qQxhDLEwbpNlOQ4/I/DXtmtJA3fKa6aXKARy5EePH4mJJNRDhnkJDaRatae2bFpWd00J3Y79i3rvw "JavaScript (Node.js) – Try It Online") # [JavaScript (Node.js)](https://nodejs.org), 15 bytes ``` x=>'0x'+x-[]+'' ``` [Try it online!](https://tio.run/##HcvRCoIwFIDh@z2Fd2djKYlIWSh0I/QM0cWYx1jIztpmGOKzW3bz8938T/VWQXvjYmqpw7Wv16luYD@BnNLbXQKsHl@j8cjBo@oGYxFEpn@OeLURfa808tlYN8aT86QxhCzEzthFZGQ5/I/d1rqZqe75RnHWZAMNmA304PHjkPqEJCQgSSxizVl1ZGVRsbwoDuxSthVrvw "JavaScript (Node.js) – Try It Online") # Original 20 bytes ``` l=>''+parseInt(l,16) ``` [Try it online!](https://tio.run/##HYtRC8IgFEbf/SMqLWGMVRs46GXQzxC9C0OudnW9RL/dspePw@F8D/My2ZJP5YjRQd10DXrh/JAMZbhhEaHrT7ISPHdPIDiBccEjcKnsj0trgDZjQbw9pr3MiaKFnFUuzuNHqoiC/x9dW73YiDkGUCHexSaak1LWnk0XNg4T64fhzK7jOrH1Cw "JavaScript (Node.js) – Try It Online") [Answer] # [><>](https://esolangs.org/wiki/Fish), 23 bytes ``` 0l1=?n88+*{'0'-:a)7*-+! ``` [Try it online!](https://tio.run/##S8sszvj/3yDH0NY@z8JCW6ta3UBd1ypR01xLV1vx////usWJpmmWAA "><> – Try It Online") If the hex can be contain lowercase letters instead of uppercase, we can do it in 17 bytes: ``` 0l1=?n88+*{e0p +! ``` [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 6 bytes ``` I⍘↧S¹⁶ ``` [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwymxODW4BMhP1/DJL08tSgbyNTzzCkpLoKKamjoKhmaamprW//87mrpZ/tctywEA "Charcoal – Try It Online") Link is to verbose version of code. Save 1 byte if the input can be in lower case. Charcoal doesn't automatically convert numbers to decimal on output, so the cast operator is necessary anyway. Explanation: ``` S Input string ↧ Lower case ¹⁶ Literal 16 ⍘ Base conversion I Cast to string Implicitly print ``` [Answer] # [Haskell](https://www.haskell.org/), ~~24~~ ~~23~~ 22 bytes ``` show.abs.read.("0x"++) ``` Thanks to @user9549915 for saving a byte [Try it online!](https://tio.run/##y0gszk7NyfmfZhvzvzgjv1wvMalYryg1MUVPQ8mgQklbW/N/bmJmnoKtQm5igW@8gkZBaUlwSZFPnl6apkK0kqGSjpKlBZAwNbYEkobGxuZAyk0p9v@/5LScxPTi/7rJBQUA "Haskell – Try It Online") [Answer] # Java 8, 24 bytes ``` s->Long.valueOf(s,16)+"" ``` Try it online [here](https://tio.run/##lY5NC4JAEIbP669YPLlUgkkfIgURRIeiQ8fosOmoW7Yr7ipF@NtN@yA77ml4Z@Z5Zs60pAORAT@HlzorTikLcJBSKfGWMo4fBmJcQR7RAPAabkvBS8ibRjtBe5UzHuMEbsMQAusXiW@gykAfn1RUNaUULMTXxvpZPBwxzWNJXqo/d9INM1zLwXwjeGyXNC1gF1my74xJzzT9GiG//eMuFVxtUSg7a8wq5VZXYX8fNB2TEC3Am@oSI9fTRRzXnegyi9FK@87qDVRGVT8B). [Answer] # Excel, 14 bytes ``` =0&HEX2DEC(A1) ``` Concatenates a leading `0` to convert to String. I.e. `042489` --- # Excel, 20 bytes ``` =TEXT(HEX2DEC(A1),0) ``` Naive solution. --- Format both outputs verified as String (`=T(B2)`) [Answer] # Pyth, 5 4 bytes `iz16` Parses input as a hex number and returns the base 10 equivalent. [Answer] # [Stax](https://github.com/tomtheisen/stax), 3 bytes ``` i|H ``` [Run and debug it](https://staxlang.xyz/#c=i%7CH&i=1%0A98%0A539%0A1337&m=2) `i` ensures that the input doesn't get automatically evaluated as an integer, and `|H` converts from/to hexadecimal. The link above is for the online interpreter, but the language really does use `stdin` and `stdout`. The C# implementation of the language does this, which is available from the repository above. [Answer] # [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 5 bytes ``` 16i?p ``` [Try it online!](https://tio.run/##S0n@/9/QLNO@4P9/N1NXAA "dc – Try It Online") Rather trivial. If input really needs to be a *string* vs. the language's natural hex input, then `16i?xp` [takes care of that in 6 bytes](https://tio.run/##S0n@/9/QLNO@ouD//2g3U9dYAA "dc – Try It Online"). [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes ``` ØHiЀɠ’ḅ⁴Ṿ ``` [Try it online!](https://tio.run/##AUIAvf9qZWxsef//w5hIacOQ4oKsyaDigJnhuIXigbThub7/wqLhuYQkNsKhyKfigbj/MQo5OAo1MzkKMTMzNwpGCkE1Rjk "Jelly – Try It Online") ## How it works ``` ØHiЀɠ’ḅ⁴Ṿ - Main link, no arguments ØH - Yield the string “0123456789ABCDEF”. Call that H ɠ - Read a line from STDIN, e.g. “A5F9”. Call that A Ѐ - For each character in A i ’ - Get the 0-based index of that character in H ⁴ - Yield 16 ḅ - Convert from base Ṿ - Convert to string ``` [Answer] # [Ruby](https://www.ruby-lang.org/), 14 bytes ``` p gets.to_i 16 ``` [Try it online!](https://tio.run/##KypNqvz/v0AhPbWkWK8kPz5TwdDs/383AA "Ruby – Try It Online") [Answer] # [APL (Dyalog)](https://www.dyalog.com/), 13 bytes ``` ⍕16⊥(⎕D,⎕A)⍳⊢ ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OA5KPeqYZmj7qWagCFXXSAhKPmo97Nj7oW/f@fpqBubGKqzgWkHU3dLMEMN3UA "APL (Dyalog Unicode) – Try It Online") [Answer] # [Julia](http://julialang.org/), 23 bytes ``` !s=dec(parse(Int,s,16)) ``` [Try it online!](https://tio.run/##yyrNyUw0@/9fsdg2JTVZoyCxqDhVwzOvRKdYx9BMU/N/QVFmXklOnoaikrGppZImF4LvaOqGKuCmpPkfAA "Julia 0.6 – Try It Online") `dec` appears to be shorter than `repr` or `string`. [Answer] # Japt, 4 bytes Outputting as a string doubles the byte count! ``` nG s ``` [Try it](https://ethproductions.github.io/japt/?v=2.0a0&code=bkcgcw==&input=Ijg4ODg4ODg4IgotUQ==) [Answer] ## Batch, 15 bytes ``` @cmd/cset/a0x%1 ``` If input via command-line argument is unacceptable, then for 26 bytes: ``` @set/ph= @cmd/cset/a0x%h% ``` [Answer] # [R](https://www.r-project.org/), 27 bytes ``` paste(strtoi(scan(,""),16)) ``` [Try it online!](https://tio.run/##K/r/vyCxuCRVo7ikqCQ/U6M4OTFPQ0dJSVPH0ExT878hl6UFl6mxJZehsbE5l9t/AA "R – Try It Online") `strtoi` will always return a number of type `integer` which is a signed 32-bit integer type, and `paste` implicitly converts to `character`, as required. [Answer] # WinDbg, 15 bytes ``` .printf"%d",$u0 ``` Input is done by first setting the pseudo-alias `$u0` with the input string and then running the code (eg- to set pseudo-alias: `r$.u0=a5f9`). Prints the input, conversion from hex to decimal is implicit. How it works: ``` .printf"%d", $$ Prints a decimal $u0 $$ The decimal to print ``` If the extra sugar that WinDbg prints when evaluating an expression is allowed: ## WinDbg, 4 bytes ``` ?$u0 ``` How this one works: ``` ? $$ Evaluates an expression $u0 $$ The expression to evaluate ``` This one would have output like this (for input= A5F9): ``` Evaluate expression: 42489 = 0000a5f9 ``` [Answer] # C# .NET, 34 bytes ``` s=>System.Convert.ToInt32(s,16)+"" ``` I have the feeling this is overly long, but the alternative `s=>int.Parse(s,System.Globalization.NumberStyles.HexNumber)+""` is even worse.. [Try it online.](https://tio.run/##jcxBC4IwGMbxu5/iZaeNTLBhJaUQgRDkqaCzrBkD22DvEiL87CvJQ7d2euDhx1/gXBgrvegaRKhfEQC6xikBvVFXqBulKRtfgNMTnbwn1UOLLTqr9C2G75bQQgEei3Iye6N7aV1yNgft@IJinC7ZjBA/dja/tY9E08nkYpWTR6UlbSlJCWP/Vb4OYhnPg1zK@SoI7rIqrFhNaogG/wY) [Answer] # [Perl 5](https://www.perl.org/) `-lp`, 6 bytes ``` #!/usr/bin/perl -lp $_=hex ``` [Try it online!](https://tio.run/##K0gtyjH9/18l3jYjteL/fze3f/kFJZn5ecX/dQsA "Perl 5 – Try It Online") [Answer] # [Io](http://iolanguage.org/), 24 bytes ``` method(x,x fromBase(16)) ``` [Try it online!](https://tio.run/##y8z/n6ZgZasQ8z83tSQjP0WjQqdCIa0oP9cpsThVw9BMU/N/moaSoZKmQkFRZl5JTh4XkGtpgco3NbZEFTA0NjZHFXE0dUNT44bg/gcA "Io – Try It Online") [Answer] # [Tcl](http://tcl.tk/), 20 bytes ``` proc D n {expr 0x$n} ``` [Try it online!](https://tio.run/##K0nO@f@/oCg/WcFFIU@hOrWioEjBoEIlr/Z/Tm5igUKqQjWXIZelBZepsSWXobGxOZejqZsll1utQnVBaUmxgkqqVYxCtAuQjq39DwA "Tcl – Try It Online") [Answer] # [Tcl](http://tcl.tk/), 19 bytes ``` puts [expr 0x$argv] ``` [Try it online!](https://tio.run/##K0nO@f@/oLSkWCE6taKgSMGgQiWxKL0s9v///46mbpYA "Tcl – Try It Online") [Answer] # [Coconut](http://coconut-lang.org/), 15 bytes ``` str..int$(?,16) ``` [Try it online!](https://tio.run/##S85Pzs8rLfmfZhvzv7ikSE8vM69ERcNex9BM83@0uqG6jrqlBZAwNbYEkobGxuZAytHUDcRzU49VqLFTyE0sUNFI0wQxC4qAuvX0cjKLS/4DAA "Coconut – Try It Online") ]
[Question] [ Write a script, program or function which takes one input of type string and outputs or returns some sort of indication wether the input string was 'hi whats up' (without the apostrophes) or not. You can for example return true if it was and false if it wasn't. Or print something to the screen, like 1 or 0. It just has to be consistent: whenever you run the function with parameter/input 'hi whats up' the same output/return should emerge (so don't make it random) and whenever the input is something else, the other possible outcome is expected (it has to be always the same, whatever the input was!). In conclusion, your function/script can only have in total 2 different possible outcomes. The catch is, your entire code must not contain any of these characters: h, i, w, a, t, s, u, p Code golf: shortest code in bytes wins. [Answer] # [Python 3](https://docs.python.org/3/), 29 bytes ``` "HI WHATS UP".loʷer().__eq__ ``` [Try it online!](https://tio.run/##K6gsycjPM/6fZhvzX8nDUyHcwzEkWCE0QEkvJ//U9tQiDU29@PjUwvj4/@UZmTmpCoZWXAqZtpl5BaUlGppcCgVFmXklGmkamZqa/zMyFcozEkuKFUoLuEpSi0sA "Python 3 – Try It Online") An anonymous function taking a string as input. See [Using object methods as answer.](https://codegolf.stackexchange.com/a/95156/81098) [Answer] # [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 16 bytes Full program. Prints 1 for a match, 0 otherwise. ``` ⍞≡⌊'HI WHATS UP' ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qKO94P@j3nmPOhc@6ulS9/BUCPdwDAlWCA1QB8lxPertUy941N2CjB/1rlH/n5GpUJ6RWFKsUFrAhcS2R3BS8svzuDwyFcLBvNACAA "APL (Dyalog Extended) – Try It Online") Does the input `⍞` match `≡` the lowercased `⌊` string `'HI WHATS UP'`? [Answer] # [Excel](https://www.microsoft.com/en-us/microsoft-365/excel), 31 bytes ``` =EXACT(A1,LOWER("HI WHATS UP")) ``` [![enter image description here](https://i.stack.imgur.com/Z4Fvx.png)](https://i.stack.imgur.com/Z4Fvx.png) [Answer] # [Ruby](https://www.ruby-lang.org/), 62 bytes ``` ->b{b==""<<104<<105<<32<<119<<104<<97<<116<<115<<32<<117<<112} ``` [Try it online!](https://tio.run/##KypNqvyfZvtf1y6pOsnWVknJxsbQwAREmNrYGBsBGYaWUCFLcxDPDETA5cBCRrX/CxTSopUyMhXKMxJLihVKC5RiucBC4UB@allqkUJqTnGqUux/AA "Ruby – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` …ŒÞÝà€¾Q ``` Outputs `1` if the input is `hi whats up`, `0` otherwise. [Try it online](https://tio.run/##ASYA2f9vc2FiaWX//@KApsWSw57DncOg4oKswr5R//9oaSB3aGF0cyB1cA) or [verify some more test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/Rw3Ljk46PO/w3MMLHjWtObQv8L/O/2iljEyF8ozEkmKF0gIlHaWknEQgmZEJJuAS9hAulA9RCZVWB2uMBQA). **Explanation:** Pretty straight-forward. ``` …ŒÞÝà€¾ # Push dictionary string "hi whats up" Q # Check if it's equal to the (implicit) input # (after which the result is output implicitly) ``` [See this 05AB1E tip of mine (section *How to use the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `…ŒÞÝà€¾` is `"hi whats up"`. [Answer] # [C (clang)](http://clang.llvm.org/), ~~68~~ ~~62~~ 57 bytes * -5 bytes thanks to [@Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)! ``` f(*x,n,*r){for(*r=0;~n;)*r|="()`7(!43`50@"[n]^x[n--]^64;} ``` [Try it online!](https://tio.run/##bY5RS8MwFIXf9ytuA5MkS7Hg3MBY8HEPvsoeasdKl2yBmI6ko8NZf7ox7dy04H25nJPv3JwyLnVhtt5LTI/MMGrJSVYWU5sm/NNwQu1HijBZz3E0vVvfJ08oM/nqmJk4zlezKW@9MjW8FcpgAqcRhAkGhVq4Ossh/fG6eUY7Bc2uqB0c9oj94w/MhYJlD78M4YXQumKwrKzeRKh/aHm/QnHAXR0V/k14WI/g1LuoJO7qELi9SNrrQEwm5E/DLmuFO@iaX71zNlM5g6Z0WpiLJgxuzjD5pfc23JAYjbV7gPHm1SAG13w0wNtR679KqYut83HzDQ "C (clang) – Try It Online") [Answer] # [Vyxal](https://github.com/Vyxal/Vyxal), 10 bytes ``` «⟇>βX⋏⋏ƈ«= ``` [Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCq+Kfhz7Osljii4/ii4/GiMKrPSIsIiIsImhpIHdoYXRzIHVwIl0=) Base 255 compressed string for the phrase `"hi whats up"` compared against the input. [Answer] # [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 21 bytes ``` T`Ll`lL ^HI WHATS UP$ ``` [Try it online!](https://tio.run/##K0otycxL/K@q4Z7wPyTBJychx4crzsNTIdzDMSRYITRA5f9/JB5XRqZCeUZiSbFCaQEA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation: ``` T`Ll`lL ``` Toggle the case of the input. ``` ^HI WHATS UP$ ``` Compare it against the uppercased phrase. [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes ``` ⁼S”↶⌊&νξ←₂Yδ ``` [Try it online!](https://tio.run/##ATcAyP9jaGFyY29hbP//4oG877yz4oCd4oa24oyK77yGzr3OvuKGkOKCglnOtP//aGkgd2hhdHMgdXAK "Charcoal – Try It Online") No verbose link because the deverbosifier doesn't realise it can save a byte by omitting the closing quote. Explanation: Simply compares the input string to the compressed form of the phrase. [Answer] # [Factor](https://factorcode.org), 24 bytes ``` [ "no&}ngzy&{v"6 v-n = ] ``` [Attempt This Online!](https://ato.pxeger.com/run?1=m70sLTG5JL9owU2z0GBPP3crhdzEkgy9slSQYLFCdmpRXmqOQkFRaklJZUFRZl6JgjWXUkamQnlGYkmxQmmB0tLSkjRdix3RCkp5-Wq1eelVlWrVZUpmCmW6eQq2CrEQ6WXJiTk5CnoQzoIFEBoA) Subtracting 6 from each code point in the string `"no&}ngzy&{v"` results in `"hi whats up"`, then check for equality. [Answer] # Python 3, ~~89 101~~ 85 bytes Hey, hey hey.... nobody said you couldn't use code points! Doesn't use object methods or superscript ASCIIs unlike the other answer Thanks to Dingus and Arnauld for pointing out 2 mistakes. Apparently I'm bad at detecting stuff. Also thanks to Arnauld for letting me forget about 1s and 0s ``` exec("\x70r\x69n\x74(\x69n\x70\x75\x74()=='\x68\x69 \x77\x68\x61\x74\x73 \x75\x70')") ``` [Answer] # [JavaScript (Node.js)](https://nodejs.org), 52 bytes ``` x=>x=='\x68\x69\x20\x77\x68\x61\x74\x73\x20\x75\x70' ``` [Try it online!](https://tio.run/##bYxNCsIwEIX3nmIQwXah@F9dtCfpojFOTCQmJRk1RbyTR/FGNWgRQRcP3nyP@Q7szDx3qqaRsTtsuTWeQEAObciLkOfDMqzWMZsyzCZlyLLunsa@iJl3fBkzGb7@rcaxtvukkgoukpGHUw2jAgZXkfS/WD@9QeLJKbMHsuCROS5BWJdWae9X9Lj/MXXwpeKNU1orDuxHQBLBKIOEaEjCtiH8eP5sb5091jpS3cBOCYEuzlHcPgE "JavaScript (Node.js) – Try It Online") Boring, but you can't really do much else. [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 11 [bytes](https://github.com/DennisMitchell/jellylanguage/wiki/Code-page) ``` “¥_Ż⁺ḄḂȮ§»⁼ ``` [Try it online!](https://tio.run/##y0rNyan8//9Rw5xDS@OP7n7UuOvhjpaHO5pOrDu0/BCQu@f///8ZmQrlGYklxQqlBQA "Jelly – Try It Online") Same as the other golflang answers: uses a compressed string and then compares with the input. ]
[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/194324/edit). Closed 4 years ago. [Improve this question](/posts/194324/edit) I'm sure this is going to spark some controversy, but let's do a practical demonstration. The objective of this is simple, using the [new code of conduct](https://meta.stackexchange.com/q/334900/367090) and no input, print out my pronouns ( "he/him", "he him" is also acceptable). Here's the challenge. This is a classical polyglot contest! This means that the first answer can be in any language, and the only requirement is that the user post their number (1), their language, and their code. The second user must then rework this code to satisfy the condition with the first answers language, and any other language that hasn't been used. Adding code is the preferred method of polyglotting, but subtraction is ok too. This keeps going until we have a program which works simultaneously in many languages. No language should appear twice. Breaking the contest functionality in any previous language would make an answer invalid An example: First person to post code: 1. C++ [Code] Second person to post code: 2. Python. [Altered Code] Third person to post code: 3. Java. [Further altered code] The winner will be the last answer that stands uncontested for 4 weeks. This is a high steaks round, as the penalty for intentionally posting code which mis-genders me, could be a ban from the site itself (though I, unlike stack exchange, am able to overlook this)! Best of luck! For Additional reference, he'res the clarification on chaining rules. > > # Additional rules > > > * Your program must run without erroring out or crashing. Warnings (and other stderr output) are acceptable, but the program must exit > normally (e.g. by running off the end of the program, or via a command > such as `exit` that performs normal program termination). > * Each answer must be no more than 20% or 20 bytes (whichever is larger) longer than the previous answer. (This is to prevent the use > of languages like Lenguage spamming up the thread, and to encourage at > least a minor amount of golfing.) > * Tricks like excessive comment abuse, despite being banned in some polyglot competitions, are just fine here. > * You don't have to use the previous answers as a guide to writing your own (you can rewrite the whole program if you like, as long as it > complies with the spec); however, basing your answer mostly on a > previous answer is allowed and probably the easiest way to make a > solution. > * You cannot submit two answers in a row. Let someone else post in between. This rule applies until victory condition is met. > * As this challenge requires other competitors to post in the same languages you are, you can only use languages with a [free > implementation](http://meta.codegolf.stackexchange.com/q/7822/62131) > (much as though this were a [cops-and-robbers](/questions/tagged/cops-and-robbers "show questions tagged 'cops-and-robbers'") contest). > * In the case where a language has more than one interpreter, you can pick any interpreter for any given language so long as all programs > which are meant to run successfully in that language do so in that > interpreter. (In other words, if a program works in more than one > interpreter, future posts can pick either of those interpreters, > rather than a post "locking in" a particular choice of interpreter for > a language.) > * This challenge now uses the [new PPCG rules about language choice](https://codegolf.meta.stackexchange.com/questions/12877/lets-allow-newer-languages-versions-for-older-challenges?cb=1): > you can use a language, or a language interpreter, even if it's newer > than the question. However, you may not use a language/interpreter > that's newer than the question if a) the language was designed for the > purpose of polyglotting or b) the language was inspired by this > question. (So newly designed practical programming languages are > almost certainly going to be OK, as are unrelated esolangs, but things > like [A Pear Tree](https://esolangs.org/wiki/A_Pear_Tree), which was > inspired by this question, are banned.) Note that this doesn't change > the validity of languages designed for polyglotting that are older > than this question. > * Note that the victory condition (see below) is designed so that breaking the chain (i.e. making it impossible for anyone else to > answer after you via the use of a language that is hard to polyglot > with further languages) will disqualify you from winning. The aim is > to keep going as long as we can, and if you want to win, you'll have > to respect that. > > > # For reference, this is the exact CoC I'm referring to, consolidated as per the request of many users for clairity: > > We expect [today’s changes](https://stackoverflow.blog/2019/10/10/iterating-on-inclusion/) to the [Code of > Conduct](https://meta.stackexchange.com/conduct) to generate a lot of > questions. We’ve tried to anticipate some of the most common questions > people may have here, and we’ll be adding to this list as more > questions come up. > > > **Q1: What are personal pronouns, and why are they relevant to the Code of Conduct?** > > > Personal pronouns are a way to refer to a person without using their > name, when the subject is known. [From > mypronouns.org](https://www.mypronouns.org/sharing): > > > > > > > *The vast majority of people go by the pronouns sets “he/him” or “she/her.” A small but increasing number of people use “they/them” > > pronouns or another pronouns set -- sometimes simply because they > > don’t want to go by pronouns with a gender association (just as some > > folks go by “Ms.” whether or not they are married, because they don’t > > think their marital status should be a relevant issue), and sometimes > > people use pronouns that aren’t associated with one of those two most > > common (binary) genders because they are nonbinary (i.e. people who > > are neither exclusively a man nor exclusively a woman -- e.g. > > genderqueer, agender, bigender, fluid, third/additional gender in a > > cultural tradition, etc.).* > > > > > > > > > The goal of our Code of Conduct is to help us “build a community that > is rooted in kindness, collaboration, and mutual respect.” Using > someone’s pronouns is a way of showing respect for them and refusing > to do so causes harm. > > > **Q2: What does the Code of Conduct say about gender pronouns?** > > > The Code of Conduct has two direct references to gender pronouns: > > > 1. “Use stated pronouns (when known).” > 2. “Prefer gender-neutral language when uncertain.” > > > We’re asking everyone to do two things. First, if you do know > someone’s pronouns (e.g. because they told you), then use them as you > normally would use any pronoun. Second, if you don’t know someone’s > pronouns, use gender-neutral language rather than making an > assumption. > > > **Q3: What should I do if I make a mistake and use the wrong pronouns?** > > > If you make a mistake, apologize and correct your mistake if possible > (e.g. by editing your post). We recognize that this may be new to many > people, particularly members of our community who do not speak English > as a first language, and so mistakes will happen as we all learn > together. > > > **Q4: What should I do if I see someone using the wrong pronouns?** > > > If you notice someone who is using the wrong pronouns for someone else > who has stated them (e.g. in a comment or on their profiles), we > encourage you to gently correct them in a comment. Do not state > pronouns for third parties who have not done so in Stack Exchange (eg. > You know them in person). If the situation escalates, please flag what > you see. A moderator or community manager will look into it further. > > > **Q5: How will this be moderated? Will we ban people based on one mistake?** > > > We understand that miscommunication or mistakes may happen, so most > situations will just result in a gentle correction or warning. As with > any violation of the Code of Conduct, in cases of willful, repeated, > or abusive behavior, warnings may escalate to account suspensions > and/or expulsion. > > > **Q6: What should I do if I don't know someone's pronouns?** > > > When in doubt, use gender-neutral language or refer to the user by > name. > > > **Q7: Are we going to force everyone to identify their pronouns?** > > > No. Just as we do not force users to identify their real name, we will > never force users to identify their pronouns. This is a voluntary > decision by each user to share as much or as little as they are > comfortable. > > > **Q8: How should I identify my pronouns if I choose to do so?** > > > Whether and how you identify your pronouns is up to you. If you choose > to do so, add it to the “About Me” section of your user profile. > > > **Q9: Do I have to use pronouns I’m unfamiliar or uncomfortable with (e.g., [neopronouns](https://en.wiktionary.org/wiki/neopronoun) like > xe, zir, ne... )?** > > > Yes, if those are stated by the individual. > > > **Q10: What if I believe it is grammatically incorrect to use some pronouns (e.g. they/them to refer to a single person)?** > > > If they are the pronouns stated by the individual, you must respect > that and use them. Grammar concerns do not override a person’s right > to self identify. > > > **Q11: If I’m uncomfortable with a particular pronoun, can I just avoid using it?** > > > We are asking everyone to use all stated pronouns as you would > naturally write. Explicitly avoiding using someone’s pronouns because > you are uncomfortable is a way of refusing to recognize their identity > and is a violation of the Code of Conduct. > > > **Q12: Does this mean I’m required to use pronouns when I normally wouldn’t?** > > > We are asking everyone to use all stated pronouns as you would > naturally write. You are not required to insert pronouns where you > otherwise would not. > > > [From @CesarM (staff)](https://meta.stackexchange.com/questions/334900/official-faq-on-gender-pronouns-and-code-of-conduct-changes?cb=1#comment1101186_335191): You have to use their stated pronouns in > places where you'd include a pronoun. If you wouldn't include a > pronoun in the sentence, you don't have to go out of your way to find > a place to include one. > > > **Q13: How does this apply to languages other than English?** > > > For now, while the intent of being inclusive and respectful of all > gender identities applies to all our communities, the specific > requirements around pronoun usage apply only to English language > sites. As we determine best practices in other languages, we’ll work > with those communities and update guidance for those languages. > > > **Q14: Should all posts be written using gender-inclusive language? Should we edit all old posts to be gender-inclusive?** > > > The focus of this change is on using correct pronouns when addressing > other members of the community. However, writing posts in a > gender-inclusive way is encouraged and a great way to make the > community more accessible to more people. If you are writing or > editing a post and can make it gender-inclusive without changing the > meaning, you are encouraged to do so. > > > **Q15: Is it expected that people go to "About me" to check whether someone has pronouns there when interacting in Q&A?** > > > No. That would be good practice, but it is not *required*. > > > [From @jnat (staff)](https://meta.stackexchange.com/questions/334900/official-faq-on-gender-pronouns-and-code-of-conduct-changes#comment1098285_334910): We ask that you use gender-neutral language > when uncertain, and use the stated pronouns once they're made known. > If you wanna "go the extra mile," looking at the user's "about me" > before interacting is certainly nice, but we're not requiring it. > > > [From @CesarM (staff)](https://meta.stackexchange.com/questions/334900/official-faq-on-gender-pronouns-and-code-of-conduct-changes/334915#comment1098325_334915): *Made known* is when you become aware of > the fact. If it's in the comments, then, fine. Correct and move on. > There's no obligation to go out of your way to seek it out, but if > someone tells you directly, comply. > > > **Q16: May I use *they/them* by default?** > > > Yes, but be prepared to make adjustments if so requested. > > > [From @Catija (staff)](https://meta.stackexchange.com/questions/334900/official-faq-on-gender-pronouns-and-code-of-conduct-changes/335477#comment1104046_335428) If you use *they/them* by default, that's > fine. If someone requests that you use other pronouns and you > immediately continue to use *they/them* for that person, we may point > it out to you. "Penalized" in most cases is generally going to be as > minor as a comment being removed or adjusted to meet the request of > the person being spoken about. Only in extreme cases of repeated > requests to change, will it lead to a mod message or suspension. > > > **Q17: What should I do if I think someone requests me to use a certain pronoun in bad faith?** [From @Cesar M(Staff)](https://meta.stackexchange.com/questions/334900/official-faq-on-gender-pronouns-and-code-of-conduct-changes?cb=1#comment1098246_334908) > > > > > > > If people are requesting things in bad faith, you are welcome to escalate to mods and mods can contact us CMs when in doubt too. > > > > > > > > > It is advised to use a custom (Something Else) flag for this. Please > explain, as detailed as possible, what the issue is. > > > [Return to FAQ index](/q/7931) > > > [Answer] # 1. [Keg](https://github.com/JonoCode9374/Keg), 6 bytes ``` he him ``` [Try it online!](https://tio.run/##y05N//8/I1UhIzP3/38A "Keg – Try It Online") Real easy one for Keg, just print the desired output. ]
[Question] [ You have to write a program, if its source code is reversed, then it will error. For example, if your source is `ABC`, then reversing it and writing `CBA` should crash/throw an error. And `ABC` itself should be a vaild program (I mean your primary source should be a valid program). Output of the main source code can be empty, but your `ABC` code I mean primary source should not output anything to standard error. Also the minimum length of a solution is 2 bytes. Standard loopholes apply, shortest code wins. [Answer] # [Malbolge](https://github.com/TryItOnline/malbolge), 2 bytes Errors via raising a SIGILL (illegal instruction). ``` DP ``` [Try it online!](https://tio.run/##y03MScrPSU/9/98l4P9/AA "Malbolge – Try It Online") [Try it reversed!](https://tio.run/##y03MScrPSU/9/z/A5f9/AA "Malbolge – Try It Online") ## Explanation Forward: | C | [C] | (C+[C])%94 | Action | | --- | --- | --- | --- | | 0 | `D` (ord 68) | 68 | No operation. | | 1 | `P` (ord 80) | 81 | Stop execution of current program. | Reversed: | C | [C] | (C+[C])%94 | Action | | --- | --- | --- | --- | | 0 | `P` (ord 80) | 80 | Illegal instruction (stops program) | | 1 | `D` (ord 68) | 69 | Illegal instruction (not executed) | [Answer] # [Python 2](https://docs.python.org/2/), 2 bytes And probably 1 million different languages too ``` +1 ``` [Try it online!](https://tio.run/##K6gsycjPM/r/X9vw/38A "Python 2 – Try It Online") [Answer] # [R](https://www.r-project.org/), 2 bytes ``` NA ``` [Try it online!](https://tio.run/##K/r/38/x/38A "R – Try It Online") Outputs `NA`, which corresponds to "Not Available", to represent missing values. On the other hand, `AN` errors, as it is literally not available. A bunch of other examples: ``` 1i 1L ar as by de df dt gc gl Im is lh lm ls pf pi pt qf qr qt Re rf rt sd ts vi {} .C ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes ``` D€ ``` [Try it online!](https://tio.run/##y0rNyan8/9/lUdOa//8B "Jelly – Try It Online") or [!enilno ti yrT](https://tio.run/##y0rNyan8//9R0xqX//8B) ## How it works ``` D€ - Main link. Takes no arguments - Implicitly set the argument to 0 as the chain doesn't begin with a nilad € - Generate the range from 1 to 0 ([]) and over each element: D - Get its digits Output the empty list, which outputs nothing due to Jelly's output rules ``` ## skrow ti woH ``` €D - Main link. Takes no arguments € - € is a quick, which needs a preceding atom upon which to act Without a preceding atom, parsing fails and the program errors D - D is ignored as the program has errored ``` --- ### Alternative programs There are far too many 2-byte programs that also work to fully list them. Instead, here's how to make your own: 1. Open [Jelly](https://tio.run/#jelly) on Try it online! 2. Open the [Quicks page](https://github.com/DennisMitchell/jellylanguage/wiki/Quicks) 3. Open the [Atoms page](https://github.com/DennisMitchell/jellylanguage/wiki/Atoms) 4. Choose any single character atom. Enter it into the TIO Code field (Copy-Paste works best) 5. Choose any single character quick. Enter it after the atom 6. Press Run. 7. If this errors, clear the characters and go to step 4 8. Voila, you have your answer [Answer] # [Python 2 or 3](https://docs.python.org/2/), 3 bytes ``` 0/1 ``` [Try it online!](https://tio.run/##K6gsycjPM/r/30Df8P9/AA "Python 2 – Try It Online") [Try it online (Reversed)!](https://tio.run/##K6gsycjPM/r/31Df4P9/AA "Python 2 – Try It Online") `0/1` is a valid mathematical expression and will result 0 (will show nothing on TIO interpreter) `1/0` (reversed) causes a divide by zero error. Polygots in a "loooottttttttttt" of languages [Answer] # [Python 3](https://docs.python.org/3/), 2 bytes [G B](https://codegolf.stackexchange.com/users/18535/g-b) already [posted](https://codegolf.stackexchange.com/a/219890/64121) one of those, but I wanted to show some more 2-byters: ``` +0 0, ~0 #\ id 0j 0; {} 0 ``` [Try it all online!](https://tio.run/##bYw9C8IwFEX39ysetYiihaijqZuCs6tLTB5NiiYlrV@I/vUYxHTqdrnn3HsSrQ7hrs2ZcL87lOhJKCw8Nt5VXlxAOUAkqR1m2wfJa2dshfmfZrjYjJdRaJ6ddnaFhcSsh7H3dCPfkirzSYyc8wSnQ6/JHr7taZr@JOUshTBjwObwYTA6glHAamBreL2BIXwB) [Here](https://tio.run/##bY3BCsIwEETv/Yo9JtSD1YsIfol42Cxbk0saNhFSxG@PJLWi6G1485gJc7KT35dCFiXCCc5kRWUN4ySQwXkQ9FdWw@6gL11XKVba9GMHzTNfBCDJvASAeCPiWIe3L8KZSWFvNnB/6B9r@LRMj/@tZYszcUjrU8AYW3Tjar4rcT7VT13KEw) is a more complete list. [Answer] # JavaScript, 2 bytes ``` [] ``` Errors with `][` [Answer] # [Bash](https://www.gnu.org/software/bash/), 2 bytes ``` wc ``` [Try it online!](https://tio.run/##S0oszvj/vzz5/38A "Bash – Try It Online") [Try it online (Reversed)!](https://tio.run/##S0oszvj/P7n8/38A "Bash – Try It Online") Don't think this one has a lot of "polygot"s other 2-byters `sh`,`ps`,`du`,`ls` (if `sl` is not installed) [Answer] # Windows Batch, 2 bytes ``` :a ``` This program is an empty label, if reversed then it would search for a drive named `a:`, but floppy drives are no longer available!!! [Answer] # [Vyxal](https://github.com/Lyxal/Vyxal), 2 bytes ``` i1 ``` [Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=i1&inputs=&header=&footer=) or [Try it Reversed!](http://lyxal.pythonanywhere.com?flags=&code=1i&inputs=&header=&footer=) ## Explained Before we begin, `i` takes two arguments (we'll call them `a` and `b`) and returns `a[b]` (indexing). `1` simply pushes `1` to the stack. The program `i1` is: ``` rhs, lhs = pop(stack, 2) stack.append(lhs[rhs]) stack.append(1) ``` Because the stack is empty, implicit input is taken for `lhs` and `rhs`. And because there is no input, `0` is returned each time input is needed. Thus, `i` gives `"0"[0]` and then pushes `1`. The program `1i` is: ``` stack.append(1) rhs, lhs = pop(stack, 2) stack.append(lhs[rhs]) ``` Which attempts to push `"0"[1]`, which is obviously out of the list. Vyxal doesn't have modular indexing (yet), so this errors. [Answer] # [naz](https://github.com/sporeball/naz), 2 bytes ``` 1o ``` Any valid 2-byter will throw the error `missing number literal` if reversed; I just picked this one because it actually outputs something (`0`). [Try it online!](https://sporeball.dev/naz/?code=1o&input=&n=false) / [Try it reversed!](https://sporeball.dev/naz/?code=o1&input=&n=false) [Answer] # MATLAB/Octave, 2 bytes ``` pi ``` When run forward, this yields an approximation of `pi` represented as a floating point number. When reversed, it tries to execute the function named `ip` which is not defined: ``` octave:1> ip error: 'ip' undefined near line 1, column 1 ``` [Answer] # Java, 42 bytes ``` interface M{static void main(String[]a){}} ``` This is the shortest valid full Java program. It does not output anything. Since all methods in an interface are implicitly public, we can save bytes by putting the main method inside an interface instead of a class. [Try it online!](https://tio.run/##y0osS9TNSsn@/z8zryS1KC0xOVXBt7q4JLEkM1mhLD8zRSE3MTNPI7ikKDMvPTo2UbO6tvb/fwA) The reversed code is clearly invalid syntax: ``` }}{)a][gnirtS(niam diov citats{M ecafretni ``` [Try it online!](https://tio.run/##y0osS9TNSsn@/7@2tlozMTY6PS@zqCRYIy8zMVchJTO/TCE5sySxpLjaVyE1OTGtKLUkL/P/fwA) [Answer] # Lua (2 bytes) Write the following in the command line ``` =1 ``` Although the `=<something>` is supported for backward compatibility, is a deprecated feature in Lua. `1=` triggers the following error: ``` stdin:1: unexpected symbol near '1' ``` in Lua 5.4.2. [Answer] ## x86-16 machine code, 2 bytes Full program. Error type is an unhandled SIGSEGV. Hexdump: ``` 00000000: 63c3 c. ``` Listing: ``` 63 DB 63 ; Raises an unhandled SIGSEGV C3 RET ; Not executed ``` Listing (reversed): ``` C3 RET ; Return to caller 63 DB 63 ; Not executed ``` [Answer] # [BASIC], 2 bytes ``` ?a ``` [Try it online!](https://tio.run/##q0xMSizOTP7/3z7x/38A "Yabasic – Try It Online") ``` a? ``` [The reverse will just generate a Syntax Error](https://tio.run/##q0xMSizOTP7/P9H@/38A "Yabasic – Try It Online") Basically (pun totally intended) if you can't make a 2-3 byte program in almost any language that'll crash if reversed, something is wrong! [Answer] # Brain-flak, 2 `()` Errors on `)(` # # PHP, 2 `$=?>` does nothing `<?=$` errors. [Answer] # MATL, 2 bytes ``` lt ``` Try it at [MATL Online](https://matl.io/?code=lt&inputs=&version=22.4.0) **Explanation** This program pushes the literal `1` to the stack and duplicates it using `t`. When reversed, `t` tries to grab it's input argument implicitly and since no inputs are provided it errors out ``` MATL run-time error: The following Octave error refers to statement number 1: t --- Unable to fetch user input ``` ]
[Question] [ It's strange this question hasn't been asked yet, so here it is: **Calculate the length of a string given through STDIN** ## Rules * As said, your string will be given through STDIN, not via command line arguments * Print the length of the string to STDOUT * Only ASCII chars will be given, **and all printable ASCII chars count!** * This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the answer with the shortest length wins! Good Luck and have fun! [Answer] # [Shakespeare Programming Language](https://github.com/TryItOnline/spl), 156 bytes Thanks JoKing for nice trick with `[Exeunt]`. `,.Ajax,.Page,.Act I:.Scene I:.[Exeunt][Enter Ajax and Page]Ajax:Open mind Be you nicer zero?Page:If soyou be the sum ofa cat you.If solet usact I.Open heart` [Try it online!](https://tio.run/##Hc0xDoMwDAXQq/wDoBwgS9VKDEyt1BExmNQUKkhQ4ki0l09jtm//JzvtaymNuX7oaMyD3lyzE3TWPB171tC3B2cvQ9964QilIP@C6kEne9/ZY1vq7sb4hgy/uCp/HMNFle0mpKDFyJCZkfKGMBEciXpz9isLciL9bs6LM1OUUmh0fw "Shakespeare Programming Language – Try It Online") [Answer] ## Golfscript (1 byte) ``` , ``` And that's why this question hadn't already been asked. [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 1 [byte](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` g ``` [Try it online.](https://tio.run/##MzBNTDJM/f8//f//kNTikvjgkqLMvHQA) **Explanation:** (As if it would be necessary..) ``` # Implicit input from STDIN g # Length # Implicit output to STDOUT ``` [Answer] # Java 8, 63 bytes A lambda taking empty input and throwing `IOException`. ``` n->{int c=0;while(System.in.read()>=0)c++;System.out.print(c);} ``` [Try It Online](https://tio.run/##fU89T8MwEJ3jX@ExVlWrjMhKN4YOiCESC2IwjpNc6p4j@5ICVX57cKIgIZCY7vTe3fvo9Kj3vrfYVee5H94cGG6cjpE/akB@Y9kGRtKUBiDZUGtj@Wkhv9nRQ8W1Mban/HnZR8GpDf4aeZccJHh5enp4X3jwqFg2sd/KNaB2SbWxVFIFWMKn5QWbcX@8JVduioO6tuBsXn5EshcJKIPVVS6OxUGY3U5tuB9I9iG95EaoaWaZ@uO1xr2kgnlJ6bJ5eeU6NPG/zGvbn9nkVhcH58TaaGIzYD8Q8zVzFhtq2d09@wI) [Answer] # [brainfuck](https://github.com/TryItOnline/brainfuck), 163 bytes ``` ,[>+<,]>[>>+>+<<<-]>>>[<<<+>>>-]<<+>[<->[>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]++++++++[<++++++>-]>[<<+>>-]>[<<+>>-]<<]>]<[->>++++++++[<++++++>-]]<[.[-]<]< ``` [Try it online!](https://tio.run/##bUzBCsJQDPugrgN1m5eQHyk9bIPBGHgQ/P5nqigezCVpkma5z/tte6xHa13Q0CWDNCnAk2RImNizOODK7QuE02WQ@rNwVfJ1oSDP81MNvFlLNWr8FdXNGuOfuoJeQ0i0djpfhnG6PgE "brainfuck – Try It Online") Somebody had to make this a little interesting. ## Explanation: ``` ,[>+<,]> ``` This is a modified cat program that, rather than outputting each read value, increments the 2nd cell each time a value is read. The entire rest of the program is for outputting a cell's value as a number rather than an ASCII codepoint. [Answer] # [Hexagony](https://github.com/m-ender/hexagony), 11 bytes ``` ,~<@!"/>"){ ``` [Try it online!](https://tio.run/##y0itSEzPz6v8/19BQUehTsGGS8FBQVFBSUGfyw5IaipUK@gpcAExGHIpQOj//w2NjE1MzQA) More readable version: ``` , ~ < @ ! " / > " ) { . . . . . . . . ``` [Answer] # [Pyth](https://github.com/isaacg1/pyth), 2 bytes ``` lz ``` **Explanation** ``` l #length of z #input ``` [Try it online!](https://tio.run/##K6gsyfj/P6fq/3@lyvzSuCgQVAIA "Pyth – Try It Online") [Answer] # [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak) + `-a` flag, 6 bytes Even Brain-Flak has a built-in for this challenge... ``` ([]<>) ``` [Try it online!](https://tio.run/##SypKzMzTTctJzP7/XyM61sZO8/9/j9ScnHwdhfD8opwUxf@6iQA "Brain-Flak – Try It Online") Without using `[]` but still rather simple (10 bytes): [`({<{}>()})`](https://tio.run/##SypKzMzTTctJzP7/X6PaprrWTkOzVvP/f4/UnJx8HYXw/KKcFMX/uokA "Brain-Flak – Try It Online") [Answer] # [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), ~~73~~ 64 bytes ``` [S S S N _Push_0][N S S N _Create_Label_LOOP][S N S _Duplicate][S N S _Duplicate][T N T S _Read_STDIN_as_character][T T T _Retrieve][S S S T S T T S T T S N _Push_182][T S S T _Subtract][N T S S N _If_0_jump_to_Label_PRINT_AND_EXIT][S S S T N _Push_1][T S S S _Add][N S N N _Jump_to_Label_LOOP][N S S S N _Create_Label_PRINT_AND_EXIT][T N S T _Print_to_STDOUT] ``` Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only. `[..._some_action]` added as explanation only. Input requires a trailing `¶`, because Whitespace has no way to tell when the input-characters are complete. Whitespace only has two STDIN inputs: integer or character. A full string should be inputted one by one, but Whitespace doesn't know when it has all. So perhaps this answer is non-competing due to the restriction of Whitespace, but I've chosen a character outside the printable ASCII range to add as leading character for inputs, so the program knows when to stop and output the length. [Try it online](https://tio.run/##K8/ILEktLkhMTv3/X0FBgYsLiBXABCcXpwInJydQEESDEFAALAqShzBAakFagFJADf//h6QWl8QHlxRl5qUf2gYA) (with raw spaces, tabs and new-lines only). **Explanation in pseudo-code:** ``` Integer counter = 0 Start LOOP: Integer input = STDIN as character If(input == '¶') Jump to function PRINT_AND_EXIT counter = counter + 1 Jump to next iteration of LOOP function PRINT_AND_EXIT: Print counter as integer to STDOUT ``` **Example input: `acb¶`** ``` Command Explanation Stack HEAP STDIN STDOUT STDERR SSSN Push 0 [0] NSSN Create Label_LOOP [0] SNS Duplicate top (0) [0,0] SNS Duplicate top (0) [0,0,0] TNTS Read STDIN as character [0,0] {0:97} 'a' TTT Retrieve [0,97] {0:97} SSSTSTTSTTSN Push 182 [0,97,182] {0:97} TSST Subtract top two (97-182) [0,-85] {0:97} NTSSN If 0: Jump to Label_EXIT [0] {0:97} SSSTN Push 1 [0,1] {0:97} TSSS Add top two (0+1) [1] {0:97} NSNN Jump to Label_LOOP [1] {0:97} SNS Duplicate top (1) [1,1] {0:97} SNS Duplicate top (1) [1,1,1] {0:97} TNTS Read STDIN as character [1,1] {0:97,1:99} 'c' TTT Retrieve [1,99] {0:97,1:99} SSSTSTTSTTSN Push 182 [1,99,182] {0:97,1:99} TSST Subtract top two (99-182) [1,-83] {0:97,1:99} NTSSN If 0: Jump to Label_EXIT [1] {0:97,1:99} SSSTN Push 1 [1,1] {0:97,1:99} TSSS Add top two (1+1) [2] {0:97,1:99} NSNN Jump to Label_LOOP [2] {0:97,1:99} SNS Duplicate top (2) [2,2] {0:97,1:99} SNS Duplicate top (2) [2,2,2] {0:97,1:99} TNTS Read STDIN as character [2,2] {0:97,1:99,2:98} 'b' TTT Retrieve [2,98] {0:97,1:99,2:98} SSSTSTTSTTSN Push 182 [2,98,182] {0:97,1:99,2:98} TSST Subtract top two (98-182) [2,-84] {0:97,1:99,2:98} NTSSN If 0: Jump to Label_EXIT [2] {0:97,1:99,2:98} SSSTN Push 1 [2,1] {0:97,1:99,2:98} TSSS Add top two (2+1) [3] {0:97,1:99,2:98} NSNN Jump to Label_LOOP [3] {0:97,1:99,2:98} SNS Duplicate top (3) [3,3] {0:97,1:99,2:98} SNS Duplicate top (3) [3,3,3] {0:97,1:99,2:98} TNTS Read STDIN as character [3,3] {0:97,1:99,2:98,3:182} '¶' TTT Retrieve [3,182] {0:97,1:99,2:98,3:182} SSSTSTTSTTSN Push 182 [3,182,182] {0:97,1:99,2:98,3:182} TSST Subtract top two (182-182) [3,0] {0:97,1:99,2:98,3:182} NTSSN If 0: Jump to Label_EXIT [3] {0:97,1:99,2:98,3:182} NSSSN Create Label_EXIT [3] {0:97,1:99,2:98,3:182} TNST Print as integer to STDOUT [] 3 error ``` Stops program with error: No exit defined. [Answer] # [Haskell](https://www.haskell.org/), ~~25~~ 20 bytes -5 bytes for making this a function only (initially thought that it has to be a full program) ``` interact$show.length ``` [Try it online!](https://tio.run/##y0gszk7Nyfmfm5iZp2CrEPM/M68ktSgxuUSlOCO/XC8nNS@9JOP//7T8fIWkxKJ/yWk5ienF/3WTCwoA "Haskell – Try It Online") [Answer] # APL+WIN, 2 bytes Prompts for character string input then counts characters: ``` ⍴⍞ ``` [Answer] ## [Keg](https://github.com/JonoCode9374/Keg), 3 bytes ``` ?!. ``` Well, I can't golf this program well. [TIO](https://tio.run/##y05N///fXlHv/3@P1JycfAA) [Answer] # [Octave](https://www.gnu.org/software/octave/), 14 bytes ``` nnz(input('')) ``` [Try it online!](https://tio.run/##y08uSSxL/f8/L69KIzOvoLREQ11dU/P/f/WQjMxiBSBKVCguKcrMS1cHAA "Octave – Try It Online") [Answer] # [R](https://www.r-project.org/), 23 bytes ``` cat(nchar(readLines())) ``` [Try it online!](https://tio.run/##K/r/PzmxRCMvOSOxSKMoNTHFJzMvtVhDU1Pzv6GRsYmpiZlCSgonkDIx/Q8A "R – Try It Online") [Answer] # [Retina](https://github.com/m-ender/retina/wiki/The-Language), 3 bytes ``` s`. ``` [Try it online!](https://tio.run/##K0otycxLNPz/vzhB7/9/Qy5jTlMA "Retina – Try It Online") This isn't even technically a built-in function, but it is a central feature of the language: counting matches of a regular expression, in this case `.` (wildcard matching any character). The ``` makes Retina treat the character(s) preceding it in the line as configuration, so `s` activates SingleLine mode, which makes `.` match newlines also, because they are part of printable ASCII. [Answer] # Ruby, 16 Bytes This was rather easy. ``` puts gets.length ``` needs no explanation ;) [Answer] ## Batch, 182 bytes ``` @set s= @set/ps= @set "t=%s:"=""%" @if "%t:"=""%"=="""=""""" goto g @for %%s in ("%s:"=%" "%t%")do @echo(%%~s>>_ @for %%s in (_)do @set s=%%~zs @del _ :g @cmd/cset/as/2-2*!!s ``` Testing for the empty string without breaking when quotes were present was cumbersome! Explanation: ``` @set s= ``` Clear `s` as `set/p` leaves `s` unchanged if the input was empty. ``` @set/ps= ``` Take input on STDIN into `s`. ``` @set "t=%s:"=""%" ``` Try to quote all of the quotes in `s`. However, if `s` is empty, Batch throws a wobbly, and sets `t` to `"=""` instead, which still has an odd number of quotes. ``` @if "%t:"=""%"=="""=""""" goto g ``` Quote all of the quotes in `t`, and compare the result to `""=""""`. This can only happen if `s` was empty, in which case we skip the measurement step. ``` @for %%s in ("%s:"=%" "%t%")do @echo(%%~s>>_ ``` Print `s` without quotes and `s` with quoted quotes on separate lines to a temporary file. The `(` is needed in case `s` only contains quotes. ``` @for %%s in (_)do @set s=%%~zs ``` Obtain the length of the temporary file. ``` @del _ ``` Delete the temporary file. ``` :g ``` Jump here if the input was empty. ``` @cmd/cset/as/2-2*!!s ``` Halve and subtract 2 from the length of the temporary file. However if the input was empty then `s` will be treated as the numeric value zero, and the result of the expression is then zero as desired. 117 bytes without empty string support: ``` @set/ps= @for %%s in ("%s:"=%" "%s:"=""%")do @echo(%%~s>>_ @for %%s in (_)do @set s=%%~zs @del _ @cmd/cset/as/2-2 ``` 93 bytes if support for `"`s is not necessary (84 bytes without `"` or empty string support): ``` @set s= @set/ps= @set n=0 :l @if not "%s%"=="" set/an+=1&set "s=%s:~1%"&goto l @echo %n% ``` Empty strings and quotes can even be handled for 212 bytes without resorting to file length builtins: ``` @set s= @set/ps= @set "t=%s:"=""%" @set n=0 @if "%t:"=""%"=="""=""""" goto g :l @set/an+=1 @set "s=%t:~,1%%t:~,1%" @if "%s%" neq """" set "t=.%t%" @set "t=%t:~2%" @if not "%t%"=="" goto l :g @echo %n% ``` Here after quoting the quotes in `s` we have to be careful to double the first character of `t` in case it is a quote, then if it is not then prefix a dummy character to `t` so that the first two characters may be safely removed. This ends up counting the quoted quotes as single characters again. [Answer] # [Perl 6](https://perl6.org), ~~15~~ 14 bytes ``` slurp.codes.say ``` [Try it](https://tio.run/##K0gtyjH7/784p7SoQC85PyW1WK84sfL/f4/UnJx8hfD8opwUAA "Perl 6 – Try It Online") ``` say +$*IN.comb ``` [Try it](https://tio.run/##K0gtyjH7/784sVJBW0XL008vOT836f9/j9ScnHyF8PyinBQA "Perl 6 – Try It Online") --- * [`slurp`](https://docs.perl6.org/routine/slurp) reads everything * [`codes`](https://docs.perl6.org/routine/codes) gets the number of Unicode codepoints (this is different than [`chars`](https://docs.perl6.org/routine/chars) for `\r\n`) * [`say`](https://docs.perl6.org/routine/say) print the [`.gist`](https://docs.perl6.org/routine/gist) with trailing newline ([`put`](https://docs.perl6.org/routine/put) could have been used, which just adds the newline) * [`&prefix:« + »`](https://docs.perl6.org/routine/+) converts to [`Numeric`](https://docs.perl6.org/type/Numeric) * [`$*IN`](https://docs.perl6.org/language/variables#index-entry-%24%2AIN) is STDIN * [`comb`](https://docs.perl6.org/routine/comb) splits its input into a sequence of characters (Which when converted to [`Numeric`](https://docs.perl6.org/type/Numeric) returns a count) [Answer] # [Python 3](https://docs.python.org/3/), 19 bytes ``` print(len(input())) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EIyc1TyMzr6C0RENTU/P//5DU4pL44BKgVDoA "Python 3 – Try It Online") [Answer] ## [W](https://github.com/A-ee/w) `s`, 1 byte ``` k ``` ## Explanation ``` % s: we have to read from STDIN. % Implicitly prepend an input k % (k)ount the number of items in this thing % Implicit output ``` ## How do I use the parameter? The cli param system is quite weird (to allow people to type less), so here is an example of how it is used: ``` $ ..\python W.py code.w [] s 'Hello' Code: k #0: a [] #1: k ['a[0]'] out: lambda a:mylen(a[0]) 5 ``` ]
[Question] [ ## Challenge Given two numbers, output their quotient. In other words, integer divide one number by another. Both divisor/dividend will be under 10001. Division must be performed using integer division, rounding down. Here are some example inputs and outputs: ``` 5 1 5 -4 2 -2 4 -2 -2 6 2 3 16 4 4 36 9 4 15 2 7 17 3 5 43 5 8 500 5 100 500 100 5 10000 2 5000 ``` Or as CSV: ``` 5,1,5 -4,2,-2 4,-2,-2 6,2,3 16,4,4 36,9,4 15,2,7 17,3,5 43,5,8 500,5,100 500,100,5 10000,2,5000 ``` ## Rules * Standard loopholes not allowed * You must use integer division, not floating point division * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer wins, but will not be selected. * The second input (denominator) will never be equal to `0`. ## Why? I'm interested in seeing answers in esoteric languages, like Brainfuck and Retina. Answers in regular languages will be trivial, however I would really like to see answers in these languages. I will be giving a bounty of **+50** reputation to a Retina answer. [Answer] # Mathematica, 8 bytes ``` Quotient ``` Thanks to @JungHwanMin for reminding me there's a builtin. [Answer] # JavaScript, 11 bytes JavaScript doesn't have integers but using a [bitwise or](http://ecma262-5.com/ELS5_HTML.htm#Section_11.10) parses a float as a signed 32 bit integer. ``` a=>b=>a/b|0 ``` # Try it online ``` const f = a=>b=>a/b|0 alert(f(prompt())(prompt())) ``` [Answer] # C (GCC), 13 bytes Doesn't work on *all* implementations, but that's OK. ``` f(a,b){a/=b;} ``` [Try it on TIO!](https://tio.run/nexus/c-gcc#@5@mkaiTpFmdqG@bZF37PzcxM09Ds7qgKDOvJE1DSTVFSSdNw9BUx0hTEygLAA "C (gcc) – TIO Nexus") [Answer] # [Pip](https://github.com/dloscutoff/pip), 4 bytes ``` a//b ``` [Try it online!](https://tio.run/nexus/pip#@5@or5/0//9/Q/P/xgA "Pip – TIO Nexus") Explanation: ``` A and B are read implicitly from the cmd line a//b Calculate the int div of a and b (double slash == int div) Results of the last expression are printed implicitly. ``` [Answer] # [CJam](https://sourceforge.net/p/cjam), 3 bytes ``` q~/ ``` [Try it online!](https://tio.run/nexus/cjam#@19Yp///v7GZgiUA "CJam – TIO Nexus") [Answer] # [아희(Aheui)](http://esolangs.org/wiki/Aheui), 15 bytes ``` 방방나망희 ``` [Try it here! (please copy and paste the code manually)](http://jinoh.3owl.com/aheui/jsaheui_en.html) [Answer] # Python 2, ~~14~~ 11 bytes ``` int.__div__ ``` [**Try it online**](https://tio.run/nexus/python2#S7ON@Z@ZV6IXH5@SWRYf/7@gCMhTSNMwMdax0PwPAA) [Answer] # Bash, ~~25~~ ~~22~~ 15 bytes ``` echo $(($1/$2)) ``` Save to script, input numbers given at command line Saved 3 bytes thanks to @betseg [Answer] # [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 8 bytes ``` ::?a'\`b ``` # Explanation: ``` :: get a and b from the cmd line ? Print a \ b the backslash does integer division, (opposed to the forward slash / for float div) ' ` however, the same symbol is used for ELSE. We need to escape it with ' and ` ``` --- Note that the latest version of QBIC allows for an inline use of the `:` function, saving two bytes: ``` ?:'\`: ``` [Answer] # [Aceto](https://github.com/aceto/aceto), 6 bytes ``` riri/p ``` ``` ri takes input as integer / does integer division p prints it ``` [Try it online!](https://tio.run/##S0xOLcn//78osyhTv@D/f0NzLmMA "Aceto – Try It Online") [Answer] # PHP, 23 Bytes ``` <?=$argv[1]/$argv[2]^0; ``` or ``` <?=$argv[1]/$argv[2]|0; ``` and for 29 Bytes ``` <?=intdiv($argv[1],$argv[2]); ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 1 byte ``` : ``` [Try it online!](https://tio.run/nexus/jelly#@2/1//9/Q/P/xgA "Jelly – TIO Nexus") [Answer] # 05AB1E, 3 bytes `II÷` [Try online](https://tio.run/nexus/05ab1e#@@/peXj7//@GBiDAZQQA) If you can reverse the input, it would work in 1 byte: `÷` [Answer] # [Triangular](https://github.com/aaronryank/triangular), 6 bytes ``` $.$%_< ``` [Try it online!](https://tio.run/##KynKTMxLL81JLPr/X0VPRTXe5v9/CwVdo/8A "Triangular – Try It Online") Formats into this triangle: ``` $ . $ % _ < ``` Without directionals and no-ops, the code looks like this: `$$_%` * `$` - read input as integer * `_` - divide * `%` - print [Answer] # [Decimal](//git.io/Decimal), 12 bytes ``` 81D81D44D301 ``` Ungolfed: ``` 81D ; builtin 1 - read INT to stack 81D ; builtin 1 - read INT to stack 44D ; math divide (postfix /) 301 ; print from stack to output ``` [Try it online!](https://tio.run/##S0lNzsxNzPn/38LQBYhMTFyMDQz//7dUMAYA) [Answer] # [Retina](https://github.com/m-ender/retina/wiki/The-Language), 28 bytes ``` \d+ * ~`(_+) (_+) K`$1$nC`$2 ``` [Try it online!](https://tio.run/##K0otycxLNPz/PyZFm0uLqy5BI15bUwFEcHknqBiq5DknqBj9/29ppmAOAA "Retina – Try It Online") I'm quite new to Retina; I probably could have golfed this more. **Explanation:** Let's start with an input: `38 4` ``` \d+ * ``` This turns the numbers into unary, so 4 is represented as \_\_\_\_, and 38 with 38 underscores. ``` ~`... ``` This marks a stage that generates code to run afterwards ``` (_+) (_+) K`$1$nC`$2 ``` This is a replace stage to generate the division code; Firstly, it splits the string into the dividend (referenced as $1) and divisor (referenced as $2). Then, it returns the string: ``` K`{dividend as unary} C`{divisor as unary} ``` The returned string is evaluated and the answer implicitly printed. It sets the working string to the dividend, and counts the matches of the divisor in it. [Answer] ## [Keg](https://github.com/JonoCode9374/Keg/), 3 bytes ``` ¿¿/ ``` Simply 2 nice inputs and then divides them. [TIO](https://tio.run/##y05N////0P5D@/X//zfkMgYA) [Answer] ## Batch, 16 bytes ``` @cmd/cset/a%1/%2 ``` `set/a` doesn't print its output inside a batch script, so we have to fake it out by starting a new copy of the command processor. [Answer] # GML, 30 bytes ``` return argument0 div argument1 ``` [Answer] # TI-Basic, 6 bytes ``` Input :iPart(X/Y ``` [Answer] # [Retina](https://github.com/m-ender/retina/wiki), ~~40~~ 38 bytes ``` \d+ * (-?)(_+);(-?)(\2)*_* $1$3$#4 -- ``` Takes input in the format `denominator;numerator`. Also works for negative integers after the specs got changed, unlike the existing Retina answer. -2 bytes thanks to *@FryAmTheEggman* thanks to a golf suggested in [another Retina answer of mine](https://codegolf.stackexchange.com/a/190623/52210). [Try it online.](https://tio.run/##JYk7CsMwEET7uYYVkGQWdvXFbJHSlzA4gaRIkyLk/sqiTPHmDfN5fl/vu4yL32/jeKyI8HQN/lyDTjlSiGeEE5fdUkCEMUQrkpKtpMWsoag0bJqbLanIKh1VSzZUZgjzbDvZgq5bA012pb9b/QA) **Explanation:** Convert all numbers in the input to unary, replacing them with that amount of underscores: ``` \d+ * ``` Integer divide the two unary numbers (but with a decimal numbers as result), and filter all `-` to the front at the same time: ``` (-?)(_+);(-?)(\2)*_* $1$3$#4 ``` Remove any `--` if present: ``` -- ``` [Answer] # [J-uby](https://github.com/cyoce/J-uby), 2 bytes 🫤 ``` :/ ``` [Attempt This Online!](https://ato.pxeger.com/run?1=m700K740qXLBIjfbpaUlaboWi6z0IYwVBQpu0RY6xrEQ7oIFEBoA) [Answer] ## Ruby, 10 bytes ``` ->i,j{i/j} ``` Extremely simple. Lambda function that returns the value `i/j`. ]
[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/172511/edit). Closed 5 years ago. [Improve this question](/posts/172511/edit) Your goal is simple: to fail everything. More precisely, you should write the shortest code that triggers a compilation/interpretation error, or a runtime error. # What does not count * Failing with symbols that are not covered by the language syntax and are meant to appear only in string literals, comments and other ways to include non-executable data in the code, or are not meant to appear in the code at all * Warnings and notices that don't prevent successful compilation or execution * Overflow related errors: infinite loops, recursion limits reaching, stack overflows, out-of-memory errors and so on This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins! By the way, this is probably the only challenge where non-esoterical languages can beat esoterical ones ;-) [Answer] # Polyglot, 0 bytes This is a list of languages where an empty program gives an error. * **C/C++/Objective-C**: Any compiler will complain not having a `main`, and emit a link error. + [C (gcc)](https://tio.run/##S9ZNT07@DwQA "C (gcc) – Try It Online"), [C (tcc)](https://tio.run/##S9YtSU7@DwQA "C (tcc) – Try It Online"), [C (clang)](https://tio.run/##S9ZNzknMS/8PBAA "C (clang) – Try It Online"), [C++ (gcc)](https://tio.run/##Sy4o0E1PTv4PBAA "C++ (gcc) – Try It Online"), [C++ (clang)](https://tio.run/##Sy4o0E3OScxL/w8EAA "C++ (clang) – Try It Online"), [Objective-C (gcc)](https://tio.run/##y0/KSk0uySxL1U3WTU9O/g8EAA "Objective-C (gcc) – Try It Online"), [Objective-C (clang)](https://tio.run/##y0/KSk0uySxL1U3WTc5JzEv/DwQA "Objective-C (clang) – Try It Online") + [shortC](https://tio.run/##K87ILypJ/g8EAA "shortC – Try It Online") * **Java**: It's an error to not have a class to run. + [Java (JDK)](https://tio.run/##y0osS9TNSsn@DwQA "Java (JDK 10) – Try It Online"), [Java (OpenJDK)](https://tio.run/##y0osS9TNL0jNy0rJ/g8EAA "Java (OpenJDK 8) – Try It Online") + [Kotlin](https://tio.run/##y84vycnM@w8EAA "Kotlin – Try It Online") + [Scala](https://tio.run/##K05OzEn8DwQA "Scala – Try It Online") * **C#**: Requires a static `Main` method. + [.NET Core](https://tio.run/##Sy7WTc4vSv0PBAA "C# (.NET Core) – Try It Online"), [Mono](https://tio.run/##Sy7Wzc3Py/8PBAA "C# (Mono C# compiler) – Try It Online"), [Visual C#](https://tio.run/##Sy7WTS5O/g8EAA "C# (Visual C# Compiler) – Try It Online") * **Pascal**: Not having a `BEGIN` to begin with is an error. + [Pascal](https://tio.run/##K0gsTk7M0U0rSP4PBAA "Pascal (FPC) – Try It Online"), [Object Pascal](https://tio.run/##y0/KSk0u0S1ILE5OzNFNK0j@DwQA "Object Pascal (FPC) – Try It Online") * **Visual Basic**: Unlike other `Basic`s, VB requires to have a `Sub Main` to run. + [.NET Core](https://tio.run/##K0vSTc4vSv0PBAA "Visual Basic .NET (.NET Core) – Try It Online"), [Mono](https://tio.run/##K8ssLk3M0U1KLM5M1s1LLdHNzc/L/w8EAA "Visual Basic .NET (Mono) – Try It Online"), [VBC](https://tio.run/##K8ssLk3M0U1KLM5M1s1LLdEtS0r@DwQA "Visual Basic .NET (VBC) – Try It Online") * Other languages that require some kind of `main` to compile and run. + [B](https://tio.run/##q0xK/g8EAA "B (ybc) – Try It Online") + [D](https://tio.run/##S/kPBAA "D – Try It Online") + [Dart](https://tio.run/##S0ksKvkPBAA "Dart – Try It Online") + [Fortran (gfortran)](https://tio.run/##S8svKilKzNNNT4Mw/gMBAA "Fortran (GFortran) – Try It Online") + [Go](https://tio.run/##S8//DwQA "Go – Try It Online") + [Vala](https://tio.run/##K0vMSfwPBAA "Vala – Try It Online") + (Add language here) * Languages that require specific syntax elements to run correctly. + [ArnoldC](https://tio.run/##SyzKy89JSf4PBAA "ArnoldC – Try It Online") + [Shakespeare Programming Language](https://tio.run/##Ky7I@Q8EAA "Shakespeare Programming Language – Try It Online") + [Whitespace](https://tio.run/##K8/ILEktLkhMTv0PBAA "Whitespace – Try It Online") + [Taxi](https://tio.run/##K0msyPwPBAA) + (Add language here) * Languages that specifically reject empty files. + [Chapel](https://tio.run/##S85ILEjN@Q8EAA "Chapel – Try It Online") + (Add language here) * Languages that segfault or otherwise show erroneous behavior with empty files. Some of these might be actually a bug in the compiler/interpreter. + [Backhand](https://tio.run/##S0pMzs5IzEv5DwQA "Backhand – Try It Online"): Tries to access the first instruction and throws an error. + [Check](https://tio.run/##S85ITc7@DwQA "Check – Try It Online") is similarly bugged with empty code. + [ecpp](https://tio.run/##S00uKNBN/g8EAA "ecpp + C (gcc) – Try It Online") segfaults when an empty program is given. + [Seed](https://tio.run/##K05NTfkPBAA "Seed – Try It Online") always gives error if the code isn't *two integers with a space between them*. + (Add language here) [Answer] # 60% of all coding languages, 1 byte `+` or `-` or `/` or `*` or `%` or any valid token etc. To complement Bubbler's answer. [Answer] # Polyglot, 1 byte ``` a ``` This gives `undefined identifier` error in many interpreted languages. * Python * Javascript * APL * J * (Add language here) # Polyglot, 1 byte ``` + ``` This gives `syntax error` in many languages. * (Add language here) # Polyglot, 1 byte ``` ' ``` This gives `open string literal` error in many languages. * (Add language here) # Polyglot, 1 byte ``` [ ``` This gives `open bracket` error in many languages. (Feel free to change to `(` or `{` if some languages specifically error with it.) * (Add language here) [Answer] # Racket / Scheme / Lisp / Others?: 1 byte `)` Will give an error for mismatched parentheses [Answer] # [Ahead](https://github.com/ajc2/ahead), 1 byte ``` / ``` Tries to do `0/0`. Reference implementation on TIO will fail with: ``` Exception in thread "main" java.lang.ArithmeticException: / by zero at ajc2.ahead.Head.doCell(Head.kt:148) at ajc2.ahead.Head.step(Head.kt:31) at ajc2.ahead.Runner.go(Runner.kt:6) at ajc2.ahead.MainKt.main(Main.kt:13) ``` [Try it online!](https://tio.run/##S8xITUz5/1///38A "Ahead – Try It Online") [Answer] # [Attache](https://github.com/ConorOBrien-Foxx/Attache), 1 byte ``` / ``` [Try it online!](https://tio.run/##SywpSUzOSP3/X///fwA "Attache – Try It Online") Crashes with: ``` AttacheUnimplementedError: (1:1) / is not defined for `NilClass` ``` ]
[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/58597/edit). Closed 7 years ago. [Improve this question](/posts/58597/edit) # The Challenge Create a program or function that takes no input, and outputs (or returns): ``` I'm a programming paradox — no I'm not. ``` Without using a character twice in any string, or digit twice in any integer. --- # Rules 1. You may not use any character twice *within a string*. For example, the word `"test"` would violate this rule. 2. You may not use any character twice *between strings*. For example, if somewhere in your code you have the string `"hi"`, no other strings may contain the substring `"h"` or `"i"`. 3. You may not use a digits more than once *within an integer*. For example, the integer `200` would not be acceptable. 4. You may not use a digit more than once *between integers*. For example, if you have the integer `40` in your code, you may not have the integer `304`. 5. The above rules do not apply between data types. You could, for example, have the string `"9"` and the integer `9` in your code. 6. An uppercase letter is considered a separate character from the lowercase. 7. You may only use printable ASCII characters in your strings. 8. You may not set variables to each character and add them together. --- # Example Here is an example, written in Python 2, of what the same challenge might look like with the string "Hello, World!" instead. ``` print"He"+"l"*2+"o, "+"W"+chr(int("1"*3))+"r"+chr(108)+"d!" ``` --- Note: For those wondering why I chose this particular string; I chose it because it has several repeated characters and a repeated word. It has no greater significance or meaning. [Answer] # Python 2, ~~186~~ ~~155~~ ~~139~~ ~~138~~ ~~126~~ ~~109~~ 98 bytes I don't know if this is a loophole... ``` OKDLPLGHFBHPDDCEBLGPHPAFJLMLEFLOKDLEFIN=0 print list(locals())[3].translate("adgimnoprtx' -.I"*16) ``` ~~don't think~~ I can golf more than this... [Answer] ## C++14, 327 bytes ``` #include <iostream> #define x(y) <<(y)[s] std::string s[]={"I'"," ","a","p","r","o","g","m","n","i","d","x","—","t","."};enum{J,S,A,P,R,O,G,M,N,I,D,X,W,T,Z};[]{std::cout x(J)x(M)x(S)x(A)x(S)x(P)x(R)x(O)x(G)x(R)x(A)x(M)x(M)x(I)x(N)x(G)x(S)x(P)x(A)x(R)x(A)x(D)x(O)x(X)x(S)x(W)x(S)x(N)x(O)x(S)x(J)x(M)x(S)x(N)x(O)x(T)x(Z);}(); ``` I'm defining a macro which returns a string to the `<<` operator, mapping the necessary characters in a string array and access them with an `enum` [Answer] # Javascript (ES6), ~~142~~ ~~105~~ ~~98~~ 96 bytes ``` [a="I'm","a",`${y=>programming}`.slice(3),`${no=>paradox}`.slice(4),'-',x="no",a,x+"t."].join` ` ``` Another possible rule-breaker, but it was fun, anyway. :) Original version: ``` [a="I'm",(''+(b=>a)).substr(3),(''+(is=>programming)).substr(4),(''+(Fermi=>paradox)).substr(7),'-',(''+(yes=>no)).substr(5),a,'not.'].join` ` ``` [Answer] # Javascript (ES6), ~~89~~ ~~86~~ 84 Bytes ``` `${y=>I0m3a3programming3paradox313no3I0m3not2}`.slice(3).replace(/\d/g,m=>"'—. "[m]) ``` [Answer] # Haskell, 320 bytes ``` import Data.Char data Letter = A|D|I|I'm|MM|P|R|G|N|O|X|Y|S|T deriving Show transform :: Letter -> String transform S = " " transform Y = "—" transform I'm = "I'm" transform x = map toLower $ show x main :: IO () main = print $ transform =<< [I'm,S,A,S,P,R,O,G,R,A,MM,I,N,G,S,P,A,R,A,D,O,X,S,Y,S,N,O,S,I'm,S,N,O,T] ``` ]
[Question] [ Following this question: [Tut-tut-tut-tut-tut](https://codegolf.stackexchange.com/questions/251772/tut-tut-tut-tut-tut) Write a program that writes "tut-tut-tut" **without** using the characters "t", "u" or "-" in the code itself. This is code golf, shortest code in bytes wins. [Answer] # [Japt](https://github.com/ETHproductions/japt), 9 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) ``` Bî`¡s,`cÄ ``` [Test it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Qu5goXMsYGPE) ``` Bî`¡s,`cÄ B :11 î :Repeat to length B `¡s,` : Compressed string "sts," c : Map charcodes Ä : Add 1 ``` [Answer] # [Windows Batch](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd), 169 115 bytes No code points, but assuming capital letters are OK for the output, as this will produce TuT-TuT-TuT ``` @for /f %%a in ('sc^|find "CO"') do @se%OS:~9% q=%%a @se%OS:~9% a=%q:~8,1%%OS:~9%%q:~6,1%%OS:~9% @echo %a:~1%%a%%a% ``` Length calculated by using Unix/LF as EOL, without an EOL at the end of the last line. Shaved of 54 bytes thanks to @jdt, who posted a solution using code points (which I wanted to avoid), but contained three `t`s. Thinking about ways to fix this made me have another go at mine as well. The first issue with Batch is that you can't even `set` a variable without using a `t`. But Batch will expand variables in a command first and then take the resulting line verbatim, so the forbidden characters can be picked from a variable. As luck would have it, there is a default environment variable with only two letters, and it even has the T at the last position (allowing to drop the substring length when extracting the T): `OS=Windows_NT`. So a `T` in a command line can be replaced by `%OS:~9%`, which solves most of the problems; but no such luck for `U` or `-`. `@for /f %%a in ('sc^|find "CO"') do @se%OS:~9% q=%%a` This will use the help for sc.exe, find the line `continue--------Sends a CONTINUE control request to a service.`, break it into tokens at spaces (discarding empty fields), and set the variable `q` to `continue--------Sends`, where `u` and `-` are at single-digit positions. `@se%OS:~9% a=%q:~8,1%%OS:~9%%q:~6,1%%OS:~9%` This sets `a` to `-TuT` by picking characters from `OS` and `q`. `@echo %a:~1%%a%%a%` This prints `a` three times, with the first instance `%a:~1%` starting with the second character to remove the leading `-`. --- ## Alternative answer by [@jdt](https://codegolf.stackexchange.com/users/41374/jdt), 118 bytes ``` @for %%a in (84,85,84,45,84,85,84,45,84,85,84) do @(cmd /C exi%OS:~9% %%a&echo|se%OS:~9% /p=%%^=Exi%OS:~9%CodeAscii%%) ``` @jdt posted this in a comment for initially 110 bytes, but it used `exit`, `set`, and `ExitCodeAscii` in the original. Replacing the `t`s with `%OS:~9%` brought it to 128, some more golfing brought it down to a one-liner with 118 bytes. --- --- ## Previous version ``` @for /f %%a in ('help^|find "SE%OS:~9,1% "') do @%%a s=%%a @for /f "delims=" %%a in ('wmic/?^|find "/E"') do @%s%q=%%a @%s%a=%q:~10,1%%q:~3,1%%q:~1,1%%q:~3,1% @echo %a:~1%%a%%a% ``` Used the line `SET Displays, sets, or removes Windows environment variables.` of the `help` output to set a variable to `SET` . Above is the "safe" version (178 bytes) that should work with localized versions as well. In the optimized version for **English** versions of cmd.exe **only** (otherwise the first line might run some unexpected commands, and/or not work at all), the first line changes to this, for a total of 169 bytes: `@for /f %%a in ('help^|find "s e"') do @%%a s=%%a` (this line ends with a trailing space!) [Answer] # [BQN](https://mlochbaum.github.io/BQN/), 11 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn) ``` 11⥊"rsr+"+2 ``` `"rsr+"+2` add 2 to the code points of "rsr+" giving "tut-" `11⥊` cyclically reshape to length 11 [Run online!](https://mlochbaum.github.io/BQN/try.html#code=ZuKGkDEx4qWKInJzcisiKzI=) [Answer] # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell) (Core or Windows), 46 bytes No code points; taking advantage of the long cmdlet names for a change ... ``` $ofs='';"$((gal oh|% R*e)[3,2,1,2])"*3|% S*g 1 ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XyU/rdhWXd1aSUVDIz0xRyE/o0ZVIUgrVTPaWMdIx1DHKFZTScsYKBasla5g@P8/AA "PowerShell – Try It Online") ``` $ofs=''; # set the output field separator to an empty string gal oh # gal is an alias for Get-Alias; oh is an alias for Out-Host; returns an AliasInfo object |% R*e # pipe the AliasInfo object for "oh" to % (an alias for ForEach-Object), and call its member ResolvedCommandName, which will return the string "Out-Host" ( )[3,2,1,2] # take the characters at positions 3, 2, 1, 2 from "Out-Host" (-, t, u, t) "$( )" # evaluate that in a subexpression $() and stuff it all into a single string "-tut" *3 # "multiply" with 3 to get "-tut-tut-tut" |% S*g 1 # pipe that to ForEach-Object again, and call its member "SubString" to get everything starting at position 1 ``` [Answer] # Python 2.7 and 3.xx, ~~45~~ 44 bytes This was harder and easier than I though... ``` exec('prin\x74(("\x2d\x74\x75\x74"*3)[1:])') ``` I've tested it on Python 2.7.11+, 3.9.6 and 3.10.5. Good 'ol ~~evil~~ ~~eval~~ exec to the rescue! --- Thanks to [@Dingus](https://codegolf.stackexchange.com/users/92901/dingus) for pointing out a mistake, and [@Bubbler](https://codegolf.stackexchange.com/users/78410/bubbler) for saving 1 byte. --- --- # Alternative answers Personally, I feel these are against the spirit of the challenge, and that's why they aren't replacing the "main" answer. ## Python 2.7 and 3.xx, 40 bytes This is an alternative provided by [@Bubbler](https://codegolf.stackexchange.com/users/78410/bubbler). It uses "TUT" instead of "tut", for the string, saving 1 byte. I modified a little, to save 3 more bytes. ``` exec('prinT(("\x2dTUT"*3)[1:])'.lower()) ``` This was edited to use `exec` to run in Python 2.7. ## Python 2.7 and 3.xx, 40 bytes This alternative was written by [@py3programmer](https://codegolf.stackexchange.com/users/110681/py3programmer). It produces the correct output, and avoids the `[1:]` string indexing. ``` exec("prinT('TUT\x2d'*2+'TUT')".lower()) ``` [Answer] # [C (clang)](http://clang.llvm.org/), 51 bytes ``` i;f(*b){for(i=0;i<4;b[i++]=i^3?762606932:7632244);} ``` [Try it online!](https://tio.run/##S9ZNzknMS///P9M6TUMrSbM6Lb9II9PWwDrTxsQ6KTpTWzvWNjPO2N7czMjMwMzS2MjK3MzYyMjERNO69n9mXolCbmJmnoamQjWXAhCABJJK06ItDGKtwQJpGkCuJoRdUASUTtNQUi1W0lGACNf@/5eclpOYXvxftxwA "C (clang) – Try It Online") # [C (clang)](http://clang.llvm.org/), ~~69~~ 63 bytes ``` f(){syscall(1,1,L"\x2d747554\x2d747574\x2d747574\x747574",15);} ``` [Try it online!](https://tio.run/##S9ZNzknMS///P01Ds7q4sjg5MSdHw1DHUMdHKabCKMXcxNzU1ATGMkdhQWglHUNTTeva/7mJmXkamgrVXApAADTMmqv2/7/ktJzE9OL/uuUA "C (clang) – Try It Online") -6 bytes thanks to ceilingcat!! [Answer] # Ruby, 70 bytes ``` p"#{[116,117,116,45,116,117,116,45,116,117,116].map{|c|c.chr}.join()}" ``` [Try it online!](https://tio.run/##KypNqvz/v0BJuTra0NBMx9DQXAdEm5jq4ObG6uUmFlTXJNck6yVnFNXqZeVn5mlo1ir9/w8A) [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 12 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) Four different alternatives: ``` …TUTl45ç«11∍ .•x`•45ç«11∍ '±È3£45ç«6∍û "vwv/"ÇÍç6∍û ``` [Try it online.](https://tio.run/##yy9OTMpM/f//UcOykNCQHBPTw8sPrTY0fNTRq8Ol96hhUUUCkEARVT@08XCH8aHFEEEzoNjh3TpcSmXlZfpKh9sP9x5eDhX7/x8A) Without the [restricted-source](/questions/tagged/restricted-source "show questions tagged 'restricted-source'") it would have been just 3 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) shorter: ``` "tut-"11∍ ``` [Try it online.](https://tio.run/##yy9OTMpM/f9fqaS0RFfJ0PBRR@///wA) **Explanation:** Part 1 alternatives: ``` …TUT # Push string "TUT" l # Convert it to lowercase 45 # Push 45 ç # Convert it to a character with this codepoint: "-" « # Append the two together: "tut-" .•x`• # Push compressed string "tut" 45ç« # Same as above '±È '# Push dictionary string "tutorial" 3£ # Only keep its first 3 characters: "tut" 45ç« # Same as above "vwv/" # Push string "vwv/" Ç # Convert it to a list of its codepoint-integers: [118,119,118,47] Í # Decrease each by 2 ç # Convert it from codepoint-integers to a list of characters ``` Part 2 alternatives: ``` 11∍ # Extend it to size 11: "tut-tut-tut" # (after which the result is output implicitly) 6∍ # Extend it to size 6: "tut-tu" û # Palindromize it: "tut-tut-tut" # (after which the result is output implicitly) ``` [See this 05AB1E tip of mine (sections *How to use the dictionary?* and *How to compress strings not part of the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `.•x`•` is `"tut"` and `'±È` is `"tutorial"`. ]
[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/158134/edit). Closed 5 years ago. [Improve this question](/posts/158134/edit) As the title says, your task is to print the largest string using the shortest code without taking any input value. ## Rules * The program must take no input and print the largest string to STDOUT * The string must contain only ASCII Characters. If you don't know the ASCII Characters, take a look at the [table](https://www.asciitable.com/) * No Loops are allowed * No multiplication, exponentiation or any kind of elevation is permitted. * The score is measured by subtracting the amount of bytes of your code to the amount of bytes of your string. Example. My code is `60` Bytes and it generates an string of `300` Bytes. My score will be `300-60=240` * The highest score wins. ## Example ``` try{a.b}catch(e){alert(e)} ``` The output of my program is `ReferenceError: a is not defined` = 32 bytes My Score will be `32-26` = 6 --- ## Update By Loops i mean any repetitive structure. For example `for`, `while`, `do while`, `recursive functions` etc.. [Answer] # R, 541-9 = 532 When passing a built-in function name to R, the console describes it parameters. I'm sure there are longer ones, but I went for the low-hanging fruit Code: ``` .packages ``` Output: ``` function (all.available = FALSE, lib.loc = NULL) { if (is.null(lib.loc)) lib.loc <- .libPaths() if (all.available) { ans <- character() for (lib in lib.loc[file.exists(lib.loc)]) { a <- list.files(lib, all.files = FALSE, full.names = FALSE) pfile <- file.path(lib, a, "Meta", "package.rds") ans <- c(ans, a[file.exists(pfile)]) } return(unique(ans)) } s <- search() invisible(.rmpkg(s[substr(s, 1L, 8L) == "package:"])) } <bytecode: 0x103fdf200> <environment: namespace:base> ``` Edit: Thanks Giuseppe for the [link](https://tio.run/##K/r/X68gMTk7MT21@P9/AA) [Answer] # [Python 3](https://docs.python.org/3/), 937 ``` help() ``` [Try it online!](https://tio.run/##K6gsycjPM/7/PyM1p0BD8/9/AA "Python 3 – Try It Online") ]
[Question] [ Your program is supposed to create a full red screen in MSDOS. The source of the binary (.com file) must be 5 bytes or less. No wild assumptions, the binary must work in MsDos, DosBox, and FreeDos alike. For winning, you have to post x86 assembler code which can be assembled with NASM (FASM) or directly the hex code of the binary. You can test you assembler code in an Online Dosbox. Code Example (six bytes): ``` X les cx,[si] inc sp stosb jmp short X+1 ``` [Try x86 asm code in an Online DosBox](http://twt86.co/) [Information on sizecoding for Msdos](http://www.sizecoding.org/wiki/Main_Page) ["M8trix" might be helpful](http://www.sizecoding.org/wiki/M8trix_8b) [Background information/ six bytes version](https://www.pouet.net/topic.php?which=11991) [Answer] **5 bytes** *Byte values* ``` 0x56 0xC4 0x04 0xAB 0xC3 ``` *ASM mnemonic* ``` PUSH SI LES AX,[SI] STOSW RET ``` *View inside a DOS debugger* [![View inside a DOS debugger](https://i.stack.imgur.com/F8hzF.png)](https://i.stack.imgur.com/F8hzF.png) (edit:) To clarify, this is NOT MY solution. The challenge is mirrored from [www.pouet.net](http://www.pouet.net), as linked in the question. There, somebody posted a valid solution which i pasted here. (edit2: added byte values and image) ]
[Question] [ Your friend has been caught sleeping in class again! As punishment, his computer science teacher has assigned him homework, knowing that he will not be able to solve it due to not having paid any attention. The assignment seems deceiving simple at first; all that is required is to output the string: ``` John Doe ``` Unfortunately, the teacher is intent on making the simple assignment much more difficult. Since your friend was not listening when the teacher explained the concept of strings and numbers, the teacher forbids him from using any number character (0-9) or the quotes (`"`, `'`, ```). Can you help your friend solve this problem with the shortest code possible, and save his computer science grade in the process? Try to find the shortest code in each language! Note: it is encouraged to try to solve this problem in languages where string/character literals exist but cannot be used due to the restrictions (most mainstream languages are like this, e.g. C++). [Answer] # C, 41 bytes ``` #define p(x)puts(#x) main(){p(John Doe);} ``` [Try it online!](https://tio.run/##S9ZNT07@/185JTUtMy9VoUCjQrOgtKRYQ7lCkys3MTNPQ7O6QMMrPyNPwSU/VdO69v9/AA) `#` converts a token passed to a macro to a string literal. [Answer] # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 51 bytes ``` #John Doe (gc $PsCommandPath)[+$x]-replace(echo \#) ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X9krPyNPwSU/lUsjPVlBJaDYOT83NzEvJSCxJEMzWlulIla3KLUgJzE5VSM1OSNfIUZZ8/9/AA "PowerShell – Try It Online") # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 59 54 bytes ``` $x++;$x++ -join((echo John),(echo Doe).PadLeft($x+$x)) ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X6VCW9saQXDpZuVn5mlopCZn5Ct45WfkaepA2C75qZp6AYkpPqlpJRra2ioVmpr//wMA "PowerShell – Try It Online") # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 56 bytes ``` -join((echo John),[char](++$x-shl$x+++$x+$x),(echo Doe)) ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XzcrPzNPQyM1OSNfwSs/I09TJzo5I7EoVkNbW6VCtzgjR6VCG8QEIk0diDKX/FRNzf//AQ "PowerShell – Try It Online") # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 57 bytes ``` -join((echo John),[char]([char](echo !)-++$x),(echo Doe)) ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XzcrPzNPQyM1OSNfwSs/I09TJzo5I7EoVgNKgSUUNXW1tVUqNHUgXJf8VE3N//8B "PowerShell – Try It Online") # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), The Most Trivial Solution™, 10 bytes (I'm sorry, I said I wanted to avoid trivial solutions, but I did not know this was possible, and felt that this method might benefit PS solutions to other challenges) ``` {John Doe} ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/v9orPyNPwSU/tfb/fwA "PowerShell – Try It Online") [Answer] # [JavaScript (V8)](https://v8.dev), ~~80~~ ~~77~~ ~~76~~ ~~65~~ ~~40~~ ~~34~~ 20 bytes ``` _=>/John Doe/.source ``` Turns out the `_=>` might be required. **History:** ``` /John Doe/.source ``` Oh there's a trivial way to do it. I just wasted an hour :/ **31:** ``` (/John Doe/+[]).slice(-~[],~[]) ``` Finally found a way to get rid of that pesky `toString` :p **37:** ``` /John Doe/.toString().slice(-~[],~[]) ``` Why use the function thing at all? **62:** ``` (function John_Doe(){}).name.replace(/_/,/ /.toString()[-~[]]) ``` I probably should have thought about using `/ /` sooner... **73:** ``` (function John_Doe(){}).name.replace(/_/,{}.toString(x=true)[x-~x-~x-~x]) ``` I wasted twenty minutes trying to do this character by character then remembered this. Golfed three bytes by using `-~x`, which is the same as `+2`. [Answer] # [Vyxal](https://github.com/Lyxal/Vyxal), `s`, 16 bytes ``` \J\o\h\nð\D\o\eW ``` [Try it Online!](http://lyxal.pythonanywhere.com?flags=s&code=%5CJ%5Co%5Ch%5Cn%C3%B0%5CD%5Co%5CeW&inputs=&header=&footer=) ## Explained ``` \J\o\h\n # Push the characters J, o, h and n ð # Push a space \D\o\e # Push the characters D, o and e W # Wrap everything into a list. The s flag joins on newlines ``` [Answer] # [Python 3](https://docs.python.org/3/), ~~55~~ ~~43~~ 28 bytes Saved 12 bytes thanks to [Makonede](https://codegolf.stackexchange.com/users/94066/makonede)!!! Saved 15 bytes thanks to [ovs](https://codegolf.stackexchange.com/users/64121/ovs)!!! ``` print(*dict(John=[],Doe=[])) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EQyslM7lEwys/I882OlbHJT8VSGlq/v8PAA "Python 3 – Try It Online") [Answer] # CW for languages where the program `John Doe` is valid Feel free to add to this list if you find a solution in another language. **NOTE:** Text editors have been excluded as there are way too many of them. # [///](https://esolangs.org/wiki////) # [Charcoal](https://github.com/somebody1234/Charcoal) # [GS2](https://github.com/nooodl/gs2) # [HTML](https://html.spec.whatwg.org) # [Keg](https://github.com/Lyxal/Keg) # [PHP](https://php.net) # [Quine](https://esolangs.org/wiki/Quine_(programming_language)) # [Text](https://esolangs.org/wiki/Text) [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes ``` ”„ÐÒ« ``` [Try it online!](https://tio.run/##yy9OTMpM/f//UcPcRw3zDk84POnQ6v//AQ "05AB1E – Try It Online") ``` ”„ÐÒ« # full program ”„ÐÒ« # push "John Doe" # implicit output ``` [Answer] # [Perl 5](https://www.perl.org/) -M5.10.0, 15 bytes ``` say q(John Doe) ``` [Try it online!](https://tio.run/##K0gtyjH9/784sVKhUMMrPyNPwSU/VfP//3/5BSWZ@XnF/3V9TfUMDfQMAA "Perl 5 – Try It Online") I don't know whether -M5.10.0 is optimal, I just cargo culted it from a random Perl answer. [Answer] # Java, 166 bytes ``` $->{class John_Doe{}final char o=Byte.MAX_VALUE/Byte.MAX_VALUE,t=o+o,f=t+t+o,T=f+f,u=T*T-f,s=f*(f+o)+t;System.out.print(John_Doe.class.getSimpleName().replace(u,s));} ``` [Try it online!](https://tio.run/##VVDLTsMwELznK3zgYOdhPiC4UnlcEOWSUCEhVBnXTh0cO7LXlaoo3x4MhUrsZTSzo53d7fmRV/3@c9HD6DygPnEaQRuqohWgnaV5nY3xw2iBhOEhoA3XFk0ZSvWrB@CQ4Oj0Hg2pixvw2nZv74j7LpCz97vunA1xkP5mm6wrJNhyVa2m89hHd7C7eyenWWnLDRIH7pFjtyeQdLN@3W3XTy8P1/9pCcwVrlQMCkjYMlWoMrI2bytVBqZyrApHCqibUwA5UBeBjmk1wH9p9CecdhKa9AEjn/kgMaFejoYLiWMZCKnnpb6cICgXQo6AbTSGnPU5m5cv) # Java, 192 bytes ``` a->{final char O=Byte.MAX_VALUE/Byte.MAX_VALUE,T=O+O,t=T+O,F=t+T,S=F+T,Z=F+F,Y=Z*Z,o=Y+Z+O,J=S*Z+T+T,h=Y+T+T,n=Y+Z,$=Z*t+T,D=F*Z+Z+F+t,e=Y+O;System.out.print(String.valueOf(J)+o+h+n+$+D+o+e);} ``` This uses `Byte.MAX_VALUE/Byte.MAX_VALUE` to obtain the number `1` and then uses it to construct the ASCII codes of all the characters in the string. `final` is needed so that casts from `int` to `char` are not necessary. [Try it online!](https://tio.run/##VY/BboMwEETv@QofcgDsuB9AHSltyiFqxAEaNVRV5RITTI2NYB0pivLtdFGiSt3DrHfe@DCNPMlFc/gZddu5HkiDN/egDa@8LUE7y6N41vlvo0tSGjkMZCu1JZcZwbn7A0jAdXL6QFqkQQa9tsePTyL74xDestM8Ozv4VvWPO4wuSSVGuVheKm2lIWUte5KKpzMovl29f@1Wr28vD/9PlouUpgxEjpoIoDnLRIJaoCZsL4qoYE7saYF8I7KooDnSGp1p24mwOaamn2uRIC9oQoEpJGmcnQdQLXceeIcF4N6Dn6TxKq2CTUgdramlc7rGlwrj6xj/lau4LEvVQWC9MeHNv86u4y8) [Answer] # JavaScript, 32 bytes ``` _=>(/John Doe/+[]).slice(-~_,~_) ``` When the function is called without arguments, the first argument will be `undefined` and `~undefined` produces `-1`. [Try it online!](https://tio.run/##y0osSyxOLsosKNEts/ifZvs/3tZOQ98rPyNPwSU/VV87OlZTrzgnMzlVQ7cuXqcuXvN/cn5ecX5Oql5OfrpGmoam5n8A) *Thanks to [tsh](https://codegolf.stackexchange.com/users/44718) for the idea* # JavaScript (V8), 39 bytes ``` print(...Object.keys({John:[],Doe:[]})) ``` `print` uses a space to separate arguments when printing. [Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/v6AoM69EQ09Pzz8pKzW5RC87tbJYo9orPyPPKjpWxyU/FUjVamr@/w8A) [Answer] # Windows Batch, 13 bytes ``` echo John Doe ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes ``` “®ƊʠỌḂŒ» ``` [Try it online!](https://tio.run/##ARwA4/9qZWxsef//4oCcwq7Gisqg4buM4biCxZLCu/// "Jelly – Try It Online") The `“` at the beginning isn't defined as a quote in the challenge, so Id say this is valid. [Answer] # [PowerShell Core](https://github.com/PowerShell/PowerShell), 19 bytes ``` Write-Host John Doe ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNydFNzi9K/f8/vCizJFXXI7@4RMErPyNPwSUfKAgA "PowerShell Core – Try It Online") ``` Write-Host John Doe # full program Write-Host # output... John Doe # literal ``` [Answer] # [Bubblegum](https://esolangs.org/wiki/Bubblegum), ~~10~~ 7 bytes *-3 bytes by [@tsh](https://codegolf.stackexchange.com/users/44718/tsh).* ``` ´H&ÒF ``` [Try it online!](https://tio.run/##SypNSspJTS/N/f/fAAqsFAySkkwUTCyMzBQMjFKMFEzMFBT09DzU9PTc/v8HAA "Bubblegum – Try It Online") This program gets converted to base 256, then to base 96, and each digit \$n\$ gets replaced with the \$n\$th printable ASCII character. Hexdump: ``` 00000000: 0bb4 4826 02d2 46 ..H&..F ``` [Answer] # Notepad / Gedit, 15 keystrokes ``` SHIFT+J o SHIFT+LEFT ARROW CTRL+C RIGHT ARROW h n D CTRL+V e ``` # Notepad / Gedit (Boring solution), 8 keystrokes ``` J o h n D o e ``` [Answer] # [brainfuck](https://github.com/TryItOnline/brainfuck), 91 bytes ``` -[------->+<]>+.[-->+++<]>.-------.++++++.-[->+++++<]>-.++[->++<]>.[--->+<]>+++.----------. ``` [Try it online!](https://tio.run/##SypKzMxLK03O/v9fN1oXAuy0bWLttPWiQSxtEFsPKqGnDQZ6QJV2YBZQDiQI5oLURcN1g1TBgd7//wA "brainfuck – Try It Online") [Answer] # [Julia](http://julialang.org/), 38 bytes ``` print(:John,Char(ceil(π*π*π)),:Doe) ``` [Try it online!](https://tio.run/##yyrNyUw0rPj/v6AoM69Ew8orPyNPxzkjsUgjOTUzR@N8gxYYaWrqWLnkp2r@/w8A "Julia 1.0 – Try It Online") [Answer] # [Java (JDK)](http://jdk.java.net/), 134 bytes ``` class John{public static void main(String[]z){System.out.print(John.class.getName()+(char)Float.SIZE+Doe.class.getName());}}enum Doe{} ``` # [Java (OpenJDK 8)](http://openjdk.java.net/), 131 bytes ``` interface John{static void main(String[]z){System.out.print(John.class.getName()+(char)Float.SIZE+Doe.class.getName());}}enum Doe{} ``` This is an everything java solution - count in the whole file, header and footer. No tio.run link because it depends on the class name, which must be `John` in this case. In Java 8+ you can make it an `interface` and omit `public` in the main method for -3. `Float.SIZE` and `Integer.SIZE` return `32`, the char code for a space. In this case, `getName()`, `getTypeName()`, `getSimpleName()`, and `getCanonicalName()` will all return just the desired name part of the class/enum. You can make `John` an `enum` for -1, but it would require an extra `;` at the start to declare the enum objects, +1, making it equal length. You can run this to verify whether it prints the correct String (and that the space character is an actual space, because doing `(char)0`, for example, will leave a blank spot without it technically being a space): ``` interface John { // or class public static void main(String[]z) { System.out.print((John.class.getName() + (char) Float.SIZE + Doe.class.getName()) .equals("John Doe")); } } enum Doe{} ``` [Answer] # [Pxem](https://esolangs.org/wiki/Pxem), 10 bytes of file name + 0 bytes of content = 10 bytes * Filename: `John Doe.p` * Content is empty What a low effort. [Answer] # [Deadfish~](https://github.com/TryItOnline/deadfish-), 70 bytes ``` {i}dds{i}c{iiii}dddc{d}iiiciiiiiic{{d}ii}iic{iii}iiiiiic{iiii}iiic{d}c ``` [Try it online!](https://tio.run/##LYoxDgAgDAJf5KMMaGR2bPr2WqsMwBE4Oqf2ahEmJ3c6TKkEwuhZoRKs0G9T5Vv14b4RcQA "Deadfish~ – Try It Online") It somehow beats Java! [Answer] # [Vyxal](https://github.com/Lyxal/Vyxal), 8 bytes ``` «:L∞I\«ǐ ``` [Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C2%AB%3AL%E2%88%9EI%5C%C2%AB%C7%90&inputs=&header=&footer=) Explanation: ``` «:L∞I\« # Base-256 compressed "john doe" ǐ # Convert To Title Case # Implicit output ``` Vyxal doesn't support capital letters in compressed strings, which is why the `ǐ` command is needed. [Answer] # [PHP](https://php.net), 8 bytes ``` John Doe ``` [Try it online!](https://tio.run/##K8go@P/fKz8jT8ElP/X/fwA "PHP – Try It Online") ``` John Doe # full program John Doe # no leading <?, so outputs source ``` [Answer] # [Python 2](https://docs.python.org/2), ~~56~~ 14+8=22 bytes ``` print __file__ ``` Must be saved in a file called `John Doe` in the root directory. However, the path may not even contain a single `/` for this to work. Therefore, this file's full path should be only `John Doe`, and not `/John Doe` or `C:/John Doe`. Theoretically possible but not sure how in practice. NB: Adding the lengths of the file name and the code was somehow the shortest approach I could find to this challenge (in Python). [Answer] # [Bash](https://www.gnu.org/software/bash), 13 bytes ``` echo John Doe ``` [Try it online!](https://tio.run/##S0oszvj/PzU5I1/BKz8jT8ElP/X/fwA "Bash – Try It Online") ``` echo John Doe # full program echo # output... John Doe # literal ``` ]
[Question] [ Use any programming language to display numbers divisible by 1000000 that are greater than 1 and less than 10000000. Each number should be displayed in new line. Your program should display exactly: ``` 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 ``` [Answer] # Japt `-R`, 5 bytes ``` 9õ*L³ ``` [Test it](https://ethproductions.github.io/japt/?v=1.4.6&code=OfUqTLM=&input=LVI=) --- ## Explanation ``` 9õ :Range [1,9] * :Multiply each by L :100 ³ :Cubed :Implicitly join with newlines and output ``` [Answer] # [Python 2](https://docs.python.org/2/), 29 bytes ``` i=0;exec'i+=10**6;print i;'*9 ``` [Try it online!](https://tio.run/##K6gsycjPM/r/P9PWwDq1IjVZPVPb1tBAS8vMuqAoM69EIdNaXcvy/38A "Python 2 – Try It Online") [Answer] # [Bash](https://www.gnu.org/software/bash/), 13 bytes ``` seq {1,1,9}e6 ``` [Try it online!](https://tio.run/##S0oszvj/vzi1UKHaUMdQx7I21ez/fwA "Bash – Try It Online") This answer is found out by [@manatwork](https://codegolf.stackexchange.com/users/4198/manatwork) [Answer] # [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 85 bytes ``` [S S S N _Push_0][N S S N _Create_Label_LOOP][S S S T N _Push_1][T S S S _Add][S N S _Duplicate][S S S T S T S N _Push_10][T S S T _Subtract][N T S S N _If_0_Jump_to_Label_EXIT][S N S _Duplicate][S S S T T T T T S T S S S N _Push_1000][S N S _Duplicate][T S S N _Multiply][T S S N _Multiply][T N S T _Print_number][S S S T S T S N _Push_10][T N S S _Print_character][N S N N _Jump_to_Label_LOOP] ``` Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only. `[..._some_action]` added as explanation only. [Try it online](https://tio.run/##LYxdCgAgCIOf3Sl2tQih3oKCjm/@pAy3D@Yd8@herasZScDlVyBkWYpvxGT4LIbCAsFTaX8hPwFmDw) (with raw spaces, tabs and new-lines only). **Pseudo-code:** ``` Integer i = 0 Start LOOP: i = i + 1 If(i == 10): Exit with an error Integer j = 1000 * 1000 * i Print j as number to STDOUT Print "\n" Go to next iteration of LOOP ``` [Answer] # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 14 bytes ``` 1..9|%{$_*1e6} ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/31BPz7JGtVolXssw1az2/38A "PowerShell – Try It Online") Simply loops from `1` to `9` and multiplies each by `1e6`, i.e., `1000000`, to give the appropriate numbers. Ho-hum boring. Saved 7 bytes thanks to mazzy. Previous versions: --- ### [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 21 bytes ``` 1..9|%{"$_"+"000000"} ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/31BPz7JGtVpJJV5JW8kADJRq//8HAA "PowerShell – Try It Online") Boring simple loop from `1` to `9` that just string-concatenates the output together. --- ### [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 21 bytes ``` 1e6..9e6|?{!($_%1e6)} ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/3zDVTE/PMtWsxr5aUUMlXhXI16z9/x8A "PowerShell – Try It Online") Loops from `1e6` to `9e6`, pulls out those entries where they're divisible by `1e6`. Times out on TIO but works offline. [Run it with 3 instead of 6](https://tio.run/##K8gvTy0qzkjNyfn/3zDVWE/PMtW4xr5aUUMlXhXI16z9/x8A "PowerShell – Try It Online") to see the logic better. [Answer] # [Neim](https://github.com/okx-code/Neim), 8 bytes ``` 9Δμ7𝕎𝕋)_ ``` [Try it online!](https://tio.run/##y0vNzP3/3/LclHN7zD/MndoHxN2a8f///8svKMnMzyv@r5sHAA "Neim – Try It Online") [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) ``` 9L6°*» ``` [Try it online.](https://tio.run/##yy9OTMpM/f/f0sfs0AatQ7v//wcA) **Explanation:** ``` 9L # List in the range [1,9] 6°* # Multiply each by 10**6 » # Join the list by newlines (and output implicitly) ``` [Answer] # Java 11, ~~62~~ ~~61~~ ~~56~~ 54 bytes ``` v->{for(int i=0;i++<9;)System.out.println(i*1000000);} ``` -2 bytes thanks to *@ggorlen*. [Try it online.](https://tio.run/##LY4xDoMwDEV3TuExKQLRsUrpDWBB6lJ1cANUpiEgEiJViLOngeLB1rf1n3@HDpOu/nip0BgokPQSAZC2zdSibKDcJIAbqAbJ7ttwXITdGoVmLFqSUIKGHLxLbks7TCy4gfJMUBxfL4JXX2ObPh1mm45TuCnN6HTO9uJi9WIjjfNLBdIB3N/1IQyrbLC8H09A/k@iU8n0rNQRYvU/) **Explanation:** ``` v->{ // Method with empty unused parameter and no return-type v->{for(int i=0;i++<9;) // Loop `i` in the range (0,9] System.out.println( // Print without trailing newline: i*1000000);} // `i` multiplied by 1,000,000 ``` [Answer] # [Python 3](https://docs.python.org/3/), 35 bytes ``` for i in range(1,10):print(i*10**6) ``` [Try it online!](https://tio.run/##K6gsycjPM/7/Py2/SCFTITNPoSgxLz1Vw1DH0EDTqqAoM69EI1PL0EBLy0zz/38A "Python 3 – Try It Online") [Answer] # [Keg](https://github.com/JonoCode9374/Keg), 17 bytes ``` Ϩ²:( ;|:. ,':"+ ``` [Try it online!](https://tio.run/##y05N/////IpDm6w0uKxrrPS4dNStlLT//wcA "Keg – Try It Online") ## Explanation ``` Ϩ # Push 1k ² # Square the value :( # Copy the value for the accumulator ;| # Repeat 10-1 times: :. # Print TOS , # Print newline ':" # Copy 1m to TOS + #Add the values ``` # [Keg](https://github.com/JonoCode9374/Keg), 8 bytes (SBCS) (Doesn't seem to work online yet) ``` 9Ï_⑷ė6Ë* ``` [Try it online!](https://tio.run/##y05N///f8nB//KOJ249MNzvcrfX//3/dgrz/unn5AA "Keg – Try It Online") ## Explanation ``` 9Ï_ #Generate range 1-9 by generating range 0-9 and discarding 0 ⑷ #Map the following to each element: ė6Ë* # Multiply each by 10 to the power of 6 #-pn puts newlines between each item, which is printed using -no ``` [Answer] # [W](https://github.com/A-ee/w) `n` `d`, 5 bytes ``` -í╞6\ ``` ## Explanation Decompressed: ``` 9 M % Map in the range 1..9 a * % Multiply the current item by ... 6^ % ... 10 to the power of 6 ``` [Answer] # [JavaScript (Node.js)](https://nodejs.org), 35 bytes ``` for(i=0;i++<9;)console.log(i*10**6) ``` [Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/Lb9II9PWwDpTW9vG0lozOT@vOD8nVS8nP10jU8vQQEvLTPP/fwA "JavaScript (Node.js) – Try It Online") [Answer] # [Attache](https://github.com/ConorOBrien-Foxx/Attache), 16 bytes ``` Output[1:9*10^6] ``` [Try it online!](https://tio.run/##SywpSUzOSP3/37@0pKC0JNrQylLL0CDOLPb/fwA "Attache – Try It Online") ## Explanation ``` Output[1:9*10^6] 1:9 the range from 1 to 9 *10^6 multiplied by 10^6 (1e6) Output[ ] output each entry on its own line ``` [Answer] # [///](https://esolangs.org/wiki////), 29 bytes ``` /!/000000 /1!2!3!4!5!6!7!8!9! ``` [Try it online!](https://tio.run/##K85JLM5ILf7/X19R3wAMuPQNFY0UjRVNFE0VzRTNFS0ULRX//wcA "/// – Try It Online") 33 bytes for no trailing newline: ``` /"/000//!/"" /1!2!3!4!5!6!7!8!9"" ``` [Try it online!](https://tio.run/##K85JLM5ILf7/X19J38DAQF9fUV9JiUvfUNFI0VjRRNFU0UzRXNFC0VJJ6f9/AA "/// – Try It Online") [Answer] # C++ 44 bytes ``` for(int i=1;i<=9;i++){cout<<i*100**6<<endl;} ``` [Answer] # [Retina](https://github.com/m-ender/retina/wiki/The-Language), 16 bytes ``` 9* L$`. $.>`6*0 ``` [Try it online!](https://tio.run/##K0otycxLNPz/n8tSi8tHJUGPS0XPLsFMy@D/fwA "Retina – Try It Online") Explanation: ``` 9* ``` Insert 9 `_`s. ``` L$`. ``` List a value for each `_`. ``` $.>`6*0 ``` Number of characters up to and including the current `_` followed by six zeros. [Answer] # [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 48 44 bytes ``` for(int i=0;i++<9;)Console.WriteLine(i*1e6); ``` [Try it online!](https://tio.run/##BcGxCsIwEAbgV7kxsSi6CCU6SFedHJxDesoP9Q5y14KUPnv8vmL7opXbbJAPPX/m/E1UpmxGN1rJPDsKLYqRHhkSIq3trTVAnHA9JnTdpU9xUDGd@PCqcL5DOGB34nNMbdvaHw "C# (.NET Core) – Try It Online") *-4 bytes: changed* `i*1000000` *to* `i*1e6` *in* `Console.WriteLine()` Ungolfed: ``` for (int i = 0; i++ < 9;) // from 1 to 9 Console.WriteLine(i * 1e6); // write i times 1,000,000 (1e6 = 1*(10^6) = 1,000,000) to the console ``` [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 7 [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") Full program. ``` ⍪1E6×⍳9 ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKO94P@j3lWGrmaHpz/q3WwJEvmvAAYFAA "APL (Dyalog Unicode) – Try It Online") `⍳9` **ɩ**ndices one through nine `1E9×` multiply million by those `⍪` columnify [Answer] # [Ruby](https://www.ruby-lang.org/en/), 30 24 bytes ``` (1..9).map{|d|p d*10**6} ``` [Try it online!](https://tio.run/##KypNqvz/X8NQT89SUy83saC6JqWmQCFFy9BAS8us9v9/AA "Ruby – Try It Online") -6 bytes: use `map` instead of `step`. Use `10**6` instead of `1e6.to_i` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes ``` 9Rȷ6×Y ``` [Try it online!](https://tio.run/##y0rNyan8/98y6MR2s8PTI///BwA "Jelly – Try It Online") # Explanation ``` 9R [1, 2, ..., 8, 9] ȷ6 100000 × Multiply each Y Join by newline ``` [Answer] # x86-16 machine code, IBM PC DOS, ~~31~~ 26 bytes ``` 00000000: ba10 018b fab1 09b4 09cd 21fe 05e2 fac3 ..........!..... 00000010: 3130 3030 3030 300d 0a24 1000000..$ ``` Listing: ``` BA 0110 MOV DX, OFFSET O ; DOS pointer to output string 8B FA MOV DI, DX ; pointer to defrerence for increment B1 09 MOV CL, 9 ; counter to 9 8A E1 MOV AH, CL ; DOS write string function also to 9 LOOPY: CD 21 INT 21H ; write string to stdout FE 05 INC BYTE PTR[DI] ; increment first digit E2 FA LOOP LOOPY ; loop 9 times C3 RET ; return to DOS O: DB '1000000',0DH,0AH,'$' ; output string ``` Standalone DOS executable, output to STDOUT. [![enter image description here](https://i.stack.imgur.com/wFZpi.png)](https://i.stack.imgur.com/wFZpi.png) *TODO: re-do screenshot with old program length!* ]
[Question] [ This is my 12th question, so I thought of this idea. Goal: * Output 12, with **any preceding or trailing whitespace permitted** * **In as many languages as possible** (where different versions or flags **count as the same language**) * **Without using any numbers** * The criteria for a valid programming language are the same as those of [The Programming Language Quiz, Mark II - Cops](https://codegolf.stackexchange.com/questions/155018/the-programming-language-quiz-mark-ii-): > > > + It has [an English Wikipedia article](https://en.wikipedia.org/wiki/Lists_of_programming_languages), [an esolangs article](http://esolangs.org/wiki/Language_list) or [a Rosetta Code article](http://rosettacode.org/wiki/Category:Programming_Languages) at the time this challenge was posted, or is on [Try It Online!](https://tio.run/#) (or [ATO](https://ato.pxeger.com)). Having an interpreter linked in any of these pages makes that interpreter completely legal. > + It must satisfy our rules on [what constitutes a programming language](http://meta.codegolf.stackexchange.com/a/2073/8478). > + It must have a free interpreter (as in beer). Free here means that anyone can use the program without having to pay to do so. > * Each answer must run in less than a minute on a reasonable PC. Your score is \$\Large{\frac{\text{Bytes}}{\text{Languages}^2}}\$. Obviously the lowest score wins. This means that you can't submit something that runs in no languages (wink). [Answer] # 5 Languages - [Keg](https://github.com/Lyxal/Keg), [Vyxal](https://github.com/Vyxal/Vyxal), [Python 3](https://docs.python.org/3/), [05AB1E](https://github.com/Adriandmen/05AB1E) and [Curlyfrick](https://github.com/Lyxal/CFEsolang), 114 bytes ``` """ !+._\PC\DC-\CC\CC- [|,]#`""" ''' TT__D++,q''' print(ord("P")-ord("D")) ''' ...{} ({}+{}+{}+{})*({}+{}+{}) ''' ``` 100% ascii too [Try Keg online!](https://tio.run/##y05N//9fSUmJS1FbLz4mwDnGxVk3xtkZiHQVomt0YpUTQJLq6uoKISHx8S7a2jqFQA5XQVFmXolGflGKhlKAkqYumOGipKkJUsmlp6dXXcupUV2rDUOaWnAeWInC//8A) [Try Python 3 online!](https://tio.run/##K6gsycjPM/7/X0lJiUtRWy8@JsA5xsVZN8bZGYh0FaJrdGKVE0CS6urqCiEh8fEu2to6hUAOV0FRZl6JRn5RioZSgJKmLpjhoqSpCVLJpaenV13LqVFdqw1DmlpwHliJwv//AA) [Try 05AB1E online!](https://tio.run/##yy9OTMpM/f9fSUmJS1FbLz4mwDnGxVk3xtkZiHQVomt0YpUTQJLq6uoKISHx8S7a2jqFQA5XQVFmXolGflGKhlKAkqYumOGipKkJUsmlp6dXXcupUV2rDUOaWnAeWInC//8A) [Try Curlyfrick online!](https://tio.run/##Sy4tyqlMK8pMzv7/X0lJiUtRWy8@JsA5xsVZN8bZGYh0FaJrdGKVE0CS6urqCiEh8fEu2to6hUAOV0FRZl6JRn5RioZSgJKmLpjhoqSpCVLJpaenV13LqVFdqw1DmlpwHliJwv//AA) [Try Vyxal Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJcIlwiXCJcbiErLl9cXFBDXFxEQy1cXENDXFxDQy0gW3wsXSNgXCJcIlwiXG4nJycgVFRfX0QrKyxxJycnXG5wcmludChvcmQoXCJQXCIpLW9yZChcIkRcIikpXG4nJydcbi4uLnt9XHQoe30re30re30re30pKih7fSt7fSt7fSlcbicnJyAiLCIiLCIiXQ==) Explanation coming soon. Soon here means a time that *isn't* 21 minutes past midnight. [Answer] # 7+ languages, 24 bytes, score < 0.49 ## Haskell, OCaml, Coq, Common Lisp, Erlang, Octave/Matlab, PARI/GP, and many other functional languages `(length("twelvetwelve"))` [Answer] # brainfuck, [Headass](https://esolangs.org/wiki/Headass), Javascript; 3 languages, 52 bytes ``` print("+++++++^[>D+++++P++<-]>:".length/"+?".length) ``` Three cussword titled languages Javascript: [Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/v6AoM69EQ0kbAuKi7VzAjABtbRvdWDsrJb2c1Lz0kgx9JW17GFvz/38A "JavaScript (V8) – Try It Online") brainfuck: [Try it online!](https://tio.run/##SypKzMxLK03O/v@/oCgzr0RDSRsC4qLtXMCMAG1tG91YOyslvZzUvPSSDH0lbXsYW/P/fwA "brainfuck – Try It Online") Headass: [Do stuff online](https://dso.surge.sh/#@WyJoZWFkYXNzIixudWxsLCJwcmludChcIisrKysrKyteWz5EKysrKytQKys8LV0+OlwiLmxlbmd0aC9cIis/XCIubGVuZ3RoKSIsIiIsIiIsIiJd) Javascript: ``` / Divide .length .length The lengths "..." "+?" Of these strings (24/2) print( ) Output the result ``` brainfuck (ignored characters removed) ``` +++++++[>+++++++<-]> 7*7 (canonical) .+. print charcodes 49 and 50 ``` Headass (ignored characters removed) ``` ( [> ++<-]>: nothing important +++++++^ D+++++P print 12 . halt +?.) inaccessible code ``` Not sure what else I can add without drastically changing my approach. Just wanted to get a score up to start with for now. [Answer] # JavaScript (jsshell), Python 3, bash (core utils)?, brainfuck, 109 bytes ``` #!/usr/bin/env -S grep -c ^ e=">+++++++[->+" print(True//True*len(e));"""++++++<]> =e.length)//+.""" ``` I'm not quite sure if this should be count as bash as it actually runs `grep` from its shebang. It does not work on TIO version of jsshell, as support shebang as comment requires a newer version. * [Python 3](https://tio.run/##K6gsycjPM/7/X1lRv7S4SD8pM08/Na9MQTdYIb0otUBBN1khjivVVslOGwKide20lbgKijLzSjRCikpT9fVBpFZOap5GqqamtZKSEkSdTawdl22qHlA8vSRDU19fWw8oxQUD//8DAA "Python 3 – Try It Online") * [brainfuck](https://tio.run/##SypKzMxLK03O/v9fWVG/tLhIPykzTz81r0xBN1ghvSi1QEE3WSGOK9VWyU4bAqJ17bSVuAqKMvNKNEKKSlP19UGkVk5qnkaqpqa1kpISRJ1NrB2XbaoeUDy9JENTX19bDyjFBQP//wMA "brainfuck – Try It Online") [Answer] # Example Submission, \$1\$ Language(s), \$26\$ Byte(s), Score \$\frac{26}{1^2}=26\$. Language(s): * Python ``` print(len('aaaaaaaaaaaa')) ``` # Explanation Need I say more...? ]
[Question] [ For today's challenge you have to take an input, and if your source code is reversed, then the input should be printed doubled. Let's say your source code is `ABC` and its input is `xyz`. If I write `CBA` instead and run it, the output must be any of be `xyzxyz` or `xyz xyz` or ``` xyz xyz ``` For any numerical input you should not multiply it with `2`, instead use the upper rule, for input `1` -> `11` or `1 1` or ``` 1 1 ``` (Trailing newlines allowed in output, but not the leading ones) For simplicity, you can assume that the input is always a single line string containing only ASCII letters (a-z), digits (0-9) and spaces. (You will not get empty input) Standard loopholes apply, shortest code wins original source code's output can be anything [Answer] # Trivial comment trick ## JavaScript (ES6), 12 bytes ``` s=>s//s+s>=s ``` [Try it online!](https://tio.run/##lYyxCsIwFEV3vyJk6Qumr3SW5Cc6itASX0tKSCSvBHXw12M7ObtcOHDOXacyscv@sbUx3am6fYQRY2Vjuev4zNZwHZGDdwS9Fm2vLqd5V6hMAQ59Z5cip0AY0gIzbmnYso8LKC3kx0otZpDP11sq9SuviHjUN8xUKDOBwjX5CE2j/nmsXw "JavaScript (Node.js) – Try It Online") [Answer] # [Japt](https://github.com/ETHproductions/japt), 1 [byte](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) ``` p ``` [Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=cA&input=IjEi) * Returns S repeated n times with n defaulted to 2. [Answer] # [Perl 5](https://www.perl.org/) (`-0777p` `-M5.01`), 3 bytes ``` yas ``` reversed ``` say ``` * `-0777` to undef input record separator (slurp input). * `-p` option print default argument (input) to output. * `-M5.01` to use `say` shorter than `print` * `yas` : bareword (same as "yas" with the quotes), no-op. [Try it online!](https://tio.run/##K0gtyjH9/78ysfj//4rKqn/5BSWZ@XnF/3UNzM3NC/7r@prqGRgCAA "Perl 5 – Try It Online") [Answer] # [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 8 bytes ``` #2*sgra$ ``` [Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X9lIqzi9KFHl////FZVVAA "PowerShell – Try It Online") [!enilno ti yrT](https://tio.run/##K8gvTy0qzkjNyfn/XyWxKL1Yy0j5////FZVVAA "PowerShell – Try It Online") -6 bytes thanks to @NauhelFouilleul [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 3 bytes Anonymous tacit prefix function. ``` ,,, ``` [Try it online!](https://tio.run/##SyzI0U2pTMzJT///X0dH53/ao7YJj3r7HnU1P@pd86h3y6H1xo/aJj7qmxoc5AwkQzw8g/@nKahXVFapAwA "APL (Dyalog Unicode) – Try It Online") The outer commas ravel (flatten) the argument to a simple string (i.e. a no-op). The middle comma is concatenation. The whole function concatenates the string to itself. Since all characters are identical, this works when reversed too. [Answer] # [Keg](https://github.com/JonoCode9374/Keg), `-no`, 2 bytes ``` #: ``` [Don't try it online!](https://tio.run/##y05N//9f2er//4zU5GwA "Keg – Try It Online") Ah yes, bad language design at it's finest. You can't try it online because it desperately needs a pull - and Dennis hasn't been around for a while. The `-no` flag makes everything output as-is - without it, numbers would attempt to output as characters (not very helpful) ## Explained ``` #: ``` Do nothing: standard cat program ``` :# ``` Duplicate the top of the stack and output the entire stack [Answer] # [Vyxal](https://github.com/Lyxal/Vyxal), 2 bytes ``` #d ``` [Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%23d&inputs=Heck&header=&footer=) Very good trivial answer. Make sure to wrap input in double quotation marks. ## Explained ``` #d ``` Nothing, a standard cat program ``` d# ``` Double the input string and output. [Answer] # [Pyth](https://github.com/isaacg1/pyth), 2 bytes ``` zz ``` [Try it online!](https://tio.run/##K6gsyfj/v6rq//@KyioA "Pyth – Try It Online") `z` -> Prints the input. [Answer] # [Python 3](https://docs.python.org/3/), 17 bytes ``` #)2*)(tupni(tnirp ``` [Try it online!](https://tio.run/##K6gsycjPM/7/X1nTSEtTo6S0IC9ToyQvs6jg//@KyioA "Python 3 – Try It Online") [!enilno ti yrT](https://tio.run/##K6gsycjPM/7/v6AoM69EIzOvoLREQ1PLSFP5//@KyioA "Python 3 – Try It Online") [Answer] # [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), 2 bytes ``` x# ``` [Try it online!](https://tio.run/##MzBNTDJM/f@/QhmIK6sA "05AB1E (legacy) – Try It Online") [!enilno ti yrT](https://tio.run/##MzBNTDJM/f9fueL//4rKKgA "05AB1E (legacy) – Try It Online") `x` doubles the input [Answer] # [PHP](https://php.net/) -F, 15 bytes ``` ;ngra$.ngra$=?< ``` [Try it online!](https://tio.run/##K8go@P/fOi@9KFFFD0za2tv8/19RWfUvv6AkMz@v@L@uGwA "PHP – Try It Online") [Try it reversed!](https://tio.run/##K8go@P/fxt5WJbEoPU8PTFr//19RWfUvv6AkMz@v@L@uGwA "PHP – Try It Online") --- # [PHP](https://php.net/), 13 bytes ``` i$.i$>=)i$(nf ``` Outputs error when not reversed. [Try it online!](https://tio.run/##K8go@G9jX5BRwKWSZvs/U0UvU8XOVjNTRSMv7b81V2pyRr6CSpqGUkVllZKm9X8A "PHP – Try It Online") [Try it reversed!](https://tio.run/##K8go@G9jX5BRwKWSZvs/LU9DJVPT1k4lU08l8781V2pyRr6CSpqGUkVllZKm9X8A "PHP – Try It Online") [Answer] # [Charcoal](https://github.com/somebody1234/Charcoal), 3 bytes ``` ²×⁰ ``` [Try it online!](https://tio.run/##S85ILErOT8z5///QpsPTHzVu@P8/pKhSIbNEIT8vJzMvVZELAA "Charcoal – Try It Online") Outputs `--`. ``` ⁰ײ ``` [!enilno ti yrT](https://tio.run/##S85ILErOT8z5//9R44bD0w9t@v8/pKhSIbNEIT8vJzMvVZELAA "Charcoal – Try It Online") Explanation: Outputs zero `-`s, then doubles the implicit input. Charcoal normally takes string input, but you can force it to take numeric input. There are various ways of constructing a 5-byte program that forces string output, although in that case the unreversed output will no longer be `--`. The assumes that both programs need to be syntactically valid, as Charcoal will normally ignore invalid programs rather than exiting with error. Abusing this would allow the programs to be reduced to 2 and 3 bytes respectively. [Answer] # Batch, 16 bytes ``` @ rem&1%1% ohce@ ``` ``` @echo %1%1&rem @ ``` [Answer] # [YaBASIC](http://www.yabasic.de), 8 bytes ``` //$i,$i? ``` [Try it online!](https://tio.run/##q0xMSizOTP6fqWKrVFFZpaSgr68QkpGqkJlXUFryX19fJVNHJdP@/38A "Yabasic – Try It Online") ``` ?i$,i$// ``` [!enilno ti yrT](https://tio.run/##q0xMSizOTP6fqWKrVFFZpaSgr68QkpGqkJlXUFry3z5TRSdTRV///38A "Yabasic – Try It Online") A basic BASIC answer - hide the reversed source behind a comment! Original does nothing, reversed prints input i$ twice. This dialect recognizes // as a comment. I'd shave a byte if it would accept ' like Microsoft BASIC variations do! [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 1 bytes *Ties [AZTECCO's Japt answer](https://codegolf.stackexchange.com/questions/220370/reverse-source-code-and-double-the-input/220381#220381) for #1.* ``` « ``` [Try it online!](https://tio.run/##yy9OTMpM/f//0Or//ysqqwA "05AB1E – Try It Online") [!enilno ti yrT](https://tio.run/##yy9OTMpM/f//0Or//ysqqwA "05AB1E – Try It Online") ``` « # full program # implicit input... « # concatenated with... # implicit input # implicit output ``` ]
[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/23920/edit). Closed 9 years ago. [Improve this question](/posts/23920/edit) All these functional languages that return the same value every time a function is called give me a headache. Your task is to write a function that returns something different every time it is called. Here are the rules: * Your function must continue to return something different every time it is run * It must return a different value on your computer than it does on my computer * Your function must be guaranteed to be different (no random numbers) * +20 if your code gets time from the system or an online clock [Answer] ## T-SQL, 13 ``` PRINT NEWID() ``` Relatively uninspiring challenge, but it's rare that you can show off an instance of true brevity in SQL. [Answer] ## Python, 28 ``` def f(x=[f]):x+=[1];return x ``` Since python has mutable default arguments x will be different every time you call f. The starting element gives you a memory address, which changes each time you define the function. Example output: ``` >>> def f(x=[]): x+=[1]; return x ... >>> f() [<function f at 0x1047527d0>, 1] >>> f() [<function f at 0x1047527d0>, 1, 1] >>> f() [<function f at 0x1047527d0>, 1, 1, 1] ``` [Answer] ## Perl, 67 (but growing slowly) char ``` open X,"+<$0";seek X,66,0;print$y=<DATA>,%ENV;print X++$y __END__ 0 ``` Output the environment of the current machine, plus a hard coded number that is updated in the source code each time you run the script. [Answer] # Perl (7 bytes) ``` sub{$$} ``` Well, until processes IDs run out, this should return something else each time it's being called. Alternatively, if you think this is not fine, because it will return the same value for the same instance of program, there is an alternate version which only works in newer versions of Perl which automatically increases process ID every time it's being called. It's 9 bytes long, however. ``` sub{$$++} ``` [Answer] **DOS - 27 chars** ``` echo "X" >> random.txt dir ``` Not only will your byte size be different, even if you put it in an empty directory your volume serial number won't match mine. [Answer] # Haskell - 95 ``` import Data.Time.Clock.POSIX import System.IO.Unsafe f _=fromEnum$unsafePerformIO getPOSIXTime ``` Example: ``` > f 0 -7269056719496922816 > f 0 -7269056004375922816 > f 0 -7269055316663922816 ``` [Answer] # C [46 bytes] ``` #include<stdio.h> main(int*x){printf("%x",&x);} ``` Theoretically this may return the same address but practically the probability is rather low. [Answer] # Bash, 18, obvious ``` head /dev/urandom ``` [Answer] ## Python, 56 ``` import uuid import time print uuid.getnode(),time.time() ``` [Answer] # C++, 38 chars ``` int *r(){int*s;int n=0;s=&n;return s;} ``` Run `int main(){std::cout<<r();}` with the above, and it is guaranteed to return a different address every time. [Answer] # J, 11 bytes - True function In J, printing the date is merely: `6!:0 ''` but the question asks for a *function* (not absolutely sure other solutions follow this requirement), which gives the idea of the following 11-characters function: `(6!:0@])&''` which outputs each time something different *whatever its argument is* (note that function with no-argument should be accepted, but answers with *statements* for printing the time shouldn't). [Answer] # bash+curl - 24 chars +20 ``` curl -s time.nist.gov:13 ``` [Answer] ## Python 52 A different version of what @Hovercouch suggested: ``` def f(x=[f]):x+=[__import__("time").time()];return x >>> f() [<function f at 0x049F1A30>, 1394652231.0] >>> f() [<function f at 0x049F1A30>, 1394652231.0, 1394652232.746] >>> f() [<function f at 0x049F1A30>, 1394652231.0, 1394652232.746, 1394652423.971] >>> f() [<function f at 0x049F1A30>, 1394652231.0, 1394652232.746, 1394652423.971, 1394652428.137] ``` Although the odds of getting different output on all computers is not zero! ]
[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/122858/edit). Closed 6 years ago. [Improve this question](/posts/122858/edit) I cannot believe that this hasn't been done before but I may be wrong. If so, just close as dupe. This challenge is very similar to [Is it truthy or falsy?](https://codegolf.stackexchange.com/q/89342/66833) but, IMO, isn't close enough to be a dupe. That has predefined "falsy" variables that all languages must use, some of which aren't even falsy; this uses your own falsy values. Your task is to take an input, evaluate it and output whether it is truthy or falsy *in your language*. The "evaluate" part is just so that the input isn't always a string containing the input. For example an input of `0` would be falsy in almost all languages even if `"0"` is truthy. It simply means, "convert it into its native type" # Input Anything. This can be taken from STDIN or as command line arguments. # Output Its truthy or falsy value *in your language*. This should be preferably be denoted by `true/false` or `1/0`. If not, please state what is the output for each. For example, `1`, `"hello"` and `[0,2]` are all truthy in Python but the third isn't in MATL (? Correct me if wrong) # Rules * There must be 2 unique identifiers for truthy and falsy. You can't just say `numbers are true and symbols are false` * Submissions must be **full programs** * This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") but I have a feeling that a challenge this trivial might become a catalogue so if that happens, I will update the body to contain normal catalogue rules. * Of course, builtins are allowed but must be part of a full program. For example, `bool` isn't a valid answer in Python. Good luck! [Answer] # [Japt](https://github.com/ETHproductions/japt), ~~3~~ 2 bytes ``` o ``` Needs the `-d` flag. [Try it online!](https://tio.run/nexus/japt#@5///79ScUlRZl66koJuCgA "Japt – TIO Nexus") [Answer] # [Convex](https://github.com/GamrCorps/Convex), 2 bytes ``` !! ``` [Try it online!](https://tio.run/##S87PK0ut@P9fUfH///8lqcUlmXnpAA "Convex – Try It Online") [Answer] # [RProgN 2](https://github.com/TehFlaminTaco/RProgN-2), 2 bytes ``` ¬¬ ``` [Try it online!](https://tio.run/##Kyooyk/P0zX6///QmkNr/v//bwAA "RProgN 2 – Try It Online") [Answer] # [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 14 bytes ``` ({()(<()>)}<>) ``` [Try it online!](https://tio.run/nexus/brain-flak#@69RraGpYaOhaadZa2On@f@/kYKlgYKhggEA "Brain-Flak – TIO Nexus") ## Explanation ``` ( #Set up a push { #Execute if truthy () #Create 1 value (<()>) #Ensure a 0 to exit the loop } <> #Switch stacks ) #Push the value ``` [Answer] # [RProgN](https://github.com/TehFlaminTaco/Reverse-Programmer-Notation), 1 char, 3 bytes ``` ‼ ``` Added this because I've never really gotten a use for the `truthy` function, and I wanted to. [Try it online!](https://tio.run/##Kyooyk/P@///UcOe////GwAA "RProgN – Try It Online") [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), ~~4~~ 2 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) ``` ṆṆ ``` Full program returning 1 for Truthy and 0 for Falsy. **[Try it online!](https://tio.run/nexus/jelly#@294aN2hzfb///@PjgUA "Jelly – TIO Nexus")** ### How? ``` ṆṆ - Main link: x Ṇ - non-vectorising logical not Ṇ - non-vectorising logical not ``` [Answer] # Python 2, ~~28~~ 27 bytes ``` print(input()and 1>0or 0>1) ``` Less trivial than just `print(bool(input()))`. String input must be given in quotes as per Python 2 requirements. -1 byte thanks to ovs [Answer] # JavaScript (ES6), 6 bytes ``` i=>!!i ``` ]
[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) ["Hello, World!"](/questions/55422/hello-world) (974 answers) Closed 6 years ago. *[Related](https://codegolf.stackexchange.com/q/55422/58375)* Goats are great. Everybody loves goats. And they also, for some reason, are an excellent complex ascii art for many languages to have built-ins for. Because of this, I personally feel a catalogue to document just how easily a language can print goats is greatly needed. ## The Challenge Given an integer input via any means print that many Goats separated by Newlines. Your Goat for reference is: ``` ___. // \\ (( '' \\__, /6 (%)\, (__/:";,;\--____----_ ;; :';,:';`;,';,;';`,`_ ;:,;;';';,;':,';';,-Y\ ;,;,;';';,;':;';'; Z/ / ;,';';,;';,;';;' / / |';/~~~~~\';;' ( K | | || | \_\ | | || | \Z | | || | L_| LL_| LW/ LLW/ ``` Your particular goat may have more whitespace around it, if required. ## Example Given `3` on input, Output: ``` ___. // \\ (( '' \\__, /6 (%)\, (__/:";,;\--____----_ ;; :';,:';`;,';,;';`,`_ ;:,;;';';,;':,';';,-Y\ ;,;,;';';,;':;';'; Z/ / ;,';';,;';,;';;' / / |';/~~~~~\';;' ( K | | || | \_\ | | || | \Z | | || | L_| LL_| LW/ LLW/ ___. // \\ (( '' \\__, /6 (%)\, (__/:";,;\--____----_ ;; :';,:';`;,';,;';`,`_ ;:,;;';';,;':,';';,-Y\ ;,;,;';';,;':;';'; Z/ / ;,';';,;';,;';;' / / |';/~~~~~\';;' ( K | | || | \_\ | | || | \Z | | || | L_| LL_| LW/ LLW/ ___. // \\ (( '' \\__, /6 (%)\, (__/:";,;\--____----_ ;; :';,:';`;,';,;';`,`_ ;:,;;';';,;':,';';,-Y\ ;,;,;';';,;':;';'; Z/ / ;,';';,;';,;';;' / / |';/~~~~~\';;' ( K | | || | \_\ | | || | \Z | | || | L_| LL_| LW/ LLW/ ``` ## The Rules * You must take an integer input where `0 < input < 256`, and print that many goats. * Goats may vary in whitespace, as long as the shape of the goat is the same. * You must submit a full program. * This is a catalogue, so any language or language version newer than the challenge is acceptable. Like usual, creating a language that prints `N` goats in `0` bytes isn't incredibly creative. Also, as this is a catalogue, no answer will be accepted. * This is however [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer per language. * If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language. ## The Catalogue *Shamelessly stolen from The Hello World Challenge* The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard. 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 snippet: ``` ## [><>](http://esolangs.org/wiki/Fish), 121 bytes ``` ``` /* Configuration */ var QUESTION_ID = 107765; // Obtain this from the url // It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 58375; // This should be the user ID of the challenge author. /* App */ var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "http://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "http://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1; if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } } ``` ``` body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } 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="language-list"> <h2>Shortest Solution 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> <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> <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] ## Ruby (2.3), 312 bytes Hey, at least I didn't use a built-in! ``` n=gets.to_i puts " ___. // \\\\ (( '' \\\\__, /6 (%)\, (__/:\";,;\--____----_ ;; :';,:';`;,';,;';`,`_ ;:,;;';';,;':,';';,-Y\\ ;,;,;';';,;':;';'; Z/ / ;,';';,;';,;';;' / / |';/~~~~~\\';;' ( K | | || | \\_\\ | | || | \\Z | | || | L_| LL_| LW/ LLW/\n"*n ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), ~~194~~ 191 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page) -3 replacing `b24ị` with `ṃ` (a since-developed atom) ``` “wɦLż8ßȧṛ Ỵ?þġЮạSḍọsñL1⁶ƁṄṫȥẊ`m®Ø⁼ƒ⁺Ė6⁺oHpæİṇµ\ṅṁ⁷V⁶k¡i£}ḣọSƑṭ<ḃṚSØ:kŒxṘıquṂUnƭ⁾DEØẓ×ðH¦ḅċ5pðḳṅ⁶Ḅḍ€®85ɲPp¦Ø0B¥=ẊCƲ<7eØ7ƥ÷8¡ÆḅẎṣṂ(hþẓ]ƲƤȦE¶ƙCɼƭżÆµėṙṾḞ\&O ¬ṆñKmɠ’ṃ“ .¶/\(',6%):";-`YZ|~KLW_”Ṅ¡’ ``` **[Try it online!](https://tio.run/##DZBbSwJRFIX/igSVQVeiFCuCTBAUCqSiMOpFqNQyIiqocLQMCqML1Nh9MKeHUtRS54yDD2ePB@dn7PNHpvOyHjZrfXuxtiKx2JFt8@TLgaUG24Yb3jtfSJ4d2PybhpapwA0toa6EUMtiM7sHleAIl@pMQnKG5LtTQP1yPU5LIHPJYHdc0s2HcaE7/gSoZhnJBa2FkZwjkbjUWBTRKFU2af4EtbzghdgtkuIkamkkTyGQPdH23SES2azs7iNJLWyzIpdasz6QUb@HRyj7qYrauXk1loAyar@CLJConYl6PPVDS@4xqzqfoCrIwzO0MCXaeVl10hUB2cUK0HBTBTICgPo1krz44NyAlkCvsir77Kg@Wmc5r2WwYtuADK2Zj0hySFqovYV75hz0B0kGKoG49cGT4p4WszkGaX0o7OztH@/u83RNDKwvrxyfBoJLazz5KjaiinDatj36Dw "Jelly - Try It Online")** ### How? The 24 distinct characters from which the goat is constructed are: `.¶/\(',6%):";-`YZ|~KLW_` where `¶` represents a line feed, and the first character is a space. A goat may now be thought of as a 277 digit base 24 number, G, where each digit represents the 1-based and mod-24 index of a character in the above list. The code forms G using base 250, transforms G to a base 24 representation as a list of digits and indexes into the character set. It then repeats an instruction to print the resulting character array and a line feed `n-1` times. ``` a long string of bytes | “...’ṃ“ .¶/\(',6%):";-`YZ|~KLW_”Ṅ¡’ - Main link: n “...’ - make G using base 250 “ .¶/\(',6%):";-`YZ|~KLW_” - the characters of a goat, ¶ being a line feed ṃ - base decompression (use the 24 characters as the base 24 digits) ’ - decrement n to give n-1 ¡ - repeat the previous link n-1 times Ṅ - print the result and a line feed ``` The only slight complication is that Jelly's base 250 representation is 1-based and the indexing is modular, so when a zero digit is present it will be a 250 digit - the remedy is to reduce the next most significant digit by 1, and repeat if that becomes a zero. (This occasionally will make for shorter code, but not this time.) [Answer] ## JavaScript (ES6), 306 bytes Some slightly compressed goats... ``` [..."abcdefghijklmnopqrs"].map((c,i)=>s=s.split(c).join(` jnk me|h--~~|omLqq r__pr,; |rr'; \\`.substr(i*2,2)),s=`rl_.a//rss ((r ''assl, /6 (%)s, (l/:";nsfllff_ ;; :q,:q\`;,qnq\`,\`_k;:n;b':,j,-Ysc;nnb':;j Z/c/ ;,bqnq;'k/ /oq/gg~sq;'a( Krhdks_soodcsZood i_|iL_| iW/iLW/ `)&&console.log(s.repeat(prompt())) ``` [Answer] # [RProgN](https://github.com/TehFlaminTaco/Reverse-Programmer-Notation), 16 bytes ``` "goat " read m C ``` I assume this is the answer you've been waiting for... [Try it online!](https://tio.run/nexus/rprogn#@6@Unp9YoqCkUJSamKKQq@D8/78xAA "RProgN – TIO Nexus") [Answer] # [SOGL](https://github.com/dzaima/SOGL), 174 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md) ``` ▼īj-ηī¤ķJφB╝║α$a3╬ο'Βw)woE;@ē¹█lα.⁶↓!mΙ;┌.}γ§⁹≡r³╝╚wΓδΘργ±:⁾▓√׀⅝╝█%čczgΧMθL`«UΓ║νZ█č└sΩ±⅛mΤCρ2o¦≠]ΖøΙΧ²`žB+9‰κ╚¦¤Ƨ¹≥ΗxƧWJ∞┐∑¹±YEōΟ№Χθ≥⁹~E∞θ<a∙λy⌠s⁹░WP≡Φ╝∆~λ?(l$′Ζŗ=Κ╗2Ψ⁄>τ-‘* ``` vary simple (from the outside) ``` ...‘ push that string decompressed * multiply by input ``` I had to chop the goat up into pieces of strings that each when compressed is as small as possible, which then get each compressed and joined together. [more info](http://pastebin.com/UiBSTdkN) [Answer] ## Lua, 306 bytes `:rep()`'s `io.read()` times. ``` print(([[ ___. // \\ (( '' \\__, /6 (%)\, (__/:";,;\--____----_ ;; :';,:';`;,';,;';`,`_ ;:,;;';';,;':,';';,-Y\ ;,;,;';';,;':;';'; Z/ / ;,';';,;';,;';;' / / |';/~~~~~\';;' ( K | | || | \_\ | | || | \Z | | || | L_| LL_| LW/ LLW/ ]]):rep(io.read())) ``` ]
[Question] [ *Note: [This challenge](/questions/75687) is not the same.* # Challenge Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays (although we've got one for n-dimensional ones)! This should operate only on the 1st dimension, not on all dimensions of an array. # Rules * Standard loopholes are **denied** * **`[[1, 2], [3, 4]]`** becomes **`[[3, 4], [1, 2]]`**, not **`[[4, 3], [2, 1]]`**. * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), but no answer is accepted. Go beat the others! * You can get the array any way, except hardcoding. You can also get a string and process it. * The input will be an array (yes, commas or no commas, it needs to be an array). # Test cases These are the test cases: ``` [1, 2, 3, 4] [1, 2, 'hello', 'world!'] [[1, 2, 3, 4], [2, 3, 4, 1]] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] ``` These are the supposed results: ``` [4, 3, 2, 1] ['world!', 'hello', 2, 1] [[2, 3, 4, 1], [1, 2, 3, 4]] [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] ``` You may accept input as `[1 2 3 4]`, or even `1 2 3 4`, or any other form or array your language has. [Answer] # Jelly, 1 byte ``` Ṛ ``` [Try it online!](http://jelly.tryitonline.net/#code=4bma&input=&args=WzEsIDIsIFszLDRdXQ) It reverses an array. (yay this is my first Jelly answer!) [Answer] # Pyth, ~~2~~ 1 byte~~s~~ *1 byte off thanks to Doorknob* ``` _ ``` `_` is reverse, and Pyth takes implicit input. Yes, my first Pyth answer is an underscore. [Answer] # Python 2, 8 bytes ``` reversed ``` This is too short. [Answer] # [𝔼𝕊𝕄𝕚𝕟](https://github.com/molarmanful/ESMin), 3 bytes ``` ᴚ ``` Literally reverses array. Implicitly performs I/O. [Answer] # Python 3, 16 bytes ``` lambda x:x[::-1] ``` This isn't even enough characters to post as an answer. [Answer] # C, 65 bytes Takes a pointer to the start of the list and a list length. ``` void f(int*a,int s){int t=*a;*a=a[--s];a[s--]=t;if(s>1)f(a+1,s);} ``` This is a recursive algorithm that swaps the first element with the last, and then runs the same function on the middle. Ungolfed: ``` void f(int* a, int s){ int t = a[0]; a[0] = a[--s]; a[s--] = t; if(s > 1){ f(a + 1, s - 2); } } ``` [Answer] # Python 2, 19 bytes ``` print input()[::-1] ``` [Answer] # [05AB1E](http://github.com/Adriandmen/05AB1E), 1 byte Code: ``` R ``` [Try it online!](http://05ab1e.tryitonline.net/#code=Ug&input=W1sxLCAyLCAzLCA0XSwgWzIsIDMsIDQsIDFdXQ). [Answer] # [Brachylog](https://github.com/JCumin/Brachylog), 2 bytes ``` r. ``` which expects a list as Input and unifies the reverse with the Output. ### Alternative ``` rw ``` which expects a list as Input and writes the reverse to `STDOUT`. [Answer] # Java 8, ~~62~~ ~~38~~ 30 bytes ``` java.util.Collections::reverse ``` Modifies the input-`ArrayList` instead of returning a new one to save bytes. -8 bytes thanks to *@OliverGrégoire*. [Try it here.](https://tio.run/##tZBNa8MwDIbv/RVaTgl4Zk732X3A2HXrDj2OHdzE25w5drCVlDLy2zO5DXSXQhkULGxZj/S@diU7eeoaZavyeyiMDAFepLY/EwBtUfkPWSiYxxSgc7qEIq2ohbeoDX/WAe9el5Uq8AFMdktUT0FrDhbuYdihT84YwrSzYTbzqlM@qCE2NO3S6AICSqRtI1GTgXSBXtvPt3eQ2VY92oKaplq12iTpRhBgjx9UAYneVR@9l@vAZYhYKhjkDKYMzscxNbe8SGPXeLFYB1Q1dy3yhrygsX@rB41PvpQxLqHDynlTniRH0TrgiWxv80gwENkRP2IrccHgksEVg2sGN6R4RkF1QYAgQkQXxAiCBFGCMEFcTlwe5xCXT//jsp/0wy8) --- With an array as input instead of `ArrayList` (**62 bytes)**: ``` import java.util.*;a->{Collections.reverse(Arrays.asList(a));} ``` Modifies the input-array instead of returning a new one to save bytes. [Try it here.](https://tio.run/##vZBLT8MwEITv@RVLTwlyU5zyVAQS4goFqdwQBzdxqYNrR/amVVXlt4fNQ604cEOVbMk7@TwzcSE2YmxLaYr8u1Hr0jqEgrS4QqXj8xQAJhN4EyTbJeBKwmKHcpzZymAQZFp4Dy9CmX0AoAxKtxSZhFk7AmysyiELXxeFzPDjE0SUkl7TpuVRoMpgBgbuoRHjh/2T1ZpAZY2PndxI52X46JzY@Vj4Z@UxFFGU1k3aG5TVQpPB4NNlralJOEenzFcX19c45KP0SGFGbg/anjNIGEwZXNZpR5s4C1sw6sf5zqNcx7bCuCRf1CY8vs/QLpeyfLd9bn93uPx34GgltbYjOmyt0/nZ6ETp7UA@v3@cwVEeNAa8PumD9KFXDK4Z3DC4ZXBHHS5o03dOACeCt72I4QRxojhhnLiEuKT1IS6Z/nvvOqibHw) --- Looping over the array to reverse it would be **~~75~~ 69 bytes** instead: ``` a->{Object t;for(int i=0,j=a.length;i<--j;a[i++]=a[j],a[j]=t)t=a[i];} ``` [Try it here.](https://tio.run/##vZBNbsIwEIX3nGLKKgjHwqG/clOpByhd0B3Kwk0M2DVOlAwghHL2dIIRVRfdVUi25Rl/fu/ZVu1UXFba2@Kry51qGnhTxh8HAMajrpcq1zDrS4BdaQrIo/dPq3NcZKBGkvotTRoNKjQ5zMBDCp2KX46BA5TLso5IDEw6YTZV3Gm/wrU0z3FspVqY8ThL1cJmrF9SHCFVJpNtJ4N0tf10JH12OKXYUMZojrXxq1OQEPCSDHWDFMPr/aV3FAwSBlMGt6080Z7nUQ@OQjk/NKg3vNwir0gXnY8sfQ7fonH8ta7VoeGF1tVHGXzD3fPlvw2Ha@1cOaTNvqxdcTO8kntfkM7vhzP4aZ97DER71Q8JpncM7hk8MHhk8EQZJjTpXBAgiBB9LmIEQYIoQZggLiEu6XWIS6b/nrsdtN03) -5 bytes thanks to *@OliverGrégoire*. [Answer] # Ruby, 14 bytes you can't get simpler than this: ``` ->a{a.reverse} ``` [Answer] # JavaScript ES6, 14 bytes ``` x=>x.reverse() ``` Simple enough. Anonymous lambda that reverses an array. [Answer] ## Actually, 1 byte ``` R ``` `R`everses the input list. These are words to make this answer long enough. [Answer] # SmileBASIC, 34 bytes ``` DEF R A DIM T[LEN(A)]RSORT T,A END ``` `RSORT` actually just sorts the arrays, and then reverses them. ### Cheating answer: (requires turning the screen upside down): ``` LINPUT S$ATTR 2?S$ ``` [Answer] # Python 3, 12 bytes ``` list.reverse ``` Surprised nobody else used this. Reverses in place, but I don't think there are any restrictions on that. [Answer] # Jolf, 1 + 1 = 2 bytes ``` _ ``` [Try it here!](http://ethproductions.github.io/Jolf/#code=Xw&input=WzEsMiwzLCJoZWxsbywgd29ybGQhIiwid29ybGQiLFszLDQsNV1d) (bonus for polyglot with Pyth?) `_` reverses (negates) an array. (Make sure pretty output is on.) [Answer] ## Pyke, 1 byte ``` _ ``` [Try it here!](http://pyke.catbus.co.uk/?code=_&input=%5B1%2C+2%2C+%27hello%27%2C+%27world%21%27%5D) Pyke has implicit input and output. Polyglot with Pyth, Jolf, [Answer] # Perl 5, 11 bytes A subroutine: ``` {reverse@_} ``` [Answer] # [Keg](https://github.com/JonoCode9374/Keg), 1 byte Nothing interesting. Keg has a built-in. (Since Keg does not have any other means of representing an array, let's assume the stack is the array (and in fact it is).) ``` ? ``` [Try it online!](https://tio.run/##y05N///f/v//xOKUNAA "Keg – Try It Online") [Answer] ## Lua, 61 bytes It beats C! \o/ It simply fill a new table in the reversed order. ``` function f(g)h={}for i=0,#g do h[#g-i]=g[i+1]end return h end ``` It could have been done by working on the pointer, suppressing the return statement and the new table definition, but it actually is longer by 2 bytes ``` function f(g)for i=1,#g/2 do x=#g-i+1g[x],g[i]=g[i],g[x]end end ``` [Answer] # [MySQL](//meta.codegolf.stackexchange.com/a/5341), 64 bytes ``` set@=1;select a from(select a,@:=@+1 n from t order by n desc)u; ``` Tested on 5.6.24. My first SQL answer; please provide feedback! [Answer] # PHP, 17 bytes ``` $r=array_reverse; ``` call `$r($array)` non-built-in version, 53 bytes: ``` function r($a){while($a)$b[]=array_pop($a);return$b;} ``` call `r($array)` generator for PHP >= 5.5, 45 bytes ``` function y($a){while($a)yield array_pop($a);} ``` usage: `foreach(y($array)as$v)var_dump($v);` [Answer] # Python, 16 bytes ``` lambda l:l[::-1] ``` *Please examine this answer again. I was a bit lazy answering this :P* Thanks to 55749 (J843136028) for suggesting to convert this to a function :) [Answer] # TI-Basic, 16 bytes ``` seq(Ans(I),I,dim(Ans),1,~1 ``` No built-ins for reversing an array in TI-Basic... [Answer] # [Triangularity](https://github.com/Mr-Xcoder/Triangularity), 7 bytes ``` .). IER ``` [Try it online!](https://tio.run/##KynKTMxLL81JLMosqfz/X09Tj8vTNej//2hDHQUjHQX1jNScnHx1IKM8vygnRVE9FgA "Triangularity – Try It Online") [Answer] # [Dodos](https://github.com/DennisMitchell/dodos), 43 bytes ``` main dab dab - a - - dip a dot dab dot ``` [Try it online!](https://tio.run/##S8lPyS/@/58zNzEzTyElMYmLE0go6CokculyceoqpGQWcCUCxfJLoJL5Jf///zf8b/TfGAA "Dodos – Try It Online") (the `-` function subtracts and `a` is `lambda x: [sum(x[1:]), sum(x)]`. So `dab - a` takes the first element of a list) [Answer] # [Preproc](https://gitlab.com/pavelb/Preproc), 279 bytes ``` #define v(x)Z(Z(Z(Z(Z(x))))) #define Z(x)Y(Y(Y(Y(Y(x))))) #define Y(x)X(X(X(X(X(x))))) #define X(x)e(e(e(e(e(x))))) #define e(x,...)x #define d() #define s(x,y,...)y #define r(x,y...)i(x,,R d d d d()()()()()(y)x) #define C, #define R()r #define i(x,v...)s d()(C##x v) v(r e()(I)) ``` [Try it online!](https://tio.run/##XY49C8MgEEB3f4WQ5Q4OoV9L1zQFlw6Z2q7VQpY2GBD99dZL0YC@Rd/jDmdnZ/d9pdQZ@54@VnoI@IRCQD6iRBYPKDSRxR0KTWRhodDELEgphaEaA1tdco1rj9U5dqymfKFRmj@AlYhhW9FTvY6Arj542vOaZZ3tuy5Ij8KDy39C0Igppctw1bfhrMWO9nSgI51@ "Preproc – Try It Online") --- Some notes. * Because the language (one pass of the C preprocessor) is not Turing-complete (as far as I know), this can only process arrays up to a fixed size. That can be increased by making `v(x)` evaluate `e(x)` more times. * Input on command line, separated with `,` (please only give non-negative integers) * Output on stdout, separated with spaces. * My first Preproc answer. Golfing suggestions are appreciated. * I would appreciate it if someone explain why do I need 4 nested `d`. [Answer] # [MathGolf](https://github.com/maxbergmark/mathgolf), 1 byte Nothing interesting. MathGolf has a built-in. ``` x ``` [Try it online!](https://tio.run/##y00syUjPz0n7/7/i//9odUMjdR11I0P1WAA "MathGolf – Try It Online") [Answer] # [APL (Dyalog Unicode)](https://www.dyalog.com/), 1 byte ``` ⊖ ``` This works both on lists of lists and proper multi-dimensional arrays. [Try it online!](https://tio.run/##hZC7TsMwFIb3PsVPli6uhBPuKwzAQCXCVnVwidtGOLHlJlSdkTJUcgVCsMETILHwBDyKXyQcQwcGLsPx@aXz@T8XYVQvWwilJ23rl4/t2De33q388sa7F@/e3l8T39z51UN6fkjvxfFJ2lI@TftnGGOtugPOEDMkDFvDbufXejSVSumIxFxblW1EP8Pf3RgGa8nAh3@ZfzHbDDsMuwx7DPv0ZZOC6pwATgQPNsRwgjhRnDBOXExcHHyIi5PQxj1BXssSNOnVDPMpSWO1kRZFraq8l@WFLGe5LoWCsFYsDjo0knsO9/s82P@7IDS51IURVqJfV6auIMoMR3JUT@Cb@w8 "APL (Dyalog Unicode) – Try It Online") [Answer] # [Molecule](https://github.com/lvivtotoro/molecule), 8 bytes ``` I"Ar"+`n ``` Explanation: ``` I"Ar"+`n I"Ar" Read input, append the command (reverse array) as a string. + concatenate the 2 strings `n set the program's source code to that new string. ``` Simple I/O: ``` Input | Output [5 "n"] [n 5.0] ['n 3] [3.0 n] ``` ]
[Question] [ ## Challenge * Input two integers. + Integer I/O must be decimal. * If the integers are equal, output a truthy value. * Otherwise, output a falsy value. ### Clarifications * You will never receive non-integer inputs. * You will never receive an input that is outside the bounds [-2³¹, 2³¹). ## Rules * Standard loopholes are disallowed. * This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer wins, but will not be selected. [Answer] # [Brachylog](https://github.com/JCumin/Brachylog), 0 bytes [Try it online!](https://tio.run/##SypKTM6ozMlPN/oPBIYGBiAMAA "Brachylog – Try It Online") One number from STDIN and one from command-line arguments. [Answer] # [brainfuck](https://github.com/TryItOnline/tio-transpilers), ~~45~~ ~~49~~ ~~41~~ ~~37~~ 34 bytes ``` ,[>,]>+<<[<]>[<,[->-<]>[>]>],[>]>. ``` [Try it online!](https://tio.run/##SypKzMxLK03O/v9fJ9pOJ9ZO28Ym2ibWLtpGJ1rXThfEsou1i9UBkXr//xuZmDIAMQA "brainfuck – TIO Nexus") Takes the two integers separated by a single null byte. Null bytes are falsy in BF and everything else is truthy, so this prints a single 0x01 byte for truthy and a single 0x00 for falsy. This is my first time golfing in BF, so feel free to give me suggestions... ### Explanation ``` ,[>,] Read in everything from STDIN until the null byte is reached >+ Move one space to the right and increment; this will be a flag telling us the numbers are still equal <<[<]> Move back to the beginning of the input [ For each character in the input: <, Move to the left and input a character [->-<] Subtract this char from the char at the same spot in the original number >[>] If this is not zero (there is a difference between the two characters) move to the hole before the flag > Move one character to the right If we're in the hole before the flag this moves us onto the flag; the loop runs once more and deposits us two spots to the right ] Endwhile When the while loop finishes we will be one spot to the left of the flag or already to the right if the program found a difference between the numbers However: we will still be just to the left of the flag for cases like 24 vs 245 , So we input another byte (the next digit of the second number or 0x00) [>] and move past the flag if it's non-zero >. Move right (onto the flag or past the flag) and output ``` [Answer] # [///](https://esolangs.org/wiki////), 9 bytes ``` //f///t/f ``` [Try it online!](https://tio.run/##K85JLM5ILf7/X18/TV9fv0Q/7f9/AA "/// – Try It Online") Prints a t if they are equal, otherwise prints f. Since there is no way to take input in ///, it is hard-coded. ``` /NUM1/f//NUM2/t/f ``` **Explanation:** With example inputs of 12 and 121213. (Should return false.) 1. Input. `/12/f//121213/t/f` 2. Replace other occurrences of the first number with f. `/ff13/t/f` 3. Replace the modified new number with a t. Since the modified string is not f, , f stays the same. `f`. 4. Output. `f`. With example inputs of 501 and 501. (Should return true.) 1. Input. `/501/f//501/t/f` 2. Replace other occurrences of the first number with f. `/f/t/f` 3. Replace the modified new number with a t. Since the modified string is f,f changes to `t`. 4. Output. `t`. Credit to @user202729 for coming up with the better approach! [Answer] # [yup](https://github.com/ConorOBrien-Foxx/yup), 16 bytes I struggled to find an esolang where this was non-trivial (and that was not already covered). I present to you, this: ``` **-{0~-}0~-|0~-# ``` [Try it online!](https://tio.run/nexus/yup#@6@lpVttUKdbC8Q1QKz8//9/3bz/pmACAA "yup – TIO Nexus") This works as follows: ``` **-{0~-}0~-|0~-# ** take two inputs on the stack - subtract them {0~-}0~- this is "absolute value": { } while TOS is > 0 0~- this is negate: 0 push 0 [TOS, 0] ~ swap [0, TOS] - subtract [-TOS] thus, this negates positive numbers 0~- negate again to get a positive number this maps equal numbers to `0` and unequal numbers to their absolute differences | take ln(TOS). This gives `-Infinity` for equal numbers, and some value >= 0 for other numbers. 0~- negate. this gives Infinity for equal numbers, and a number <= 0 for unequal numbers # output as number ``` Now, `{...}` is yup's loop and is the closest thing to a condition. It repeats the inside so long as the TOS is positive and defined. Thus, any negative or 0 value is falsey, and any positive value is truthy. Infinity is truthy, being greater than 0. [Answer] # [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 26 bytes Straight from the [wiki](https://github.com/DJMcMayhem/Brain-Flak/wiki/Comparisons). [Please don't upvote trivial answers.](https://codegolf.meta.stackexchange.com/a/10132/57100) ``` ([{}]{})((){[()](<{}>)}{}) ``` [Try it online!](https://tio.run/nexus/brain-flak#@68RXV0bW12rqaGhWR2toRmrYVNda6dZCxT5/9@UyxQA "Brain-Flak – TIO Nexus") [Answer] # [Verbosity](https://github.com/cairdcoinheringaahing/Verbosity), ~~507~~ 503 bytes ``` Include<MetaFunctions> Include<Output> Include<Input> Include<Integer> Include<Boolean> Input:DefineVariable<i; 0> Output:DefineVariable<o; 0> Boolean:DefineVariable<c; 0> Integer:DefineVariable<a; Input:ReadEvaluatedLineFromInput<i>> Integer:DefineVariable<b; Input:ReadEvaluatedLineFromInput<i>> Boolean:DefineVariable<r; Boolean:ArgumentsAreEqual<c; a; b>> Boolean:DefineVariable<q; Boolean:LogicalNot<c; r>> Output:DisplayAsText<o; q> DefineMain<> [ MetaFunctions:ExecuteScript<MetaFunctions@FILE> ] ``` [Try it online!](https://tio.run/##jZHdaoNAEIXv9yl8BHMbZamlCoJpoQm9Kb0Y16kMbHZ1nQ3J01t/EiSC0Ms535yZw8wFXWk74lvf50ZpX2F8QIbMG8VkTSfFQ/7w3Hhe6tysSsYa3SK8WqsRzCgMjfs3/CWDX@AISo0xRUEoxTxzzezE7v41VBO8b1tDiIJ52ydClV5Ae2CsiqElc/Y8oZjkpr38p30jmouCB0lc7c9ouEscpq0HPeYe0pXb7nZxF7YmBfrd8mhzcjkUdY2GW9Kd8MrjnVop5jEHIBPL4Fs8fW@fXlF5xqNy1PDzZ1@yvEil@On7XSh24R8 "Verbosity – Try It Online") Saved 4 bytes thanks to Mr. Xcoder Haha, no-one shall lose to Verbosity! Outputs with a `Boolean<>` wrapper around the result. The `Boolean:LogicalNot` is required due to an ongoing bug with booleans. The ungolfed version: ``` Include<MetaFunctions> Include<Output> Include<Input> Include<Integer> Include<Boolean> Input:DefineVariable<STDIN; 0> Output:DefineVariable<STDOUT; 0> Boolean:DefineVariable<constant; 0> Integer:DefineVariable<FirstInput; Input:ReadEvaluatedLineFromInput<STDIN>> Integer:DefineVariable<SecondInput; Input:ReadEvaluatedLineFromInput<STDIN>> Boolean:DefineVariable<result; Boolean:ArgumentsAreEqual<constant; FirstInput; SecondInput>> Boolean:RedefineVariable<result; Boolean:LogicalNot<constant; result>> Output:DisplayAsText<STDOUT; result> DefineMain<> [ MetaFunctions:ExecuteScript<MetaFunctions@FILE> ] ``` [Try it online!](https://tio.run/##lZJNasMwEEb3OoWP4GwTI@oSGwxOArHbTelCkadGoEiuNArJ6V3VP4ljmkK0G83j6Rs0JzAHbQVe2jZTXLoKog0gS53iKLSylIzXO4eNw1udqVmJUIO5XbxqLYEpSkhHLtfwJRS8MyPYQUJUlOtsuwpCSnrxH/3dW9kBg2lOcB8PmcKOIcP7cygVxmIXYBX0OfbAquTEpGMIVe7Z1Ohj1@ozUfrIVYB/snpW9iC9Aeuk94zt2NTuCAptbCD5dkxO5psOMQnh5Vf7Hqr//bmuBWdyq3Ei7qFfz/gJwjaSXWJbwhmvfzBghPQzbJhQEQ0@SODP3bYskzNwh1BwIxq836SXNMsTSj7bdhGSRfgD "Verbosity – Try It Online") [Answer] # [Retina](https://github.com/m-ender/retina), 9 bytes ``` ^(.+)¶\1$ ``` Counts the number of times the first line matches the second. [Try it online!](https://tio.run/nexus/retina#@x@noaeteWhbjKHK//@mXKYA "Retina – TIO Nexus") [Answer] ## [Retina](https://github.com/m-ender/retina), 5 bytes Byte count assumes ISO 8859-1 encoding. ``` D` ¶$ ``` [Try it online!](https://tio.run/##K0otycxL/P/fJYHr0DaV//8NjbkMjQE "Retina – Try It Online") ### Explanation ``` D` ``` Deduplicate with the implicit regex `.+`, i.e. if the two lines are identical, clear the second one (the separating linefeed remains though). ``` ¶$ ``` Try to match a linefeed followed by the end of the string. This is only possible if the first stage cleared the second line, i.e. if the two numbers were equal. [Answer] # [Python 3](https://docs.python.org/3/), 10 bytes ``` int.__eq__ ``` [Try it online!](https://tio.run/##FYpBCoQwEATPziv6mAGRiHhQ8BceF4JCggGJMYnIvj47C00XTXX8luMKQ3XLp/pQOmPsbUx9D39arOmxMzVbu2OBEq0yw10JGT5I4lMUdzmeXsjUxPT/OLW12JnrhIlGDKShqdfopWXqHw "Python 3 – Try It Online") [Answer] # [Japt](https://github.com/ETHproductions/japt), 2 bytes ``` ¥V ``` [Try it online](http://ethproductions.github.io/japt/?v=1.4.4&code=pVY=&input=OCw4) [Answer] # [Cascade](https://github.com/GuyJoKing/Cascade), ~~5~~ 4 bytes ``` #& = ``` Turns out I didn't need the second `&` due to wrapping [Try it online!](https://tio.run/##S04sTk5MSf3/X1mNy/b/f3MFMwA "Cascade – Try It Online") [Answer] # [Flurry](https://github.com/Reconcyl/flurry) `-nin`, 134 bytes ``` <<>[(<<>()>)<<>[({}){}]>][<><<>[<>{{}}]()>]()()[<><<>()>]>({})[<><<>(){}>[()[<><<>()>]]]{{}{<{}{()[<>{}[<><<>()>]]}>}{{}(<>()){}}()}{} ``` ### Run example ``` $ pgm="..." # the program above $ ./flurry -nin -c $pgm 0 0 1 $ ./flurry -nin -c $pgm 123 45 0 $ ./flurry -nin -c $pgm 123 123 1 ``` There is no task that is trivial in every language. Seriously. Since Flurry's only representation of a number is Church numeral, this program takes only non-negative integers as input. Outputs 1 if two Church numerals represent the same number, 0 otherwise. Implements the following function: ``` // (n+1-m) * (m+1-n), where a-b gives zero if a < b // This gives 1 when m==n (both sides of * are 1) // and 0 otherwise (one side is 0) main = (\npm. <SK> (m p (succ n)) (n p (succ m))) n pred m // succ n = n + 1 succ = S<SK> // pred n = n - 1 (pred 0 = 0); implemented using pair construct next-pair-helper = \fmn. f n (succ n) = \fm. S f succ = \f. K(S f succ) = {()[<>{}[<><<>()>]]} next-pair = \p. <p next-pair-helper> = {<{}{()[<>{}[<><<>()>]]}>} pred = \n. n next-pair zero-pair K = {{}{<{}{()[<>{}[<><<>()>]]}>}{{}(<>()){}}()} ``` [Answer] # [Jelly](https://github.com/DennisMitchell/jelly), 1 byte ``` = ``` [Try it online!](https://tio.run/nexus/jelly#@2/7//9/0/@mAA "Jelly – TIO Nexus") **Explanation:** ``` = Takes two arguments and returns a 1 if they are equal, and a 0 if they are not. Implicit print. ``` [Answer] # OCaml, 3 bytes ``` (=) ``` Brackets are necessary, plain `=` is a syntax error [Answer] # [sed](https://www.gnu.org/software/sed/), 14 bytes Includes +1 for `-r` ``` s/^(.+),\1$// ``` sed doesn't have truthy/falsy values, so I use the empty string as truty and everything else as falsy. This make sense because `/^$/` is the simplest (fully matching) if statement. [Try it online!](https://tio.run/nexus/sed#@1@sH6ehp62pE2Oooq///7@pjtG//IKSzPy84v@6RQA "sed – TIO Nexus") [Answer] # [Haskell](https://www.haskell.org/), 4 bytes ``` (==) ``` [Try it online!](https://tio.run/nexus/haskell#@59mq2Frq/k/NzEzz7agKDOvREFFIU3B0ACI/gMA "Haskell – TIO Nexus") (The function has to be named) [Answer] # JavaScript (ES6), 12 bytes ``` x=>y=>!(x-y) ``` Because `0` is false and all other numbers are true in JavaScript, if `x-y` equals `0`, a not `!` of that `0` will return `true`, and a not `!` of any other number will return false. Two bytes longer than simple comparison `x==y` as shown in @Shaggy's answer. [Answer] ## [MSM](http://esolangs.org/wiki/MSM), 31 bytes ``` '?ddF',',',.....T',',':'?....': ``` MSM is stack based, so the two input numbers are expected to be on top of the stack, i.e. on the right of the string. MSM has neither numbers nor booleans so we are free to choose a (reasonable) representation: ``` T True F False 123 numbers are just sequences of ascii digits. There's no literal representation in MSM source code, so you have to construct them digit by digit: 321.. -> 123 (remember: . is concatenation) ``` TIO doesn't support MSM out of the box, so I've included the JS interpreter from the esolang page. [Try it online!](https://tio.run/##hZDBTsMwDIbvPAXyYbW1NKxwSxX1xhNwGz1EaUdLtzZqXKYK8ewlyQ5wQCKRLFv/51@2382H8XbuHefj1LTbdvEXfVpGy/00ohcsjLBiECt9nqYZvfbSu3PPCEAlciy7/sRItNv546Eu6dpzh57WatUHNVToFt8hkxj0gRQa7Y9Wn9vxjbu8qAUI0JorNzkkBQ@pwIDUgctzW4uUm6DJGxjdEr1PMQhZEgZdKFC3/ghJ49x5DRsk7Gfo2FHdsFUn8xjDKKSSN5RJNIqJyrnlZR7v@evOhuNoyKqmec5E/DK@l5SrrIpFpuDOzZNtfTgKN9PC8jr33GI4KcLTYyFlCrCPZkR/w/A6Av3nUxS/fLbtGw "JavaScript (Node.js) – Try It Online") How it works: (I use `a` and `b` for the two numbers on the stack). Excerpt from the MSM command reference: ``` ' quote, push next char on the stack, even if it is a command ? skip next command if the two top elements of the stack are equal , drop : expand string at top of the stack and push each char of it on the stack . concatenate two top elements everything else is pushed ``` Stack trace: ``` ' ? d d F ' , ' , ' , . . . . . T ' , ' , ' : ' ? . . . . ' : a b d d F ' , ' , ' , . . . . . T ' , ' , ' : ' ? . . . . ' : a b ? ``` The next 6 chars are pushed on the stack and concatenated with 5 dots ``` T ' , ' , ' : ' ? . . . . ' : a b ? ,,,Fdd ``` The next 5 chars are pushed on the stack and concatenated with 4 dots ``` ' : a b ? ,,,Fdd ?:,,T ``` `:` and the two numbers are pushed ``` ? ,,,Fdd ?:,,T : a b ``` Now it gets interesting. If the two numbers are equal, `,,,Fdd` is skipped ``` ?:,,T : a b -- ?:,,T as a whole is not a command, so it's pushed : a b ?:,,T -- expand a b ? : , , T -- push a b ? : , , T a b -- a b are still equal, so skip : , , T a b -- drop a b T -- MSM stops, output is True ``` If the two numbers are not equal, don't skip `,,,Fdd`, but push it: ``` ,,,Fdd ?:,,T : a b : a b ,,,Fdd ?:,,T -- expand a b ,,,Fdd ? : , , T -- push up to ? ? : , , T a b ,,,Fdd -- number b is never equal to ,,,Fdd so expand , , T a b , , , F d d -- drop two dummy values T a b , , , F -- push T a b , , , F T a b -- drop b a T F -- stop ``` [Answer] # [Cubix](https://github.com/ETHproductions/cubix), 11 bytes ``` O0O1II-!//@ ``` [Try it online!](https://tio.run/nexus/cubix#@@9v4G/o6amrqK/v8P@/iY6CEQA "Cubix – TIO Nexus") This was harder than expected. Outputs 0 for falsy and 10 for truthy. [Answer] ## Java, 41 36 12 bytes -4 bytes thanks to @totallyhuman - Changed floats to ints -1 byte by removing space between second method argument and comma. -24 by converting the whole program to a lambda (woo). ``` (i,j)->i==j; ``` Takes the form of a java.util.function.BiFunction< Boolean, Integer, Integer > using an expression lambda. [Answer] # TI-BASIC, 13 bytes ``` Prompt A,B If A=B Disp 1 Else Disp 0 ``` Pretty self-explanatory. Prompts for two numbers and prints 1 if they are euqal, 0 otherwise. [Answer] # [Hexagony](https://github.com/m-ender/hexagony), 20 bytes -4 Bytes thanks to Jo King by using conditional wrapping. ``` ?}?".@!\!.!_1/@_-<~. ``` [Try it online!](https://tio.run/##y0itSEzPz6v8/19BQcFeoRaIlbgUFPQUHBQUFWIUFLmATEWFeAVDBX0FB654BV0FG4U6oBgQckEoGAeFDWP@/2@qYAIA) More readable version: ``` ? } ? " . @ ! \ ! . ! _ 1 / @ _ - < ~ . . . . . . . . . . . . . . . . . . ``` Prints 0 for truthy and 1 for falsy. There's a no-op at the end to keep it at a sidelength of 4. It might be possible to reduce the sidelength by one and safe a few more bytes. --- If I can print 0 for truthy and anything else for falsy, this would be a valid solution aswell: ``` ? } ? / - ! @ " / . . . . . . . . . . ``` This is basically just subtraction and seems like cheating to me. [Answer] # [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 60 bytes ``` [S S S N _Push_0][S N S _Duplicate_0][S N S _Duplicate_0][T N T T _Read_STDIN_as_integer][T T T _Retrieve][S S S T N _Push_1][S N S _Duplicate_1][T N T T _Read_STDIN_as_integer][T T T _Retrieve][T S S T _Subtract][N T S N _If_0_Jump_to_Label_EQUAL][T N S T _Print_as_integer][N N N _Exit_program][N S S N _Create_Label_EQUAL][S S S T N _Push_1][T N S T _Print_as_integer] ``` Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only. `[..._some_action]` added as explanation only. [Try it online](https://tio.run/##K8/ILEktLkhMTv3/X0FBgQsIgYiTixMEgAKcXAguJ4jLqcDFCRIBApBKsBCQ//@/rqGRMReIAAA) (with raw spaces, tabs and new-lines only). Outputs `1`/`0` as truthy/falsey values. 3 bytes could be saved by removing `NNN` if `1`/`01` as truthy/falsey values are allowed. **Pseudo-code:** ``` Integer i = STDIN as number Integer j = STDIN as number If(i == j): Call function EQUAL() Print 0 to STDOUT Exit program function EQUAL: Print 1 to STDOUT Exit automatically with error ``` [Answer] # [Flurry](https://github.com/Reconcyl/flurry), 30 bytes ``` {}{{}{}}[{}{{{}}}[<>()]](){{}} ``` You can test it with the interpreter: ``` $ for i in {0..5}; do $ for j in {0..5}; do $ ./Flurry -nin -c '{}{{}{}}[{}{{{}}}[<>()]](){{}}' $i $j $ done | xargs $ done 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 ``` In Flurry, popping from the stack returns the `I` combinator (`λa. a`), which also happens to be the Church numeral representation for the number 1. Thus we can compute `N != M` using the following method: * Push 0 to the stack. * Push 1 to the stack `N` times. * Pop from the stack `M` times and ignore the value. * Pop from the stack and return the value. This is how the program works conceptually, but we can combine the first two steps and the second two steps using a few tricks. * `{{}}` represents the `I` combinator (`1 = I = λa. a`). * `{{{}}}` is a function that pushes its argument to the stack and returns the `I` combinator (`λa. (push a; λb. b)`) * `[<>()]` represents zero (`0 = S K = λab. b`). * By applying the input number to both of these terms, we obtain the expression `n{{{}}}[<>()]`, which has the following semantics: + If `n > 1`, push 0 to the stack, followed by `n - 1` ones, and return 1. + If `n = 0`, push nothing to the stack and return 0. * `{{}{}}` is a function that takes an argument `a`, pops a value `b` from the stack, and returns `ba`. In this case, `a` and `b` are both guaranteed to be either zero or one, so it effectively returns `0` if `(a, b) == (1, 0)` and `1` otherwise. * By applying the input number to this term, and to the result of the previous term, we obtain the expression `n {{}{}} [m {{{}}} 0]`, which has the following semantics: + If `m = 0`, `[m {{{}}} 0]` pushes nothing and returns 0. Since the stack is empty, `{{}{}}` always pops one, so its return value is always 1. Thus the entire expression is 0 if `n = 0` and 1 otherwise. + If `m > 0`, `[m {{{}}} 0]` pushes 0 followed by `n - 1` ones and returns 1. Thus `{{}{}}` always returns the value popped from the stack, and `n {{}{}} 1` pops `n` times and returns the last value popped. The entire expression is 0 if `n = m` and 1 otherwise. The last step is to take the resulting number (representing whether the values are unequal) and negate it by applying it to `()` and `{{}}`. [Answer] # JavaScript (ES6), 10 bytes ``` x=>y=>x==y ``` [Answer] # [05AB1E](https://github.com/Adriandmen/05AB1E), 1 byte ``` Q ``` [Try it online!](https://tio.run/nexus/05ab1e#@x/4/78plykA "05AB1E – TIO Nexus") [Answer] # [Ohm](https://github.com/MiningPotatoes/Ohm), 1 byte ``` E ``` [Try it online!](https://tio.run/nexus/ohm#@@/6/78plykA "Ohm – TIO Nexus") Because `=` is too mainstream. [Answer] # [Python 2](https://docs.python.org/2/), 15 bytes ``` lambda x,y:x==y ``` [Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqhQoVNpVWFrW/m/oCgzr0QhTSMzr6C0RENTB0pr/jflMgUA "Python 2 – TIO Nexus") [Answer] # Mathematica, 6 bytes ``` #==#2& ``` [Answer] # Pyth, 2 bytes ``` qE ``` [Try it here :)](http://pyth.herokuapp.com/?code=qE&test_suite=1&test_suite_input=2%0A2%0A0%0A0%0A-123%0A-123%0A1%0A2%0A-2147483648%0A2147483648&debug=0&input_size=2) ]