AnnouncementsMatrixEventsFunnyVideosMusicAncapsTechnologyEconomicsPrivacyGIFSCringeAnarchyFilmPicsThemesIdeas4MatrixAskMatrixHelpTop Subs
2

New code blocks. These ones have copy on click, syntax highlighting for multiple languages, and a better background.

Some sample code:

Python

from prime_decomposition import decompose
from itertools import islice, count
try: 
    from functools import reduce
except: 
    pass


def almostprime(n, k=2):
    d = decompose(n)
    try:
        terms = [next(d) for i in range(k)]
        return reduce(int.__mul__, terms, 1) == n
    except:
        return False

if __name__ == '__main__':
    for k in range(1,6):
        print('%i: %r' % (k, list(islice((n for n in count() if almostprime(n, k)), 10))))

Lua

-- Returns boolean indicating whether n is k-almost prime
function almostPrime (n, k)
    local divisor, count = 2, 0
    while count < k + 1 and n ~= 1 do
        if n % divisor == 0 then
            n = n / divisor
            count = count + 1
        else
            divisor = divisor + 1
        end
    end
    return count == k
end

Erlang

-module(factors).                                         
-export([factors/1,kfactors/0,kfactors/2]).               
                                                          
factors(N) ->                                             
     factors(N,2,[]).                                     
                                                          
factors(1,_,Acc) -> Acc;                                  
factors(N,K,Acc) when N rem K == 0 ->                     
    factors(N div K,K, [K|Acc]);                          
factors(N,K,Acc) ->                                       
    factors(N,K+1,Acc).                                   
                                                          
kfactors() -> kfactors(10,5,1,1,[]).                      
kfactors(N,K) -> kfactors(N,K,1,1,[]).                    
kfactors(_Tn,Tk,_N,K,_Acc) when K == Tk+1 ->  io:fwrite("Done! ");            
kfactors(Tn,Tk,N,K,Acc) when length(Acc) == Tn  ->        
    io:format("K: ~w ~w ~n", [K, Acc]),                   
    kfactors(Tn,Tk,2,K+1,[]);                             
                     
kfactors(Tn,Tk,N,K,Acc) ->                                
    case length(factors(N)) of K ->                       
     kfactors(Tn,Tk, N+1,K, Acc ++ [ N ] );               
      _ ->                                                
      kfactors(Tn,Tk, N+1,K, Acc) end.

Uiua apparently not supported, faggots

[123 12345 1234567 987654321 10001 ¯10001 ¯123 ¯100 100 ¯12345
 1 2 ¯1 ¯10 2002 ¯2002 0]
Mid ← (
  ⍤("too short")≥3.⧻.°□°⋕⌵
  ⍤("even length")≠0◿2.
  ↘¯⟜↘⌊÷2-3
)
⍉⊟⟜≡⍚⍣(Mid|⊂"Error: "◌) # Convert each
≡(&p$"_\t->\t_"°⊟)      # Display

Julia

using Printf

function middle3(n::Integer)
    l = ndigits(n)
    iseven(l) && error("n must have an odd number of digits")
    l < 3 && error("n must have 3 digits or more")
    mid = (l + 1) ÷ 2
    abs(n) ÷ 10^(mid-2) % 10^3
end

for n = [123, 12345, 1234567, 987654321, 10001, -10001, -123,
         -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0]
    @printf("%10d -> %s\n", n, try middle3(n) catch e e.msg end)
end

Voat's favorite jq

def middle3:
  if . <  0 then -. else . end
  | tostring as $s
  | ($s | length) as $n
  | if $n<3 or ($n % 2) == 0 then "invalid length: \($n)"
    else (($n - 1) / 2) as $n |  $s[$n - 1 : $n + 2]
    end ;

(123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0)
  | "\(.) => \( .|middle3 )"

javascript

async function* targetDivs() {
  let found = new Set();
  while(true) {
   let divs = document.querySelectorAll('#prompt-textarea');
   for(let div of divs) {
    if(!found.has(div)) {
     found.add(div);
     yield div;
    }
   }
   await timeout(500);
  }
 }
Comment preview
[-]x0x7
0(+0|0)
p { color: red }