Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Activity for celtschk‭

Type On... Excerpt Status Date
Edit Post #284213 Initial revision about 3 years ago
Answer A: Tips for golfing in Python
Replace if/else expressions by array subscripts Consider the statement ``` a=b if x<y else c ``` You can get rid of the expensive keywords by using the implicit conversion of boolean values to integer and array indexing: ``` a=b,c ``` Note however that here `b` and `c` are evaluated uncond...
(more)
about 3 years ago
Comment Post #284195 Thanks, edited.
(more)
about 3 years ago
Edit Post #284195 Post edited:
Adopted improvements suggested by @user in the comments
about 3 years ago
Edit Post #284180 Post edited:
Added forgotten scoring criterion
about 3 years ago
Comment Post #284180 Oops, yes, it's supposed to be code golf. I'll edit.
(more)
about 3 years ago
Edit Post #284195 Post edited:
Adopted improvement by @Hakerh400
about 3 years ago
Edit Post #284195 Initial revision about 3 years ago
Answer A: Collatz conjecture; Count the tries to reach $1$
[Python 3], 48 42 39 bytes Saved 6 bytes thanks to Hakerh400‭ in the comments Saved another 3 bytes thanks to user in the comments f=lambda n:n-1and-f(n//2,3n+1) Try it online!
(more)
about 3 years ago
Edit Post #284136 Post edited:
about 3 years ago
Edit Post #284180 Initial revision about 3 years ago
Question Decode periodic decimal fractions
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)
about 3 years ago
Comment Post #283865 @#53196 It was referring to the individual three-digit group.
(more)
about 3 years ago
Edit Post #284158 Post edited:
Added example noted by @user
about 3 years ago
Comment Post #284158 Thanks; actually I hadn't been aware of the number before keyword case. I'll add this.
(more)
about 3 years ago
Edit Post #284159 Initial revision about 3 years ago
Answer A: Weave Strings Together
[Python 3], 91 90 bytes Saved one byte thanks to Mark Giraffe in the comments lambda l:"".join(["".join(x)for x in ziplongest(l,fillvalue='')]) from itertools import Try it online!
(more)
about 3 years ago
Edit Post #284158 Post edited:
about 3 years ago
Edit Post #284158 Initial revision about 3 years ago
Answer A: Tips for golfing in Python
Reorder expressions in order to save whitespace Consider the following code: ``` if c=='U':c='X' ``` The space between `if` and `c` obviously cannot be removed, as that would merge them to the identifier `ifc`. However by reversing the order of the arguments to `==`, the space becomes removabl...
(more)
about 3 years ago
Edit Post #284155 Initial revision about 3 years ago
Answer A: Abbreviate everything
[Python 3], 142 bytes def f(s): &#9;m=1;r="" &#9;for c in s.upper(): &#9;&#9;if'@'&lt;c&lt;''or'-'==c:r+=cm;m=0 &#9;&#9;if c in":; ":r+=c(c!=' ');m=1 &#9;&#9;if c in".?!":r+=' ';m=1 &#9;return r [Try it online!
(more)
about 3 years ago
Edit Post #284136 Post edited:
Fixed two test cases and added another one
about 3 years ago
Comment Post #284136 Oops, right, thank you again. I'll immediately fix this.
(more)
about 3 years ago
Edit Post #284136 Post edited:
Added a few more test cases
about 3 years ago
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)
about 3 years ago
Edit Post #284136 Post edited:
Fixed last testcase and added a few more
about 3 years ago
Comment Post #284136 Oops, thank you for catching this. I'll fix and also add the extra test cases.
(more)
about 3 years ago
Edit Post #284137 Initial revision about 3 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)
about 3 years ago
Edit Post #284136 Initial revision about 3 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)
about 3 years ago
Edit Post #284131 Post edited:
Typing the alphabet directly turned out to be shorter
about 3 years ago
Edit Post #284131 Initial revision about 3 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)
about 3 years ago
Edit Post #284104 Post edited:
Removed one byte of unnecessary whitespace
about 3 years ago
Edit Post #284104 Initial revision about 3 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)
about 3 years ago
Edit Post #284029 Post edited:
posted as challenge
about 3 years ago
Edit Post #284093 Initial revision about 3 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)
about 3 years ago
Edit Post #284060 Initial revision about 3 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)
about 3 years ago
Edit Post #284032 Initial revision about 3 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)
about 3 years ago
Edit Post #284029 Initial revision about 3 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)
about 3 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)
about 3 years ago
Comment Post #283990 Indeed, +1. This special case really adds some complexity, doesn't it?
(more)
about 3 years ago
Edit Post #284010 Post edited:
about 3 years ago