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 Lundin‭

Type On... Excerpt Status Date
Answer A: Reverse the bits in a Byte
[C (gcc)], 42 bytes c;f(i){c++>1));} Try it online! Binary output version.
(more)
9 months ago
Answer A: Reverse the bits in a Byte
[C (gcc)], 47 bytes r,c;f(i){return c++>1)),r;} Try it online! I didn't manage to come up with anything better than the most obvious recursive implementation posted above. I tried to use a different algorithm based on iterating two counters instead, but it got quite a bit longer....
(more)
9 months ago
Answer A: Hosting fastest code challenges
If restricting everyone to the same system, then can force every contestant to use https://tio.run and the on-site bench-marking found below "debug" -> "real time" as efficiency metric. Example. Advantages: - No matter how (in)accurate, this gives everyone the same conditions and the same benc...
(more)
11 months ago
Answer A: How should we handle incorrect answers?
^ That can be used. You can try to contact the person who posted the challenge and have them mark the answer as "React -> Invalid". Or otherwise it seems that anyone can mark an answer as invalid? I think this was the original purpose of that feature for this site. The help text for the react...
(more)
over 1 year ago
Answer A: Lowercase, but not just the letters
[C (gcc)], 36 bytes f(intp){for(;p;putchar(32|p++));} Try it online! Similar solutions: - 36 bytes too but with new lines: `f(intp){for(;p;p|=32,puts(p++));}` - 37 bytes using recursion: `f(intp){p&&putchar(32|p)&&f(++p);}`
(more)
over 1 year ago
Answer A: Sort letters by height
[C (gcc)], 152 bytes r;e(c){r=c=='j'?5:strchr("bdfghklpqy",c)?4:c=='i'?3:c=='t'?2:1;}c;s;f(chari,charo){s?(e(i),c=r,e(o)):(qsort(i,strlen(i),s=1,f),puts(i));return r-c;} Try it online! Output: ```text a aa jbita kitc now jtus jpyitzx ``` I didn't fine tune it much, ...
(more)
over 1 year ago
Answer A: Make a frequency table (histogram)
[C (gcc)], 45, 42 bytes t[9999];f(s,a)inta;{for(;s;)t[a[--s]]++;} Try it online! Assumptions: - Passing the array size to a function can be used as a means to deal with empty arrays (not supported in C). - A table of integers can be regarded as a hashtable with an integer val...
(more)
almost 2 years ago
Article Code bowling using unique characters
The aim of the challenge is to write as long a source code as possible (code bowling), every character typed gives 1 point, using the following rules: - No symbol typed in the source may be re-used twice. That is, only one `a`, only one `1`, only one `+` and so on. - Whitespace characters do not ...
(more)
almost 2 years ago
Answer A: Rules for function submissions
Function parameters should not be allowed to be used in place of a return value. Reasons: - Terms like return value and function result are explicitly specified as a specific, formal language item in most languages. Therefore, interpreting a challenge asking for a return value as "return th...
(more)
almost 2 years ago
Answer A: Keyword golfing
[C (gcc)], 358 bytes static inline Noreturn float f(union u);extern Threadlocal Complex long doublerestrict B;main(void){Atomic register enum {A};typedef Alignas(unsigned char)struct S;Staticassert(Alignof(Bool),"Imaginary");do goto a;while(sizeof B);if(1)for(auto volatile const signed sho...
(more)
almost 2 years ago
Answer A: Roll n fair dice
[C (gcc)], 48 43 bytes s;r(n,m){s+=rand()%m+1;return--n?r(n,m):s;} Try it online! Previous 48 bytes version using loop: `i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;}`
(more)
almost 2 years ago
Answer A: Looping counter
[C (gcc)], 47 bytes i,n;f(){for(i=n+++2;i--;)putchar(i?42:13);f();} Try it online!
(more)
about 2 years ago
Answer A: Can you give me half?
[C (gcc)], 8 7 unique cos(cos-cos)/(cos(cos-cos)-(-cos(cos-cos))) Try it online! -1 unique character thanks to @orthoplex‭
(more)
about 2 years ago
Question Keyword golfing
Many programming languages have the concept of keywords, special syntax items that are not just identifiers reserved by some library, but words reserved by the language itself. The challenge is to write a minimal program for a language with such keywords, with as few characters as possible (code ...
(more)
about 2 years ago
Article Keyword golfing [FINALIZED]
Many programming languages have the concept of keywords, special syntax items that are not just identifiers reserved by some library, but words reserved by the language itself. The challenge is to write a minimal program for a language with such keywords, with as few characters as possible (code ...
(more)
over 2 years ago
Question Golf golf challenge
The task is to create a program which displays a golf score as text. It takes 2 numbers as input, separated by space or new line: - The first number is the par of the specific hole. - The second number is the score that the player got. The program should print the textual golf term for the re...
(more)
over 2 years ago
Article Golf golf challenge [FINALIZED]
The task is to create a program which displays a golf score as text. It takes 2 numbers as input, separated by space or new line: - The first number is the par of the specific hole. - The second number is the score that the player got. The program should print the textual golf term for the re...
(more)
over 2 years ago
Answer A: Reactions on Code Golf Codidact
None of these are applicable at least not for Code Golf challenges. I think this community should "opt out" of reactions unless we can come up with more relevant ones. - "Works for me". Answers are supposed to live up to the challenge specification - if they don't, then one should use comments to ...
(more)
over 2 years ago
Answer A: Operation "Find The Operator"
[C (gcc)], 147 151 bytes #define L(X)X(+,a+b)X(-,a-b)X(,ab)X(/,b&&a/b)X(%,b&&a%b)X(^,pow(a,b)) #define M(o,d)printf("%s",d==c?#o" ":z++==5?".":""); z;s[99];f(a,b,c){L(M)} Try it online! Somewhat naive solution with X macros that builds up a string before printing. The `...
(more)
over 2 years ago
Article Bird is the word
Make a program that prints the lyrics of the first verse of Surfin' Bird by the Trashmen: > A-well-a everybody's heard about the bird B-b-b-bird, b-bird's the word A-well, a bird, bird, bird, bird is the word A-well, a bird, bird, bird, well-a bird is the word A-well, a bird, bird, b...
(more)
over 2 years ago
Answer A: Repeat the characters
[C (gcc)], 56 bytes i;f(s,n)chars,n;{for(;s;s++)for(i=n;i--;putchar(s));} Try it online! My attempt at recursion ended up at 61 bytes: o;f(s,n)chars,n;{for(o=n;s&&n--;putchar(s));s&&f(++s,o);} I still think there's probably a more elegant way to solve both loops wit...
(more)
over 2 years ago
Answer A: Can we have [popularity-contest]s?
Well... maybe not in combination with a code golf challenge, but more like an artistic challenge with some theme, similar to screenshot of the month? For reference see for example Outdoors photo contest or Writing challenges. So rather than giving a detailed specification of what the program must ...
(more)
over 2 years ago
Answer A: Default Rules: Code Golf I/O
Command-line arguments may be used as input instead of stdin Languages/systems that support reading input from command-line arguments may use those as input instead of reading from stdin.
(more)
over 2 years ago
Answer A: "Hello, {name}!"
[C (gcc)], 43 bytes a[99];main(){printf("Hello, %s!",gets(a));} Try it online!
(more)
over 2 years ago
Answer A: Make $2 + 2 = 5$
[C (gcc)], 30 bytes f(x,y){return x+y|!(x^y|x^2);} Try it online! In case the "preferably on a function" requirement can be dropped, then #define f(x,y)x+y|!(x^y|x^2) is 28 bytes.
(more)
over 2 years ago
Article Pass a value through different memory sections
Lets get a bit closer to the metal than usual! The task is to pass a constant value between the different data memory sections of a typical computer. For this challenge you need a system and language which allows you to allocate variables in all of the following sections (using ELF notation): ...
(more)
over 2 years ago
Answer A: In The Jailhouse Now
[C (gcc)], 119 118 116 115 bytes #define p(x,y,z) printf(i^1?i^c?#z:#y:#x) i,j;f(c){for(i=1;i<=c;p(╗\n,╝\n,╣\n),i++)for(j=p(╔,╚,╠);j++<c;)p(╦,╩,╬);} Try it online! Function solution. I started with a recursive solution but it didn't work out well... though I'm still conv...
(more)
over 2 years ago
Answer A: 99 Shortened Bottles of Beer
[C (gcc)], 244 bytes main(){for(charw=" bottles of beer on the wall",i=100;--i;)printf("%d%.s%s, %d%.s%.8s.\n%s, %d%.s%s.\n\n",i,i-1?8:7,w,w+8,i,i-1?8:7,w,w+8,i^1?"Take one down and pass it around":"Go to the store and buy some more",i^1?i-1:99,i^2?8:7,w,w+8);} Try it online! Ful...
(more)
over 2 years ago
Answer A: Default Rules: Extensions
The `C (gcc)` implies extensions - it will only work with that specific compiler under it's default setting GNU17 (equivalent to `-std=gnu17`), which is mostly a superset of standard C. This also includes a number of POSIX functions. Another option is standard C, meaning no extensions and no const...
(more)
over 2 years ago
Answer A: Coat of Many Colours
C, 534 bytes Strictly conforming program. #include #include #include char i=1,c,d,t[30]={"red","yellow","green","brown","scarlet","black","ochre","peach","ruby","olive","violet","fawn","lilac","gold","chocolate","mauve","cream","crimson","silver","rose","azure","lemon"...
(more)
over 2 years ago
Question How to add lots of command line arguments to https://tio.run?
I have a question about everyone's favourite Code Golf editor https://tio.run. After picking a language, is there a sensible way to enter command line arguments to it, other than adding them manually one by one? For one golf challenge here I need to add some 30+ arguments for testing and that quic...
(more)
over 2 years ago
Answer A: Caesar shift cipher
[C (gcc)], 112 bytes Function solution. p,a;f(chars,int n){a=strdup(s);for(s=a;s;s++)(p=isalpha(s)?(s&96)^96?65:97:0)&&(s=(s-p+n)%26+p);puts(a);} Try it online! Explanation: The code takes a hard copy of the passed parameter and increases each character with the value, but...
(more)
over 2 years ago
Answer A: Tips for golfing in C
For the sake of code golf, you first need to decide if you wish to compete in strictly conforming ("real") C, in which case you can't rely on non-standard extensions, poorly-defined behavior or obsolete features. Or you can compete in non-standard extensions (gcc/GNU etc), when whatever binary the...
(more)
over 2 years ago
Answer A: Guess the language! (Cops' Thread)
C or C++ (gcc) 220 bytes, cracked by Razetime %: %: define cops(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) if(not false and k%:%:f%:%:d%:%:l(& (not true) )) %: main() Try it online! Output: ``` Cops and Robbers ``` Some explanation/de-obfuscation: - `%:` ...
(more)
over 2 years ago
Answer A: It's Hip to be Square
[C (gcc)], 57 64 bytes x,s;main(){scanf("%d",&x);s=sqrt(x);printf("%d",ss==x);} Try it online!
(more)
over 2 years ago
Answer A: Is my extension-like library allowed to be used in answers?
If you actually use the library, sure, I guess. How you are going to get it running on online compilers, I have no idea. It's very uninteresting for others to view some code using a custom library though... you'd be golfing "single player". Your answer here is doesn't use the library and is agains...
(more)
almost 3 years ago
Answer A: Evens or Odds - you know this one
[C (gcc)], 20 bytes f(a){puts("!"+a%2);} Try it online! Function solution. Prints `!` in case of even numbers, otherwise just new line.
(more)
almost 3 years ago
Article FizzBuzz based on line count
Background The normal "FizzBuzz" task is to create an up-counting loop which prints "Fizz" in case the count is divisible by 3 or "Buzz" in case the count is divisible by 5. Consequently, "FizzBuzz" for numbers like 15 that are divisible by both. Task The task is to write a solution which pr...
(more)
almost 3 years ago
Answer A: Microcontroller-involving challenges and the rules.
For this to work, I think we need to rule out all start-up code (the C runtime) but also the register maps. So I think answers should be a `void main (void){ ... }` (or equivalent) function solution where the register map is included but not counting as part of the solution. Other than that, ban all ...
(more)
about 3 years ago
Answer A: Write a Deadfish Interpreter
[C (gcc)], 153 bytes a,b;f(chars){for(charc,o="idso";s;s++)for(c=o;c;c++)s==c&&(b=c-o,a+=!b,a-=b==1,b==2?a=a:0,b==3&&printf("%d%c",a,s[1]?44:10),a==-1|a==256?a=0:0);} Try it online! Function solution, misc gcc abuse.
(more)
about 3 years ago
Article Print the alphabet using alphabetic source
The task is to write a program that takes no input and prints the English alphabet in upper-case letters. It can be printed either as a single line `ABCDEFGHIJKLMNOPQRSTUVWXYZ`, or as letters separated by spaces, or as letters separated by new line. This is code golf, so the shortest program in e...
(more)
over 3 years ago
Answer A: Truthify an array
[C (gcc)], 100 bytes i,j;f(x,y,p)intp;{puts("[");for(;i<x;i++)for(j=0;j<y;j++)p++&&printf("[%d,%d],",i,j);puts("\b]");} Try it online! Note that TIO console doesn't handle backspace properly.
(more)
over 3 years ago
Answer A: Tile pyramids on top of each other!
C (compliant), 106 bytes char r,i,s[80];void f(int n){memset(s,32,79);for(;r<n;puts(s),r++)for(i=0;i++<n2;s[n-r-1]=47,s[n+r]=92);} Try it online! Standard C compliant function solution.
(more)
over 3 years ago
Article The Tannenbaum series
A series of 7 single digits, that if added in sequence to create an unbalanced binary search tree, is considered a Tannenbaum series, in case: - the left branch of the root has depth 3 and consists of ever-increasing numbers, and - the right branch of the root has depth 3 and consists of ever-de...
(more)
over 3 years ago
Answer A: Integer to Roman numeral
C (compliant), 197 198 bytes. Golfed version of the function in the question, using X macros: ```c #define L Y(1000,M)Y(900,CM)Y(500,D)Y(400,CD)Y(100,C)Y(90,XC)Y(50,L)Y(40,XL)Y(10,X)Y(9,IX)Y(5,V)Y(4,IV)Y(1,I)return r; #define Y(n,R)for(;v>=n;v-=n)strcat(r,#R); char r[99];charf(int v)...
(more)
over 3 years ago
Question Integer to Roman numeral
The task is to take a decimal integer as input and print the corresponding Roman numeral with capital letters. The program must handle all positive integer numbers between 1 and 1000. Input can be assumed to be correct and no error handling is necessary. Example data: ``` Input Output 1 ...
(more)
over 3 years ago
Answer A: "Hello, World!"
LOLCODE, 37 bytes HAI 1 VISIBLE "Hello, World!" KTHXBYE Try it online!
(more)
over 3 years ago
Answer A: Prime Difference
C (gcc), 126 129 bytes ```c N=9999;f(n){int p[N],i,j,P;memset(p,1,N);for(i=P=2;ii=n?j=N:(P=i);}e:return P;} ``` Try it online! This is an integer input/output function solution. The upper limit of prime number supported is the square root of`N`, so currently it counts prime numbers up to 9...
(more)
over 3 years ago
Answer A: Output 256 in many different ways
C, 8 solutions Standard C, no extensions. 1 solution snippet per line: ```c "llll"[3]^33^333 4444 5555-555-555-555-555-555-555-555-555-555-55-55-55-55-55-5-5-5-7-7 6666/26 (int){8<88}<<8 u'\xff'+!!u'\xff' 0XFFFFFeFF LINE ``` Somewhat naive solution so far, but the nu...
(more)
over 3 years ago
Article Integer to Roman numeral
The task is to take a decimal integer as input and print the corresponding Roman numeral with capital letters. The program must handle all positive integer numbers between 1 and 1000. Input can be assumed to be correct and no error handling is necessary. Example data: ``` Input Output 1 ...
(more)
over 3 years ago