Activity for celtschkâ€
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Answer | — |
A: Tips for golfing in Python If you print some string `s` without a newline character at the end, instead of ``` print(s,end="") ``` write ``` print(end=s) ``` to save two bytes. Note that this only works for strings, not for other types. Note also that if you print more than one string, then the `end=` part will a... (more) |
— | over 2 years ago |
Answer | — |
A: Tips for golfing in Python If you have a loop or `if`, you can save two or more characters (depending on the current indentation level and the number of statements in the body) by putting it right after the colon: For example, assume you have this loop with 33 characters: ``` for x in a: dosomethingwith(x) ``` Since y... (more) |
— | over 2 years ago |
Question | — |
Tips for golfing in Python If you have any tips for golfing in Python, add them as answers to this post. (more) |
— | over 2 years ago |
Answer | — |
A: "Hello, {name}!" [Bash], 20 18 bytes Saved two bytes by removing the quotes; the code works well without them. echo Hello, `cat`! Try it online! (more) |
— | over 2 years ago |
Article | — |
Convert integer to English [FINALIZED] Given a non-negative integer up to $999\\,999\\,999$, write it in English. The input number can be in any form other than English (though you'll typically want to use the native integer type of your language). When there are several variants of writing the number in English, you can choose whic... (more) |
— | over 2 years ago |
Answer | — |
A: Make my value binary [C (gcc)], 35 32 bytes Saved 3 bytes thanks to Lundin f(n){n&&f(n/2);putchar(n&1|48);} This solution exploits that leading zeros, while not required, are also not forbidden by the task. Try it online! (more) |
— | over 2 years ago |
Answer | — |
A: Reduce over the range [1..n] [C (gcc)], 50 bytes f(int(o)(i,j),int n){return n-1?o(f(o,n-1),n):1;} Try it online! (more) |
— | over 2 years ago |
Answer | — |
A: Output 256 in many different ways Unlambda, 1 solution Since Unlambda code that does something always contains the backtick character, there cannot be more than one solution. ``` ```.2.5.6i ``` (more) |
— | over 2 years ago |
Answer | — |
A: Make $2 + 2 = 5$ [C (gcc)], 33 31 bytes f(x,y){return x+y+(x==2&y==2);} Try it online! Saved two bytes thanks to Shaggy (more) |
— | over 2 years ago |
Question | — |
Multiply two strings Given two strings, I define their product as follows: If any of the two strings is empty, the product is the empty string. If the second string consists of a single character, the result is obtained by replacing every character of the first string that compares larger than that character ... (more) |
— | over 2 years ago |
Answer | — |
A: 99 Shortened Bottles of Beer [C (gcc)], 232 bytes f(n,w,p){printf("%i bottle%s of beer%s%s",n,"s"+(n1?"Take one down and pass it around, ":"Go to the store and buy some more, ");f(--i?:99,0,".\n\n");}} Try it online! Main golfing techniques: The repetitive part has been put into a function conditiona... (more) |
— | over 2 years ago |
Answer | — |
A: Evaluate a single variable polynomial equation [C++ (gcc)], 61 bytes float f(int n,floatp,float x){return n?p+xf(n-1,p+1,x):0;} Try it online! (more) |
— | over 2 years ago |
Article | — |
Multiply two strings [FINALIZED] Given two strings, I define their product as follows: If any of the two strings is empty, the product is the empty string. If the second string consists of a single character, the result is obtained by replacing every character of the first string that compares larger than that character ... (more) |
— | over 2 years ago |
Answer | — |
A: Golf a FRACTRAN interpreter [Python 3], 76 71 bytes Saved 5 bytes thanks to user def f(p,n):l=[np//q for(p,q)in p if n%q<1];return f(p,l[0])if l else n Try it online! This code assumes that the fractions are given as completely cancelled pairs of integers. (more) |
— | about 3 years ago |
Question | — |
Generate Lewis Caroll's Jabberwocky The task is to generate the text of Lewis Caroll's Jabberwocky. The text, quoted from Wikipedia, is as follows (I've replaced a non-ASCII character with ASCII, otherwise it's direct copy&paste from the linked Wikipedia article): ``` 'Twas brillig, and the slithy toves Did gyre and gimble in t... (more) |
— | over 3 years ago |
Answer | — |
A: Length of a Sumac Sequence [C (gcc)], 32 bytes f(a,b){return a>0?f(b,a-b)+1:0;} Try it online! (more) |
— | over 3 years ago |
Article | — |
Generate Lewis Caroll's Jabberwocky [FINALIZED] The task is to generate the text of Lewis Caroll's Jabberwocky. The text, quoted from Wikipedia, is as follows (I've replaced a non-ASCII character with ASCII, otherwise it's direct copy&paste from the linked Wikipedia article): ``` 'Twas brillig, and the slithy toves Did gyre and gimble in t... (more) |
— | over 3 years ago |
Answer | — |
A: Given the preorder and the inorder of a tree, output the postorder [C (gcc)], 114 bytes f(int n,intp,inti,into){if(n){intm=i,k;for(;m!=p;++m);k=m-i;f(k,p+1,i,o);f(n-k-1,p+k+1,m+1,o);(o)++=p;}} Try it online! Arguments: `n` is the length of the arrays `p` is the preorder array `i` is the inorder array `o` is a pointer to a pointer t... (more) |
— | over 3 years ago |
Article | — |
Run-length encode a byte sequence [FINALIZED] Run-length encoding is a simple compression technique which compresses sequences of repeating identical bytes. The encoding rules for this task are as follows: Any sequence of $n$ identical bytes ($3 \leq n \leq 63$) is replaced by a byte with value `n+0xc0` followed by only one copy of that by... (more) |
— | over 3 years ago |
Answer | — |
A: 1, 2, Fizz, 4, Buzz! C (gcc), 113 Bytes ``` i;main(){while(i++ / Declare a global int variable. The golfed code omits the type because of the old implicit-int rule, which only generates a warning also in modern gcc. Also note that global variables without initializer are zero-initialized; this is sti... (more) |
— | over 3 years ago |
- ← Previous
- 1
- 2
- Next →