Hot answers tagged

295

Haskell I just love how you can throw anything at ghci and it totally rolls with it. λ> let 2+2=5 in 2+2 5


294

C Pretty cheap trick but I'm sure I will trap the most of you. int main() { int a = 2 + 2; ...


217

Jelly, 12 bytes N+N “(ẹ+)‘FQṖṪỌv Try it online! N×N ““((ẹẹ++))‘‘FFQQṖṖṪṪỌỌvv Try it online! N^N “““(((ẹẹẹ+++)))‘‘‘FFFQQQṖṖṖṪṪṪỌỌỌvvv Try it online! How it works Jelly has several different types of string literals; all of them start with a “. If the literal contains more than one “, a string array is returned, and “ separates the strings from each ...


208

Table cloths Flat I started out putting a plaid/gingham pattern into perspective like a boundless table cloth: unsigned char RD(int i,int j){ float s=3./(j+99); return (int((i+DIM)*s+j*s)%2+int((DIM*2-i)*s+j*s)%2)*127; } unsigned char GR(int i,int j){ float s=3./(j+99); return (int((i+DIM)*s+j*s)%2+int((DIM*2-i)*s+j*s)%2)*127; } unsigned char ...


190

Random painter char red_fn(int i,int j){ #define r(n)(rand()%n) static char c[1024][1024];return!c[i][j]?c[i][j]=!r(999)?r(256):red_fn((i+r(2))%1024,(j+r(2))%1024):c[i][j]; } char green_fn(int i,int j){ static char c[1024][1024];return!c[i][j]?c[i][j]=!r(999)?r(256):green_fn((i+r(2))%1024,(j+r(2))%1024):c[i][j]; } char blue_fn(int i,int j){ ...


184

GolfScript 4:echo(2+2); Prints 5.


180

2013 - Dogescript Dogescript is a language created in 2013 by Zach Bruggeman. It is nothing more than a syntax-replacement for Javascript to make it read like the internal monologues of memetic Shiba Inus. Hello doge console dose loge with "Dogescript was made in 2013!" ASCII Art such N much N much i as 0 next i smaller N next i more 1 ...


162

Some swirly pointy things Yes, I knew exactly what to name it. unsigned short RD(int i,int j){ return(sqrt(_sq(73.-i)+_sq(609-j))+1)/(sqrt(abs(sin((sqrt(_sq(860.-i)+_sq(162-j)))/115.0)))+1)/200; } unsigned short GR(int i,int j){ return(sqrt(_sq(160.-i)+_sq(60-j))+1)/(sqrt(abs(sin((sqrt(_sq(86.-i)+_sq(860-j)))/115.0)))+1)/200; } unsigned short BL(...


143

Java Always have to round your doubles, folks public class TwoPlusTwo { public static void main(String... args) { double two = two(); System.out.format("Variable two = %.15f%n", two); double four = Math.ceil(two + two); // round just in case System.out.format("two + two = %.15f%n", four); } // 20 * .1 = 2 private ...


135

BBC BASIC EDIT: For Andrea Faulds and Squeamish Ossifrage, a more convincing version using a different interpreter: http://sourceforge.net/projects/napoleonbrandy/ MODE 6 VDU 23,52,254,192,252,6,6,198,124,0 PRINT PRINT "2+2=";2+2 PRINT "2+3=";2+3 The original image using the emulator at http://bbcbasic.co.uk/bbcwin/bbcwin.html. ...


133

Brainfuck +++++ +++++ + + + + + +++++ +++++ +++ +++++ + + + +++++ + + +++++ +++++. Output: 5 Try it here. I know this might sound a little to simple, but I tried to be creative, as suggested in original post.


132

C, 0.026119s (Mar 12 2016) #include <math.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define cache_size 16384 #define Phi_prec_max (47 * a) #define bit(k) (1ULL << ((k) & 63)) #define word(k) sieve[(k) >> 6] #define sbit(k) ((word(k >> 1) >...


122

Of course, there has to be a Mandelbrot submission. char red_fn(int i,int j){ float x=0,y=0;int k;for(k=0;k++<256;){float a=x*x-y*y+(i-768.0)/512;y=2*x*y+(j-512.0)/512;x=a;if(x*x+y*y>4)break;}return k>31?256:k*8; } char green_fn(int i,int j){ float x=0,y=0;int k;for(k=0;k++<256;){float a=x*x-y*y+(i-768.0)/512;y=2*x*y+(j-512.0)/512;x=a;if(...


120

Mandelbrot 3 x 133 chars The first thing that popped into my mind was "Mandelbrot!". Yes, I know there already is a mandelbrot submission. After confirming that I'm able to get it below 140 characters myself, I have taken the tricks and optimizations from that solution into mine (thanks Martin and Todd). That left space to choose an interesting ...


116

Python, 3 bytes min Try it online! Takes a number string, outputs its smallest digit as a smallest character. For example, 254 gives 2. The decimal with these digits starts 0.0123456789011111111101222222220123333333012344444401234555550123456666012345678801234567 This is OEIS A054054. Claim: This number c is transcendental Proof: Note that c is ...


110

Julia sets If there's a Mandelbrot, there should be a Julia set too. You can spend hours tweaking the parameters and functions, so this is just a quick one that looks decent. Inspired from Martin's participation. unsigned short red_fn(int i, int j){ #define D(x) (x-DIM/2.)/(DIM/2.) float x=D(i),y=D(j),X,Y,n=0;while(n++<200&&(X=x*x)+(Y=y*y)<...


109

Taxi, 7394 3773 bytes Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Tom's Trims.Pickup a passenger going to Tom's Trims.Go to Tom's Trims:n.[a]Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 1 l 2 r.Pickup a passenger going to Addition Alley.Pickup a ...


107

This one is interesting because it doesn't use the i, j parameters at all. Instead it remembers state in a static variable. unsigned char RD(int i,int j){ static double k;k+=rand()/1./RAND_MAX;int l=k;l%=512;return l>255?511-l:l; } unsigned char GR(int i,int j){ static double k;k+=rand()/1./RAND_MAX;int l=k;l%=512;return l>255?511-l:l; } ...


103

/* RED */ int a=(j?i%j:i)*4;int b=i-32;int c=j-32;return _sq(abs(i-512))+_sq(abs(j-512))>_sq(384)?a:int(sqrt((b+c)/2))^_cb((b-c)*2); /* GREEN */ int a=(j?i%j:i)*4;return _sq(abs(i-512))+_sq(abs(j-512))>_sq(384)?a:int(sqrt((i+j)/2))^_cb((i-j)*2); /* BLUE */ int a=(j?i%j:i)*4;int b=i+32;int c=j+32;return _sq(abs(i-512))+_sq(abs(j-512))>_sq(...


102

Sharp EL-9300 Graphics Calculator, 296 bytes This was my secondary school graphing calculator, getting on for 20 years ago! I remember writing a mandelbrot generator for it way back then. And sure enough, its still sitting there in the NV memory: ClrG DispG Range -2.35,2.35,.5,-1.55,1.55,0.5 y=-1.55 Label ly x=-2.35 Label lx n=1 zx=0 zy=0 Label ln tzx=zx²-...


101

Python Inspired by the Java answer: >>> patch = '\x312\x2D7' >>> import ctypes;ctypes.c_int8.from_address(id(len(patch))+8).value=eval(patch) >>> 2 + 2 5 A more obfuscated version exec("\x66\x72\x6f\x6d\x20c\x74\x79\x70e\x73\x20\x69\x6d\x70\ \x6f\x72\x74\x20c\x5f\x69\x6e\x748\x20a\x73\x20x\x3bf\x72\x6f\ \x6d\x20\x73\x74\x72\...


100

CJam - 13 q~,>{mfW=}$0= Try it at http://cjam.aditsu.net/ Example input: 2001 2014 Example output: 2002 Explanation: q~ reads and evaluates the input, pushing the 2 numbers on the stack (say min and max) , makes an array [0 1 ... max-1] > slices the array starting at min, resulting in [min ... max-1] {…}$ sorts the array using the block to ...


91

C and C++, 68 65 bytes #include<math.h> float f(float n){auto p=.5;return pow(n,2-p*3);} Original answer: #include<math.h> float f(float n){return pow(n,sizeof('-')-1?2:.5);} For both versions, C produces n^2 and C++ produces sqrt(n).


90

><>, 41 bytes \< 1:: : &&* + i*n n c& %: 4l 0( .i n} &? Try it online: N+N, N*N, N^N. Assumes that the STDIN input is exactly one char. ><> is a 2D language, so we can make use of the fact that code semantics are mostly unchanged if we execute instructions downwards — the extra empty lines that ensue are just no-ops. The ...


86

I came across this the other day. I don't take credit for it, but damn, is it awesome: Python 2: _ = ( 255, lambda V ,B,c :c and Y(V*V+B,B, c ...


86

JavaScript: g = function () { H = 3 return H + H } f = function () { Η = 2 return Η + H } // 3 + 3 = 6 alert(g()) // 2 + 2 = 5 alert(f()) Check it at http://jsfiddle.net/qhRJY/


81

Buddhabrot (+ Antibuddhabrot) Edit: It's a proper Buddhabrot now! Edit: I managed to cap the colour intensity within the byte limit, so there are no more falsely black pixels due to overflow. I really wanted to stop after four... but... This gets slightly compressed during upload (and shrunk upon embedding) so if you want to admire all the detail, here ...


77

Algorithm Using the well-known result: we define in Python 3: from math import sin from functools import reduce from operator import mul def integrate(f, a, b, n): h = (b-a)/n i = h * sum(f(a+i*h+h/2) for i in range(n)) return i def sinc(x): return sin(x)/x def borwein(n): def f(x): g = lambda i: sinc(x/(2*i+1)) return reduce(...


Only top voted, non community-wiki answers of a minimum length are eligible