text:
Shortest Floor Function
Your task is to implement a floor function in as few bytes as possible.
A floor function is a function that takes a real number and returns the largest integer less than or equal to the input.
Your program should support both positive and negative inputs.  Since it is provably impossible to support all real numbers you need only support a reasonable subset of them.  This subset should include positive numbers, negative numbers and of course numbers that are not integers.  Such number systems include fixed-point numbers, floating point numbers and strings.
Your code may be a complete program or function.
This is code-golf so answers will be scored in bytes with less bytes being a better score.

Any limits on the size of the numbers to be handled correctly? Need to treat negatives?

I ask about range because single precision IEEE 745 floating point runs up to 2^127, which is to say that 64 bit integers would not be sufficient.

@dmckee The problem definition states any real number, not just positive ones. As far as number size is concerned, let's assume that is not a concern (i.e., an answer that handles that case is not necessarily better than an answer that doesn't handle that case, unless of course it is of equal or lesser length).

In golfscript, this would be zero bytes since x is already an integer :)

Would return (int)input; (in Java, and possibly C, C++, and C# too) count as a "built-in rounding function"?

@TheGuywithTheHat Type casting is fine, but this does not give the correct answer.

@DanielStandage Why not?

@TheGuywithTheHat Try it on negative numbers and see what you get.

PARI/GP (10)
In gp (and some other languages) x%1 gives the decimal part of x:
f(x)=x-x%1

NOTE: For negative x, x%1 returns (1 - abs(decimal part of x)), so the above works both for positive and negative numbers.

@Joey: no it does not. Yields -4 for floor(-3.1234); -4 for floor(-4). What do you get?

x - x % 1 gives -3 for -3.1234, surely, when the expected answer is -4

@Nellius: NO, because -3.1234%1 = 0.8766.

Ok, I take that back, partially. Because the sign of the modulus result depends on the operand in some languages but not in others. For me, -3.14 % 1 yields -.14 (PowerShell). Now, if you'd be so kind to make a null edit so I can take the downvote back? :-)

@Joey: I had to clarify that anyway :)

@Eelvex Does PARI/GP have function syntax? If so, it would be fair to wrap your answer in a function as you have done with your other solutions.

@Daniel: you're right. Done.

You can shave off 2 characters with x->x-x%1. If not for the restriction you could use x->x\1 which is another 2 characters shorter.

Javascript - 6 bytes
Usage of the arrow function declaration (as an anonymous function here) and a bitwise "AND" operator
x=>x&x

Try it online!
or alternatively using the bitwise "OR" operator:
x=>x|0

Try it online!

Welcome to the site! You can shave two bytes off, by removing the name of the function; as long as functions aren't recursive, the name isn't necessary. Also, is it possible to provide a link to a site such as TryItOnline where other users can verify your answer?

Surely. Thank you for the advice :)

JavaScript, 50 34 33 32 characters
function f(n){return~~n-(~~n>n)}

Works the same way as the PHP one I submitted.

32 chars if you drop the ;

If you use ES6, it is 14 characters:n=>~~n-(~~n>n)

8 bytes: n=>n-n%1

Python (20)
f=lambda x:int(x//1)

or, if the result doesn't need to be of type int, 15 characters:
f=lambda x:x//1

Two notes:

you can skip the f= part, as it is not recursive.
please state, that this is Python 3 code and not Python 2

DC (15 bytes)
Makes use of a nifty little trick that occurs during division in DC. Add a 'p' to then end to get output (it performs the floor correctly anyway), I assume that stuff is not already on the stack, and that input is in stdin.
[1-]sazk?z/d0>a

EG: echo 0 2.6 - | dc -e '[1-]sazk?z/d0>ap'

Python (81)
def f(x):return str(x - float("." + str(float(x)).split('.')[-1])).split('.')[0]

You can go down to 76 bytes by removing unnecessary spaces! def f(x):return str(x-float("."+str(float(x)).split('.')[-1])).split('.')[0]

C (51)
int F(float x){int i=x-2;while(++i<=x-1);return i;}

Generally code gold answers are expected to be in the form of either a function or a complete program (here the OP has selected a function), so you need the int f(float c){} bit.

@dmckee: forgot that, sorry.

Why <=x-1? would <x not be exactly the same thing, but 3 characters shorter?

@Nellius: no, it's not the same (unfortunately).

@Nellius: only when x is an integer: compare "<=3.5-1" with "<3.5".

LISP (26)
(Same trick as in PARI/GP answer)
(defun f(x)(- x(mod x 1)))

You can strip off the space before the (mod.

@Chris: :) Thx.

C 126 (including NL)
Doesn't use any built-in conversion such as (int)x.
r(float x) {
int
p=*(int*)&x,
f=p&8388607|1<<23,
e=((p>>23)&255)-150;
if(e>0)f*=1<<e;
if(e<0)f/=1<<-e;
return p>>31?-f-1:f;
}

C (80)
Well it's not the shortest, but it's a great opportunity to show off my bit twiddling skills :D.
main(){int I,X=0x7FFFFF;scanf("%f",&I);printf("%d",((I&X)|X+1)>>-(I>>23)+150);}

J  7 chars
f=:-1&|  NB. x - (x mod 1)

eg.
f 3.14
3
f _3.14
_4

Is there a good reason this isn't the accepted answer?

C, 42 41 bytes
int F(float x){int i=x;return i<=x?i:i-1;}

Try it online!
int F(float x){int i=x;return x>i?i:i-1;}

Try it online!

Welcome to Code Golf, nice first answer!

Hi there, welcome to CGCC. If you haven't seen it yet, tips for golfing in C and tips for golfing in  might be interesting to read through. :) Some golfs you could do to your current function: <= could be > (and the values swapped) for -1 byte; return  can be x= for -5 bytes; and you can remove the leading int  (it will give a warning, but we can ignore that) for -4 bytes. So in total: F(float x){int i=x;x=i>x?i-1:i;} (32 bytes). Enjoy your stay! :)

@KevinCruijssen Thanks for the tips. I don't understand all your tips. It looks too nonstandard to me. So I only used your first tip.

Ruby 1.9 (12 14)
 f=->x{x-x%1}

It's more a "for the record" type solution along the lines of the PARI/GP one.
>> f[3.4] #=> 3.0
>> f[-3.4] #=> -4.0

You don't need the parentheses around x%1.

APL, 1 byte (SBCS)
According to the updated rules, built-ins are allowed:
⌊

APL (dzaima/APL), 5 4 bytes
Anonymous tacit prefix function abiding by the old prohibition on built-ins:
⊢-1|

Try it online!
⊢ the argument
- minus
1| the division remainder when divided by 1

Julia, 17 bytes
f(x)=x-x%1-(x<0)

port of the PARI/GP answer
f(-pi) = -4
f(pi) = 3

Turing Machine Code, 39 bytes
0 * * r 0
0 _ _ l 1
1 * _ l 1
1 . _ l 2

Try it online!

C# (56 chars):
My quick and naive answer earlier had a stupid logical flaw in it. Two approaches here, which I believe are both the same length. Double approach relies on the fact that casting to int removes the decimal part of a double.
int F(double d){return(int)(d%1==0?d:(int)d-(d<0?1:0));}

Decimal approach relies on the fact that d%1 returns the decimal part of the number for decimal data type.
int F(decimal d){return(int)(d%1==0?d:d-d%1-(d<0?1:0));}

Could save a few characters in both cases by returning their own type instead of int, but I feel a floor function should return an int.

You can use float instead and save a byte.

PHP, 51 45 43 37 characters
function f($n){return~~$n-(~~$n>$n);}

This should be able to be applied to most languages that do not support the n%1 trick.

Since this does not need to be an independently working program, I think you can safely trim the first 3 characters (i.e. the <? ) off your solution.

Perl (23)
$_=int($_)-(int($_)>$_)

Example:
perl -ple '$_=int($_)-(int($_)>$_)'

Every value entered on input will now be printed "floored".
Its bass5098's technique, but smaller =).
As a function(36):
sub f{int($_[0])-(int($_[0])>$_[0])}

Any particular reason for shying away from regex?

This can be shortened by getting rid of the default variable: $_=(int)-($_<int)

Java 8, 19 bytes
Lambda from double to int. There are plenty of choices for types to assign to: Function<Double, Integer>, DoubleFunction<Integer>, or DoubleToIntFunction.
n->(int)(n<0?n-1:n)

Try It Online

RProgN 2, 4 bytes
]1%-

Explained
]1%-
]   # Duplicate the implicit input
 1% # Modulo 1
   -# Subtract Modulo 1 of the input from the input, inplicitly outputting the floor'd result.

Try it online!

x86_64 machine language (Linux), 11 bytes
0:       c4 e3 79 0b c0 01       vroundsd $0x1,%xmm0,%xmm0,%xmm0
6:       f2 0f 2c c0             cvttsd2si %xmm0,%eax
a:       c3                      retq

This requires a processor with AVX instructions.
To Try it online!, compile and run the following C program.
#include<stdio.h>
#include<math.h>
int f(double x){return floor(x);}
const char g[]="\xc4\xe3\x79\x0b\xc0\x01\xf2\x0f\x2c\xc0\xc3";

int main(){
  for( double d = -1.5; d < 1.5; d+=.2 ) {
    printf( "%f %d %d\n", d, f(d), ((int(*)(double))g)(d) );
  }
}

05AB1E, 2 bytes
Oï

Try it online or verify all values in the range \$[5,-5]\$ in \$0.1\$ increments.
Explanation:
O   # Sum the stack, which will use the (implicit) input-string if the stack is empty
    # (the input is read as string by default, so this `O` basically casts it to a float)
 ï  # Floor this input-float
    # (and output the resulting integer implicitly)

Although it may look pretty straight-forward, there are actually some things to note:
In the legacy version of 05AB1E, which was built in Python. The ï builtin would translate to the following code snippets:
# Pop number
a = str(number)         # Cast number to a string
a = ast.literal_eval(a) # Evaluate this string as Python structure (so it goes back to a float)
a = int(a)              # Cast this float to an integer (which will truncate)

So whether you had string input or decimal input, it would cast it to a string during the code execution anyway, before casting it to an integer to truncate all decimal values.
Try it online with -0.5 as decimal argument.
Try it online with "-0.5" as string argument.
The new version of 05AB1E is built in Elixir however. Now, the ï builtin translates to the following code snippets (huge parts removed to only keep the relevant stuff):
call_unary(fn x -> to_integer(x) end, a)      # Call the function `to_integer`, which will:
                                              # (I've only kept relevant parts of this function)
 is_float(value) -> round(Float.floor(value)) #  If it's a float: floor it down
 true ->                                      #  Else (it's a string):
     case Integer.parse(to_string(value)) do  #   Parse it from string to integer
        :error -> value                       #   If this resulted in an error: return as is
        {int, string} ->
            cond do                           #   Else it was parsed without errors:
                Regex.match?(~r/^\.\d+$/, string) -> int
                                              #    If it contains no decimal values:
                                              #      Return parsed int
                true -> value                 #    Else: return as is

Or as a TL;DR: float inputs are floored; string inputs are truncated.
Try it online with -0.5 as decimal argument.
Try it online with "-0.5" as string argument.
As you can see, a string input gives the incorrect floored result for negative decimals. Unfortunately, the default (implicit) input from STDIN is always a string, so we'll have to convert it to a float first (for which I've used O - which only works on an empty stack in the new 05AB1E version built in Elixir; for the legacy 05AB1E version built in Python, the sum would result in 0 for an empty stack).

In your TIO the floor of (for example) -4.7 is -4, but it actually is -5

@Davide Ah, I apparently had the output of negative values reversed. I thought the string input gave the correct results, but instead the float inputs give the correct results. Should be fixed now (at the cost of a byte).

Yeah it works now, I am sorry for the 100% increase in the number of bytes

@Davide haha, np. Due to lack of test cases, I simply reversed the intended outputs for negative inputs. Thanks for noticing!

Excel, 7
Tested in Excel Online. Closing parens not counted toward score.
The only reason I posted this is because, oddly enough, it seems to work the exact same as FLOOR.MATH() with 1 argument.
=INT(A1)

Semantically, at least to me, it would make sense if this didn't work for negative numbers. However, INT(-.5) is -1 for some reason. TRUNC() does what I think INT() should do.

C (gcc), 16 15 bytes
g;f(d){g=d>>9;}

Try it online!

Such number systems include fixed-point numbers, floating point numbers and strings.

I don't know why people insist on using floats... Fixed point is much easier
Uses 32-bit fixed9 precision. Abuses arithmetic shift right. Return hack, not much else to say.

I think you can save 3 bytes by cutting off g; and doing d>>=9;

Nah, that doesn't work. Undefined behavior is weird.

Oh all right, it was worth trying

x86-64 machine code, 7 bytes
Machine code:
00000000: 66 0f 3a 0b c0 01 c3                             f.:....

Assembly:
        .intel_syntax noprefix
        .globl floor_sse4
floor_sse4:
        roundsd xmm0, xmm0, 1
        ret

Try it online!
Accepts a double in an xmm0.
Returns the floored double in xmm0.
Outgolfs the previous answer without cheesing with fixed point.

Nowhere did it say the return type had to be an int, just an integer. Therefore, I can just skip the conversion code, storing the integer as a double. JavaScript has been doing it for decades.
This one only requires SSE4.1.

Yes, I know the SSE conversion functions are a little redundant in the test code.
x86-64 machine code, fixed point joke, 1 byte
Machine code:
00000000: c3                                               .

Assembly:
        .intel_syntax noprefix
        .globl floor_fixed
floor_fixed:
        ret

Try it online!
This function takes a 16-bit fixed8 in ax and returns a signed 8-bit integer in ah. It is not sign extended.
Nobody gave any specifics about precision

Vyxal, 3 bytes
1%-

Push input, modulo with 1 and negate!
Try it!
Vyxal, 1 byte
⌊

Though a builtin.....
Try it!

Hexagony, 31 bytes
,{.4{?<.(@!?\"!3'-<_".$>@>?~..@

    , { . 4
   { ? < . (
  @ ! ? \ " !
 3 ' - < _ " .
  $ > @ > ? ~
   . . @ . .
    . . . .

Try it online! or Try it online differently!
Takes input of the form +/-a.b, ex: +4.5 or -0.1 or +3. Since hexagony doesn't have built in decimal types, the input must contain a + if positive in order to not cut off the first digit of the number. This answer can definitely be improved, but its a start.

floor, 5 bytes
floor
The floor function is a (the only) built-in.
Full program (17 bytes):
Floor only accepts integers as program Input, so the program uses two inputs to generate a rational number to be passed to the floor function
f:x y->floor(x/y)
implementation

Python, 13
If the OP wants all functions to be non-anonymous, add f= to the front of each for two additional characters.
lambda x:x//1

Since x%1 returns the amount following the decimal point, this is pretty short (14):
lambda x:x-x%1

The shortest using string casting I could come up with (40):
lambda x:int(`x`.split('.')[0])+cmp(x,0)

int(x) wouldn't work since python floor will round up negative numbers while floor will always go to the lower ones. For example. floor(-5.9) should be -6, but int(-5.9) will return -5. you can take a couple more bytes and add a -1 if the original number is smaller than 1.

@Dat I'll just remove it, because int(x//1) has already been done.

MATL, 5 bytes
The programming language used in this answer was created after the challenge was posted.
it1\-

Examples
>> matl it1\-
> 5.6
5

>> matl it1\-
> -5.2
-6

Explanation
Pretty straightforward. It uses a modulo operation with divisor 1.
i      % input
t      % duplicate
1      % number literal
\      % modulus after division
-      % subtraction

You should note that this language was developed wayyyyyy after this challenge.

@cat Sorry, I hadn't noticed. Disclaimer added

Mouse-2002, 13 bytes
Second place, ahh! (And this is a full program, not a function definition)
?&DUP &FRAC -

Take the fractional bit of the input and subtract it from the input.

Perl 5, 22 bytes
s/\..+//&&$_<0?$_--:$_

This is larger than my first answer, which merely truncated the number - so, for negative numbers, it wasn't correct. This was due to a misunderstanding on my part of what a floor function does.

RProgN, 1 byte
_

A builtin, thanks to the new challenge spec.
Try it online!

same for K Try it online!

AArch64 machine language (Linux), 8 bytes
0: 1e700000 fcvtms w0, d0
4: d65f03c0 ret

To try it out, compile and run the following C program
#include<stdio.h>
#include<math.h>
int f(double x){return floor(x);}
const char g[]="\x00\x00\x70\x1e\xc0\x03\x5f\xd6";

int main(){
  for( double d = -1.5; d < 1.5; d+=.2 ) {
    printf( "%f %d %d\n", d, f(d), ((int(*)(double))g)(d) );
  }
}

Wren, 16 bytes
Exactly ported from the PARI/GP answer.
Fn.new{|x|x-x%1}

Try it online!
Wren, 26 bytes
Ported from the Keg answer.
Fn.new{|x|x.split(".")[0]}

Try it online!

Keg, 6 5 4 bytes
:1%-

Try it online!
 Look ma, no unicode!
A port of the RProgN2 answer

Jelly, 1 byte
Ḟ

Try it online!
or a non-builtin answer
%1_@

Try it online!
How the second one works
%1_@ - Main link. Takes n on the left
%1   - Fractional part of n
  _@ - n - frac(n)

Python 3, 15 bytes
f=lambda n:n//1

Try it online!

Lua, 27 25 18 15 bytes
print(...//1|0)

Try it online!
Explanation
... variable-argument operator, returns the remaining arguments passed to the current function (top-level code block with all the program arguments in this case).
//1 floor divides by 1.
|0 bitwise OR, we use this to convert to an int.

Pyth, 3 bytes
/Q1

Try it online!

MMIX, 8 bytes (2 instrs)
05000300 F8010000

Disassembly
    FIX $0,ROUND_DOWN,$0
    POP 1,0

MMIX has a builtin instruction for this. You can specify the rounding mode if you like, but you can use the default. (Options are towards 0, towards \$-\infty\$, towards \$\infty\$, or to nearest half to even.)
Honestly, I'd advise using a FIX directly, as opposed to calling.

ARBLE, 4 bytes
n//1

Try it online!
Outputs with a leading .0. If this is forbidden, then...
ARBLE, 5 bytes
floor

Try it online!

Thunno 2, 2 bytes
1÷

Try it online!
Floor divide by one.
Funnily enough, Thunno 2 doesn't have a proper floor built-in. For positive numbers, you can use N (truncate), but that doesn't work for negative numbers.


text:
Quine that takes as input the name of a language and outputs the same thing implemented in the input language
From Quine central:
Write a quine that takes as input the name of a language and outputs the same thing implemented in the input language.
The source article has something you can work from, but as the author says this is much harder. Obviously you only need to support a limited set of languages. The choice is yours though, as well as the base language.
As a code-challenge, your score will be the number of languages your program supports; higher is better.

Catchy title...

Define "number of languages".

@Adám: Well, the point of the challenge is to write a program that supports a set of languages, as follows: giving it the name of any of the languages as input will output an equivalent program in that language. The number of languages in which the program works is the size of the set. This isn't my challenge (just one I bountied), so I don't think there's an "official" source on corner cases; as such, we can and should all collaboratively edit the challenge to make it better/clearer without changing the meaning.

@ais523 What's to stop us from writing a polyglot quine that takes input and does nothing with it? That'd be perfectly legal according to these rules.

@mbomb007: it is legal, but might not be the easiest way to answer the question. Polyglot quines can often be hard to fit additional languages into, whereas the question as currently worded doesn't require you to write a polyglot (and can be solved via a set of universal quine constructors, one in each language you use).

@ais523 That's true.

Whats the tie breaker?

@RohanJhunjhunwala I think it's code-golf.

I was working on a Python/Retina solution, but I gave up. It takes a lot of hours, similar to my solution for this challenge. Taking input didn't make it any easier, on the Retina side at least.

@mbomb007 I was going to make a [https://github.com/rjhunjhunwala/S.I.L.O.S]/ java implementation. I like the way it would turn out, but it would be quite monstrous and would surely not win in terms of size.

Ruby
require 'json';s=%q[{"ruby":[" %q[","require 'json';s=##;j=JSON.load s;puts j[l=gets.chomp][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))"," ]"],"python":["' ''","import json,re;s=##;j=json.loads(s);l=raw_input();print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))","' ''"]}];j=JSON.load s;puts j[l=gets.chomp][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))

Python
import json,re;s='''{"ruby":[" %q[","require 'json';s=##;j=JSON.load s;puts j[l=gets.chomp][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))"," ]"],"python":["' ''","import json,re;s=##;j=json.loads(s);l=raw_input();print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))","' ''"]}''';j=json.loads(s);l=raw_input();print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))

Both versions take input on stdin (ruby or python currently) and generate the output to stdout in either language.

Turtlèd, Python 2, and Python 3, 3 languages, only competing for bounty
all oneliners follwed by newline
Turtlèd
@##'@r,r,r-{ +.r_}r{ +.r_}!!-.(3"';m=ord(input()[-1]);_='x=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))';print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"367>;++[ d( d)('.)]d<"x='"))(2"';m=ord(raw_input()[-1]);_='x=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))';print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"371>;++[ d( d)('.)]d<"x='"))(d' )#'@r,r,r-{ +.r_}r{ +.r_}!!-.(3"';m=ord(input()[-1]);_='x=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))';print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"367>;++[ d( d)('.)]d<"x='"))(2"';m=ord(raw_input()[-1]);_='x=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))';print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"371>;++[ d( d)('.)]d<"x='"))(d' )

Try it online!
Python 2
x='@##y@r,r,r-{ +.r_}r{ +.r_}!!-.(3"y;m=ord(input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"367>;++[ d( d)(y.)]d<"x=y"))(2"y;m=ord(raw_input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"371>;++[ d( d)(y.)]d<"x=y"))(dy )#y@r,r,r-{ +.r_}r{ +.r_}!!-.(3"y;m=ord(input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"367>;++[ d( d)(y.)]d<"x=y"))(2"y;m=ord(raw_input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"371>;++[ d( d)(y.)]d<"x=y"))(dy )';m=ord(raw_input()[-1]);_='x=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))';print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))

Try it online!
Python 3
x='@##y@r,r,r-{ +.r_}r{ +.r_}!!-.(3"y;m=ord(input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"367>;++[ d( d)(y.)]d<"x=y"))(2"y;m=ord(raw_input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"371>;++[ d( d)(y.)]d<"x=y"))(dy )#y@r,r,r-{ +.r_}r{ +.r_}!!-.(3"y;m=ord(input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"367>;++[ d( d)(y.)]d<"x=y"))(2"y;m=ord(raw_input()[-1]);_=yx=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))y;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))"371>;++[ d( d)(y.)]d<"x=y"))(dy )';m=ord(input()[-1]);_='x=%r;m=ord(input()[-1]);_=%r;print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%%(x,_) if m==50 else _%%(x,_) if m==51 else x.replace(chr(121),chr(39)))';print(_.replace(chr(100)+chr(40),chr(100)+chr(40)+chr(114)+chr(97)+chr(119)+chr(95))%(x,_) if m==50 else _%(x,_) if m==51 else x.replace(chr(121),chr(39)))

Try it online!
Explanation:
For each language, I took already written quines and modified them a bit.
Turtlèd first:
Turtlèd includes the standard quine structure. however, should the input end with a 2 or a 3, it appends the end of the python code, either 2 or 3, it includes them both separately, to the quine output, and then goes back to the start and adds x='. Otherwise the sourcecode is left and output like a regular quine
Also note it takes input twice !!., because the source contains a newline which feeds to input an empty line.
however, along the way to the start of string, in order to avoid the fact that the string cannot have ' in it, it changes all the ' in the main source along the way to y. if it did, quote escaping could be annoying, if even possible
this relies on a trick; I could not have written (''y), (pseudocode:if cell is ', write y), because then that y would have been indistinguishable from a '. so, I use the y from the input "Python"! this was a real eureka moment for me.
then, there are the python quinelike things.
How the python quinelike thing works:
it works like a regular quine, except it also includes the variable x
if it has input Python 3, it works like a regular quine, and uses % formatting to also include the source for Turtlèd.
if it has input Python 2, it replaces input in the string with raw_input, and does otherwise the exact same thing.
if input is Turtlèd, it replaces the ys in the Turtlèd source and prints it.
The two python programs function the same, and take input the same way

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/2.5/

sort: votes


text:
Project Euler Problem 12: optimize memory usage
I am referring to Project Euler #12. Write the solution in any language you want, but consume the least amount of memory while executing. Running time is not measure in this case.

The sequence of triangle numbers is
  generated by adding the natural
  numbers. So the 7th triangle number
  would be 1 + 2 + 3 + 4 + 5 + 6 + 7 =
  28. The first ten terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55,
  ...
Let us list the factors of the first
  seven triangle numbers:
1: 1  3: 1,3  6: 1,2,3,6 10: 1,2,5,10
  15: 1,3,5,15 21: 1,3,7,21 28:
  1,2,4,7,14,28 We can see that 28 is
  the first triangle number to have over
  five divisors.
What is the value of the first
  triangle number to have over five
  hundred divisors?

No hardcoding of values/results. Honour system here folks :)

You should probably make the input variable or find another to exclude solutions which just hard-codes the result.

The 1min rule still applies?

@Joey: Project Euler doesn't need to since it isn't a code competition. We do. Yes, there's nothing on Project Euler preventing me from first creating a program which calculates the result and then creating another program with the result hard coding. But since I only send in the solution, not the code, I have no reason to do that. Here OTOH the first person to hardcode the result would be trivially the winner, rendering the competition pointless. Thus such solutions should be made impossible.

@Joey: It's also common sense that it's wrong to murder people. That doesn't mean that there's no need to put that notion into law. The edit was made in response to my comment if it had been there before, I wouldn't have posted my comment.

Use the "quoting" tool instead of the block code tool for quotes, it puts > before every line of the quote.

How are you counting memory? Number of registers used?

No time limit? Here is a solution that uses 0 bytes: while 1:pass. When it finishes it prints the answer on the screen.

I was hoping for a regular shortest code golf and if it would have been I would have posted require'prime';i=500;n=s*(s+1)/2;i=s+1;while(n.prime_division.transpose[1].map{|n|n+1}.reduce(&:*)<s);n+=i; i+=1;end;n #Ruby Euler #12 but since it isn't I can't do that.

MIPS32 Assembly.  Uses 8 bytes of memory (4 for format string, 4 for saving a pointer), everything else stays in registers.  This should work in x86-64, too, but ia32 will probably require some temporary values to be stored in memory.
    .text
    .globl main
main:
    xor $t0, $t0, $t0
    xor $t1, $t1, $t1
loop1:
    addiu $t0, $t0, 1
    addu $t1, $t1, $t0
    addiu $t3, $zero, 1
    addiu $t5, $zero, 2
    srl $t6, $t1, 1
loop2:
    slt $t4, $t6, $t5
    bne $t4, $zero, loop2end
    div $t1, $t5
    mfhi $t4
    bne $t4, $zero, non_divisor
    addiu $t3, $t3, 1
non_divisor:
    addiu $t5, $t5, 1
    j loop2
loop2end:
    slti $t4, $t3, 501
    bne $t4, $zero, loop1
    la $a0, str
    addu $a1, $t1, $zero
    addiu $sp, $sp, -4
    sw $ra, 0($sp)
    jal _printf
    lw $ra, 0($sp)
    addiu $sp, $sp, 4
    jr $ra
    .data
str:
    .asciiz "%d\n"

With no running time measure, but counting memory usage, the "naive" method of finding divisors is the way to go.
int i = 1;
int n = 1;
while(true)
{
    n += ++i; //get next triangle number
    int nd = 1;
    for(int d = 1; d <= n/2; d++)
        if(n % d == 0)
            nd++;
    if(nd > 500) break;
}
printf("Result: %d", n);

Uses four locals + any compiler temporaries, no recursion or heap memory.

you can compute n everywhere it is needed using n=(i+1)*i/2. Substituting in the two places where n is used will save the extra variable

x86 assembly (32-bit), 1 byte
Try it online!
A whole program that runs on Linux with 32-bit or 64-bit x86 CPU. It uses exactly 1 byte of stack memory (by dec esp) as the output buffer for a single character.
The other entries calling printf are actually using quite a lot of memory depending on the buffer size of the C output stream.
The code was a lot simpler, initially, as a direct port of @Anon.'s brute force approach. However, since that version took about 2 minutes to complete, I did a bit of optimizations to make it run within 25 seconds in TIO.
    movd xmm0, esp
    mov esi, 1
    mov edi, esi
    jmp L0
    .balign 16
L0:
    inc esi
    add edi, esi
    test edi, 1
    jnz L0
    tzcnt ecx, edi
    mov ebx, edi
    shr ebx, cl
    inc ecx
    mov ebp, 3
    mov esp, 2
    jmp L1e
    .balign 16
L1:
    mov eax, ebx
    xor edx, edx
    div ebp
    cmp edx, 1
    adc esp, 0
    add ebp, 2
L1e:
    mov eax, ebx
    mov edx, 2863311531
    mul edx
    shr edx, 1
    cmp edx, ebp
    jae L1
    imul esp, ecx
    cmp esp, 500
    jbe L0
    mov esi, 1
    mov eax, edi
    mov ebp, 3435973837
    jmp L2e
    .balign 16
L2:
    imul esi, esi, 10
L2e:
    mul ebp
    shr edx, 3
    mov eax, edx
    jnz L2
    movd esp, xmm0
    dec esp
    jmp L3
    .balign 16
L3:
    mov eax, edi
    xor edx, edx
    div esi
    mov edi, edx
    add eax, '0'
    mov [esp], al
    mov eax, 4
    mov ebx, 1
    mov ecx, esp
    mov edx, ebx
    int 0x80
    mov eax, esi
    mul ebp
    shr edx, 3
    mov esi, edx
    jnz L3
    mov eax, 1
    int 0x80

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/