Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 6532

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

4 votes

Code Golf Bingo!

C# – 536 (OK, this is probably not the most suitable language for that, but anyway…) using System;using System.Collections.Generic;using System.Linq;class C{static void Main(){var s=Enumerable.Range …
Mormegil's user avatar
  • 1,198
1 vote

Print integers in any base up to 36

C# – 85 characters string F(int n,int b){var s="";for(;n>0;n/=b)s=(char)(n%b+(n%b>9?87:48))+s;return s;}
Mormegil's user avatar
  • 1,198
2 votes

IPv4 Integer Conversion Function

C# – 77 chars Func<string,uint>F=s=>s.Split('.').Aggregate(0u,(c,b)=>(c<<8)+uint.Parse(b));
Mormegil's user avatar
  • 1,198
3 votes

Write all possible Braille characters

C# – 205 class C{static void Main(){var s="---##-##";Action<int,int>W=(i,m)=>{Console.WriteLine(s.Substring((i>>m&3)*2,2));};for(int i=0;i<64;++i){if((i&3)>0&&(i&42)>0){W(i,0);W(i,2);W(i,4);Console.W …
Mormegil's user avatar
  • 1,198
4 votes

Calculate ISBN-13 check digit

C# – 89 77 characters string I(string s){return s+(9992-s.Sum(x=>x-0)-2*s.Where((x,i)=>i%2>0).Sum(x=>x-0))%10;} Formatted for readability: string I(string s) { return s + (9992 …
Mormegil's user avatar
  • 1,198
1 vote

Removing unique elements from string

C# – 77 characters Func<string,string>F=s=>new string(s.Where(c=>s.Count(d=>c==d)>1).ToArray()); If you accept the output as an array, it boils down to 65 characters: Func<string,char[]>F=s=>s.Whe …
Mormegil's user avatar
  • 1,198
2 votes

Golf the Subset-Sum Problem

C# – 384 characters OK, functional-style programming in C# is not that short, but I love it! (Using just a brute-force enumeration, nothing better.) using System;using System.Linq;class C{static voi …
Mormegil's user avatar
  • 1,198
1 vote

Perform basic operations on complex numbers in a language without native support for complex...

C# – 369 (I guess) Func<float,float,float[]>C=(x,y)=>new[]{x,y}; Func<float[]>read=()=>{var m=new Regex(@"(\d*(\.\d*)?) *([+-]) *(\d*(\.\d*)?)i").Match(Console.ReadLine()).Groups;return C(float.Parse …
Mormegil's user avatar
  • 1,198
2 votes

Capitalize String

C# – 110 A simple finite-state-machine-based processing: x.Aggregate(new{b=1>0,r=""},(s,c)=>new{b="-. /&#".Contains(c),r=s.r+(s.b?Char.ToUpper(c):Char.ToLower(c))}).r (where x is the string to cap …
Mormegil's user avatar
  • 1,198
4 votes

Calculate Chinese Zodiac sign

C# – 357 337 339 bytes string Z(System.DateTime d){var c=new System.Globalization.ChineseLunisolarCalendar();var y=c.GetSexagenaryYear(d);var s=c.GetCelestialStem(y)-1;return",Rat,Ox,Tiger,Rabbit,Dra …
Mormegil's user avatar
  • 1,198
4 votes

Interpret +p code

C#, 130 129 127 bytes p=>d=>{var i=0;p.Any(c=>{Console.Write((c<44?d[i++]+d[i]:Enumerable.Range(2,d[i]-2).Any(x=>d[i]%x<1)?0:1)+" ");return++i<0;});} Try it online! Saved 1 byte by currying the fun …
Mormegil's user avatar
  • 1,198
1 vote

Remove a letter to make a palindrome

C# (184 characters) I admit this is not the best language to do code-golfing... using System.Linq;class C{static void Main(string[]a){int i=0,r=-1;while(i<a[0].Length){var x=a[0].Remove(i++,1);if(x= …
Mormegil's user avatar
  • 1,198
2 votes

Print the alphabet without using each vowel

C# – 278/149 Variant 1 – Full standalone programs A and I are unavoidable here because of class and static. Without U: 81 chars: class C{static void Main(){for(int x=65;x<91;++x)System.Console.Wri …
Mormegil's user avatar
  • 1,198
0 votes

Making a coin fair

C#, 83 bytes int[]M(int[]x)=>x.Select((v,i)=>i%2>0&&x[i-1]!=v?x[i-1]:2).Where(v=>v<2).ToArray(); First, replace odd-numbered items which are not equal to their predecessors with the predecessor, wh …
Mormegil's user avatar
  • 1,198