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
Answer A: Digit antitranspose
[Python 3], 35 bytes lambda m:list(zip(m[::-1]))[::-1] Try it online! The format is a list of tuples. The content of the tuples could be any type; in my tests I used single-digit strings because I was lazy when writing the testing code. `seq[::-1]` reverses a sequence (tuple ot l...
(more)
over 1 year ago
Answer A: Encode with ROT13.5
[Bash], 31 bytes tr a-zA-Z0-9 n-za-mN-ZA-M5-90-4 Try it online!
(more)
over 1 year ago
Answer A: Thoughts on hiding challenge sections with expandable details tags
I think everything strictly needed to write or judge a solution should never be hidden. If you feel it is too large, think about how to shorten it. Information that is not strictly necessary can be hidden if large. This includes background information that, while in principle necessary for the cha...
(more)
over 1 year ago
Answer A: Presumptuous base conversion
[C (gcc)], 117 bytes b,r;f(chars){charp=s;for(;p;p++)p-=47+7(p>57),b=b<p?p:b;if(b<2)return p-s;for(;s;s++)r=b,r+=s-1;return r;} Try it online!
(more)
over 1 year ago
Answer A: Cumulative Counts
[Python 3], 74 bytes def f(a): d={x:0 for x in a};r=[] for x in a:d[x]+=1;r+=[d[x]] return r Try it online!
(more)
almost 2 years ago
Answer A: Roll n fair dice
[Python 3], 59 bytes lambda n,m:sum(choices(range(m),k=n))+n from random import Try it online!
(more)
almost 2 years ago
Question Does Looping Counter qualify as kolmogorov-complexity?
Lundin just suggested in a comment under another question that I tag the challenge Looping Counter as kolmogorov-complexity. Now I'm not sure if it actually qualifies for that tag, for the following reasons: It is an infinite loop producing an infinite output, unlike the existing challenges ...
(more)
almost 2 years ago
Question Under which condition is a function that takes arguments other than those specified by the challenge by itself a valid solution to a challenge?
On my challenge Looping Counter there are several entries like this which contains a function which needs to be called with the right parameters to give the correct output. In this particular case, you get the desired output if and only if the function is called as `f(3,2)`; any other call gives a wr...
(more)
about 2 years ago
Question Looping counter
Looping counter Create an infinite loop that outputs lines of asterisks, with each line containing one more asterisk. Instead of the asterisk, any printable, non-whitespace character can be used. However all lines need to use the same character. The beginning of the output looks like this: ```...
(more)
about 2 years ago
Answer A: Reverse an ASCII string
SOS, 76 bytes +>+>????????{>!!!!!!!!<<-)
(more)
about 2 years ago
Article Looping counter [FINALIZED]
Looping counter Create an infinite loop that outputs lines of asterisks, with each line containing one more asterisk. Instead of the asterisk, any printable, non-whitespace character can be used. However all lines need to use the same character. The beginning of the output looks like this: ```...
(more)
about 2 years ago
Answer A: "Hello, World!"
SOS, 155 Bytes !+!-!!+!-!!!!+!!-!!+!-!+!-!+!!-!+!!-!!!+!!-!+!!-!!!+!!-!+!!!!-!!+!-!+!!-!!!!+!-!!!!!!+!-!+!-!+!!!-!+!!-!+!!!!-!+!!!-!!+!-!!+!!-!+!!-!!!+!!-!!+!-!!+!-!!!!+! Explanation: Each `!` outputs a single bit. That bit is 0 if the current stack is empty, and 1 otherwise. Initially t...
(more)
about 2 years ago
Article Word wrap a string
Given a string `s` of text and a line length `l`, your task is to word-wrap that text to that line length. Concretely, the given string consists of words separated by single spaces, with no leading or trailing space. The task is then to replace spaces by newlines such that in each line, there are ...
(more)
over 2 years ago
Question Determine whether an integer is square-free
An integer is called square-free if it is not a multiple of a perfect square other than 1. For example, 42 is square-free, but 44 is not because it is a multiple of the perfect square 4 = 2². Your task is to write a program or function that takes a positive integer, and returns a truthy value if t...
(more)
over 2 years ago
Article Determine whether an integer is square-free [FINALIZED]
An integer is called square-free if it is not a multiple of a perfect square other than 1. For example, 42 is square-free, but 44 is not because it is a multiple of the perfect square 4 = 2². Your task is to write a program or function that takes a positive integer, and returns a truthy value if t...
(more)
over 2 years ago
Answer A: Find the IP address class
[C (gcc)], 64 62 bytes Saved 2 bytes thanks to m90 in the comments. i;f(chars){i=atoi(s)>>4;return'A'+(i&8?i&4?i&2?i%2+3:2:1:0);} Try it online!
(more)
over 2 years ago
Answer A: Golf golf challenge
[C (gcc)], 133 131 bytes f(p,s){chart="Hole in one\0Albatross\0Eagle\0Birdie\0Par\0Bogey\0Double bogey\0Triple bogey";for(--s?s+=5-p:0;s-=!t++;);puts(t);} Saved two bytes thanks to m90 in the comments. Try it online!
(more)
over 2 years ago
Answer A: 1, 2, Fizz, 4, Buzz!
[C (gcc)], 103 bytes Using a different approach than my previous solution, therefore posting as new answer as suggested here. i;main(){while(i++<100){char s[]="FizzBuzz",t=s+4!!(i%3);if(i%5)s[4]=0;t?puts(t):printf("%d\n",i);}} Try it online!
(more)
over 2 years ago
Question New solution to same challenge in same language: Change existing answer or add new one?
A while ago I wrote an answer in C (gcc) to the FizzBuzz challenge. Now I've found a shorter solution for the same compiler, which however uses a completely different strategy. Now I wonder if I should add that solution to my current answer, or instead add a new answer with that different solution...
(more)
over 2 years ago
Question Implement Rule 110
[Rule 110] is a Turing complete cellular automaton. It is defined as follows: Take as initial value a sequence of symbols that's infinite to both sides, which consists only of two different symbols (I'm going to use $+$ and $-$ here). This sequence can be seen as a function that maps the integers ...
(more)
over 2 years ago
Answer A: Tips for golfing in C
Use pointer arithmetic and `\0` with string literals In C, strings are just zero-terminated character arrays, which means you can play tricks with pointer arithmetic. For example, the line ``` chars=a<2?"":"s"; ``` can be replaced with ``` chars="s"+(a<2); ``` Note that you also can use ...
(more)
over 2 years ago
Answer A: Operation "Find The Operator"
[Python 3], 106 91 bytes Saved 15 bytes thanks to Moshi in the comments lambda a,b,c:[p for p in"+ - // % ".split()if(p in'+-'or b)and eval(f"{a}{p}{b}")==c] Try it online!
(more)
over 2 years ago
Article Implement Rule 110 [FINALIZED]
[Rule 110] is a Turing complete cellular automaton. It is defined as follows: Take as initial value a sequence of symbols that's infinite to both sides, which consists only of two different symbols (I'm going to use $+$ and $-$ here). This sequence can be seen as a function that maps the integers ...
(more)
over 2 years ago
Question Run-length encode a byte sequence
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 2 years ago
Question Find good coalitions
As you might know, there were elections in Germany, and now the parties have to form a government coalition. Let's help them with it! A good coalition has the strict majority of seats (that is, more seats than the opposition). Moreover you don't want more parties than necessary in a coalition, tha...
(more)
over 2 years ago
Question Encode and decode floating point integers
Imagine you have only one byte (8 bits) to store a value, but need to store values from $0$ to $4032$. Impossible, until you are also told that an error of 1/64 of the exact value does not matter. With that knowledge, you decide to design a floating point integer type, which is defined as follows:...
(more)
over 2 years ago
Answer A: Truthify an array
[Python 3], 75 bytes lambda a:[[i,k]for i in r(l(a))for k in r(l(a[0]))if ai] r=range;l=len Try it online!
(more)
over 2 years ago
Answer A: "Hello, World!"
[Unlambda], 40 bytes `````````````.H.e.l.l.o.,. .W.o.r.l.d.!i Try it online!
(more)
over 2 years ago
Article Find good coalitions [FINALIZED]
As you might know, there were elections in Germany, and now the parties have to form a government coalition. Let's help them with it! A good coalition has the strict majority of seats (that is, more seats than the opposition). Moreover you don't want more parties than necessary in a coalition, tha...
(more)
over 2 years ago
Question Convert integer to English
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). The numbers must be formatted as follows: Two-digit numbers must be written wit...
(more)
over 2 years ago
Answer A: Define a mathematical expression in English
[C (gcc)], 774 bytes #define S strcat(o, #define I(s)if(n)S s);else{S" ");return;} #define B);break;case n,N,s;chari,o[999],d[]={"zero ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ","eleven ","twelve ","thir","four","fif","six","seven","eigh...
(more)
over 2 years ago
Article Encode and decode floating point integers [FINALIZED]
Imagine you have only one byte (8 bits) to store a value, but need to store values from $0$ to $4032$. Impossible, until you are also told that an error of 1/64 of the exact value does not matter. With that knowledge, you decide to design a floating point integer type, which is defined as follows:...
(more)
over 2 years ago
Answer A: Reverse your quine
[Python 3], 69 bytes i="))43,]1-::[i,43,73(%ci(tnirp;%c%s%c=i";print(i%(37,34,i[::-1],34)) Try it online!
(more)
over 2 years ago
Answer A: Tips for golfing in Python
Replace `n+1` with `-n` and `n-1` with `-n` For integers, `n+1` and `-n` have the same value, as have `n-1` and `-n`. While the expressions themselves have the same lengths, the replacements often allow to save space by allowing either to remove whitespace or to omit parentheses due to differen...
(more)
over 2 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)
over 2 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)
over 2 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)
over 2 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)
over 2 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)
over 2 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)
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
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
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
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
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
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
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
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
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
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