Activity for celtschk
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Comment | Post #284088 |
Is it intentional that the standalone number is in words, but the numbers in expressions are in digits (except for the “negative” prefix)? (more) |
— | over 2 years ago |
Edit | Post #284136 |
Post edited: Fixed last testcase and added a few more |
— | over 2 years ago |
Comment | Post #284136 |
Oops, thank you for catching this. I'll fix and also add the extra test cases. (more) |
— | over 2 years ago |
Edit | Post #284137 | Initial revision | — | over 2 years ago |
Answer | — |
A: It's Hip to be Square [C (gcc)], 40 bytes i;f(n){for(i=1;n>0;n-=i,i+=2);return!n;} Try it online! (more) |
— | over 2 years ago |
Edit | Post #284136 | Initial revision | — | over 2 years ago |
Article | — |
Decode periodic decimal fractions [FINALIZED] Rational numbers in decimal representation can have an infinite periodic part. One common way to write this down is to repeat the periodic digits and then add three dots. Numbers without those three dots are taken to be non-periodic (or equivalently, have a periodic `0` after the given digits). Your ... (more) |
— | over 2 years ago |
Edit | Post #284131 |
Post edited: Typing the alphabet directly turned out to be shorter |
— | over 2 years ago |
Edit | Post #284131 | Initial revision | — | over 2 years ago |
Answer | — |
A: Create an Alphabet Diamond [Python 3], 99 bytes r=[range(26)] a="ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in r+r[-2::-1]:print(" "(26-i)+a[:i]+a[i::-1]) Try it online! (more) |
— | over 2 years ago |
Edit | Post #284104 |
Post edited: Removed one byte of unnecessary whitespace |
— | over 2 years ago |
Edit | Post #284104 | Initial revision | — | over 2 years ago |
Answer | — |
A: 1, 2, Fizz, 4, Buzz! [Python 3], 64 62 bytes for i in range(1,101):print("Fizz"(i%3<1)+"Buzz"(i%5<1)or i) Try it online! Saved two bytes thanks to Moshi in the comments. [Python 3]: https://docs.python.org/3/ [TIO-ku6jcjdz]: https://tio.run/##K6gsycjPM/7/Py2/SCFTITNPoSgxLz1Vw1DH0MBQ06qgKDOvREP... (more) |
— | over 2 years ago |
Edit | Post #284029 |
Post edited: posted as challenge |
— | over 2 years ago |
Edit | Post #284093 | Initial revision | — | over 2 years ago |
Question | — |
Repeat the characters Given a string and a non-negative integer $n$, output a new string in which each character is repeated $n$ times. Test cases: ``` "abc", 1 -> "abc" "Hello", 0 -> "" "double", 2 -> "ddoouubbllee" "Hi", 4 -> "HHHHiiii" "", 20 -> "" ``` (more) |
— | over 2 years ago |
Edit | Post #284060 | Initial revision | — | over 2 years ago |
Answer | — |
A: Are All Elements Equal? [C (gcc)], 46 bytes f(inta){return a<0|a[1]<0||a==a[1]&f(a+1);} This takes an array that is terminated by a negative number (which is not part of the list content, just like the terminating `\0` is not part of the string content in C strings). Try it online! (more) |
— | over 2 years ago |
Edit | Post #284032 | Initial revision | — | over 2 years ago |
Answer | — |
A: Tips for golfing in Python Replace print loops by list unpacking If you want to print elements of a list one per line, the straightforward way to do it is a loop: ``` for i in l:print(i) ``` But this can be shortened using list unpacking: ``` print(l,sep="\n") ``` Note that despite the extra `sep` this is still one ... (more) |
— | over 2 years ago |
Edit | Post #284029 | Initial revision | — | over 2 years ago |
Article | — |
Repeat the characters [FINALIZED] Given a string and a non-negative integer $n$, output a new string in which each character is repeated $n$ times. Test cases: ``` "abc", 1 -> "abc" "Hello", 0 -> "" "double", 2 -> "ddoouubbllee" "Hi", 4 -> "HHHHiiii" "", 20 -> "" ``` (more) |
— | over 2 years ago |
Comment | Post #284028 |
Good one. You could also mention that this also applies for different operators, for example `a<b>c` is valid and equivalent to `a<b and b>c`. (more) |
— | over 2 years ago |
Comment | Post #283990 |
Indeed, +1. This special case really adds some complexity, doesn't it? (more) |
— | over 2 years ago |
Edit | Post #284010 |
Post edited: |
— | over 2 years ago |
Edit | Post #284010 | Initial revision | — | over 2 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) |
— | over 2 years ago |
Comment | Post #283990 |
For the value 0, this returns the empty string instead of the string `0`. (more) |
— | over 2 years ago |
Edit | Post #283982 |
Post edited: It works also for more than one statement |
— | over 2 years ago |
Comment | Post #283982 |
Thanks, I hadn't been aware of that. (more) |
— | over 2 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) |
— | over 2 years ago |
Edit | Post #283865 |
Post edited: Updated wording and reference implementation, added more test cases |
— | over 2 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) |
— | over 2 years ago |
Comment | Post #283948 |
Actually not all your test cases are equations; better use the term “mathematical expression”. (more) |
— | over 2 years ago |
Edit | Post #283865 |
Post edited: Added rules about space |
— | over 2 years ago |
Edit | Post #283991 | Initial revision | — | over 2 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) |
— | over 2 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) |
— | over 2 years ago |
Edit | Post #283865 |
Post edited: Following the comments, define fixed number format |
— | over 2 years ago |
Comment | Post #283989 |
Are leading zeros in the output allowed? (more) |
— | over 2 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) |
— | over 2 years ago |
Edit | Post #283983 | Initial revision | — | over 2 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) |
— | over 2 years ago |
Edit | Post #283982 | Initial revision | — | 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 |
Edit | Post #283981 | Initial revision | — | 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 |
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) |
— | over 2 years ago |
Comment | Post #283978 |
@#54114 Actually it was the semicolon that I forgot to delete when I deleted the statement after it.
(more) |
— | over 2 years ago |
Edit | Post #283978 |
Post edited: Fixed spelling of my user name |
— | over 2 years ago |