Activity for celtschk
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Edit | Post #284010 | Initial revision | — | about 3 years ago |
Answer | — |
A: When The Ternary Is Balance [Python 3], 78 bytes def t(n,l):d="0+-"[n%3];return d(not l or nn) if nn<2 else t((n+1)//3,1)+d Try it online! (more) |
— | about 3 years ago |
Comment | Post #283990 |
For the value 0, this returns the empty string instead of the string `0`. (more) |
— | about 3 years ago |
Edit | Post #283982 |
Post edited: It works also for more than one statement |
— | about 3 years ago |
Comment | Post #283982 |
Thanks, I hadn't been aware of that. (more) |
— | about 3 years ago |
Comment | Post #283865 |
OK, I've changed both the reference implementation and the wording, and added more test cases. Can you please check again (in particular the wording; English is not my native language, therefore any suggestions for improvement are welcome)? (more) |
— | about 3 years ago |
Edit | Post #283865 |
Post edited: Updated wording and reference implementation, added more test cases |
— | about 3 years ago |
Comment | Post #283865 |
Well, actually that is a case I didn't consider. On one hand, the wording is obviously misleading because that's not what it was referring to, on the other hand I think “one million and one” is the reasonable result here. I'll have to think about how to adapt the rules/reference implementation accord... (more) |
— | about 3 years ago |
Comment | Post #283948 |
Actually not all your test cases are equations; better use the term “mathematical expression”. (more) |
— | about 3 years ago |
Edit | Post #283865 |
Post edited: Added rules about space |
— | about 3 years ago |
Edit | Post #283991 | Initial revision | — | about 3 years ago |
Answer | — |
A: A number adder, not a death adder [C (gcc)], 87 bytes P1: i;main(){scanf("%d",&i);printf("i;main(){scanf(\"%%d\",&i);printf(\"%%d\",%d+i);}",i);} Try it online! Generated P2 for input 10: i;main(){scanf("%d",&i);printf("%d",10+i);} Try it online! (more) |
— | about 3 years ago |
Comment | Post #283865 |
OK, I now made a concrete specification and a reference implementation. The inconsistent dashes in ninety-nine however simply were typos, than you for catching them.
(more) |
— | about 3 years ago |
Edit | Post #283865 |
Post edited: Following the comments, define fixed number format |
— | about 3 years ago |
Comment | Post #283989 |
Are leading zeros in the output allowed? (more) |
— | about 3 years ago |
Comment | Post #283982 |
I'm just too used to write C++ code that requires it, so I tend to write them without even noticing. Thanks for catching that.
(more) |
— | about 3 years ago |
Edit | Post #283983 | Initial revision | — | about 3 years ago |
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) |
— | about 3 years ago |
Edit | Post #283982 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Edit | Post #283981 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Comment | Post #283978 |
BTW, I just found you can reduce by two further bytes by using `enumerate` in the loop. While the `enumerate` expression itself is a bit longer, that is more than made up by replacing `x[i]` with `c` in the loop. And no semicolon this time ;-)
[Try it online!](https://tio.run/##JcnBCoMwDADQe7@ieEq... (more) |
— | about 3 years ago |
Comment | Post #283978 |
@#54114 Actually it was the semicolon that I forgot to delete when I deleted the statement after it.
(more) |
— | about 3 years ago |
Edit | Post #283978 |
Post edited: Fixed spelling of my user name |
— | about 3 years ago |
Suggested Edit | Post #283978 |
Suggested edit: Fixed spelling of my user name (more) |
helpful | about 3 years ago |
Comment | Post #283978 |
And another golfing opportunity: the `if i:` can be replaced by multiplying `x[i]` with `bool(i)`, and then the whole line can be combined into a single string, getting rid also of the `end=`. This brings down the byte count to 92.
[Try it online!](https://tio.run/##LcpBCsMgEEDRvaeQrGYUF2l3Fk8Ssmj... (more) |
— | about 3 years ago |
Comment | Post #283978 |
I've now noticed that you can dramatically shorten the code again by using Python's slicing syntax. Just replace the complete first loop with `x+=x[-2::-1]` and then remove the now unused variable `j`. This brings the byte count down to 103.
[Try it online!](https://tio.run/##RckxCsMwDADAOXqFyCS18... (more) |
— | about 3 years ago |
Comment | Post #283978 |
You can save quite a few bytes here.
First, you can replace `print(" ",end='')` with `print(end=" ")`, saving 3 bytes. But then, you can replace the whole `j` loop with `print(end=" "*(k-2))`. Then you can merge the two `print` statements into one: `print(x[i],end=" "*(k-2))`. Since now the `if` c... (more) |
— | about 3 years ago |
Edit | Post #283974 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Edit | Post #283864 |
Post edited: Adopted improvement by @Lundin |
— | about 3 years ago |
Edit | Post #281721 |
Post edited: Adopted improvements suggested by @user in the comments |
— | about 3 years ago |
Comment | Post #283917 |
I think is is better to separate the tags. After all, if a draft introduces a new tag, but doesn't get to Challenges, then IMHO the tag shouldn't be in main either.
Ideally, the tags in the Sandbox would be the union of the tags on Challenges and Sandbox-only tags. But I don't think the software s... (more) |
— | about 3 years ago |
Edit | Post #283865 |
Post edited: fixed a spelling error in the test cases |
— | about 3 years ago |
Edit | Post #283865 |
Post edited: forgot to add the code-golf tag |
— | about 3 years ago |
Edit | Post #283865 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Edit | Post #283864 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Edit | Post #283862 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Edit | Post #283803 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Edit | Post #283782 |
Post edited: Saved two bytes thanks to Shaggy |
— | about 3 years ago |
Comment | Post #283782 |
@#53588 Thank you. Since the JS solution is too different, changing to that now would seem to me like cheating, but I'll use the 31 byte solution. (more) |
— | about 3 years ago |
Edit | Post #283782 | Initial revision | — | about 3 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) |
— | about 3 years ago |
Edit | Post #283603 |
Post edited: finalized |
— | about 3 years ago |
Edit | Post #283690 | Initial revision | — | about 3 years ago |