New answers tagged math
0
votes
I reverse the source code, you negate the input!
Knight, 5 bytes
O P~O
Try It Online!
Try It Online reversed!
0
votes
1
vote
2
votes
I reverse the source code, you negate the input!
sed, 14 bytes
#//--/s;/-/^/s
The code is only comment, which means the input is outputted unchanged.
Attempt This Online!
Reversed:
...
2
votes
I reverse the source code, you negate the input!
Alice, 11 bytes
\ X'@
/I-O/
Try it online!
!enilno ti yrT
Operates entirely within ordinal mode. The negation is done by taking string symmetric difference ...
2
votes
I reverse the source code, you negate the input!
Alice, 15 bytes
/O\ /I@
@I/R\O/
Try it online!
!enilno ti yrT
Flattened
Original I O@, reads from the input, output
Reversed <...
0
votes
1
vote
Are they collinear?
Vyxal, 4 bytes
v-ÞḊ
Try it Online!
Outputs 0 for truthy and any other integer for falsy. Port of fireflame241's Jelly answer. ...
0
votes
1
vote
1
vote
How many steps does it take from n to 1 by subtracting the greatest divisor?
dc, 39 bytes
0[1+rd[d3R1-d_4R%0<t]dstxr-d_3R1<l]dslx
Try it online!
Takes input as number on top of stack, and leaves result as top of stack
1
vote
Cartesian - polar conversion couple
R, 30+24=54 bytes
Cartesian to polar, 30 bytes
\(x,y)c(Mod(z<-x+1i*y),Arg(z))
Attempt This Online!
No imaginary numbers for +2:
...
2
votes
Cartesian - polar conversion couple
x86 64-bit machine code, 23 + 13 = 36 bytes
D9 06 D9 07 D9 F3 D9 07 D8 C8 D9 06 D8 C8 DE C1 D9 FA D9 1E D9 1F C3
D9 07 D9 FB D8 0E D9 1F D8 0E D9 1E C3
Try it ...
1
vote
Anti-divisors of a number
x86 64-bit machine code, 26 bytes
89 F1 51 8D 44 71 01 99 01 C9 F7 F1 58 83 FA 02 77 01 AB 91 E2 EC FF 4F FC C3
Try it online!
Takes \$n\$ in ESI and writes the ...
2
votes
Cartesian - polar conversion couple
05AB1E (legacy), 7 + 22 = 29 bytes
Polar to Cartesian (7 bytes):
.¾¹.½‚*
Loose inputs in the order \$\phi,r\$; outputs as a pair \$[x,y]\$.
Try it online or verify ...
1
vote
1
vote
Divisor reduction
Vyxal l, 5 bytes
≬KL-İ
Try it Online!
Flagless:
Vyxal, 6 bytes
≬KL-İL
Try it Online!
3
votes
Cartesian - polar conversion couple
Factor, 16 + 15 = 31 bytes
[ rect> >polar ]
Try it online!
[ cis * >rect ]
Try it online!
...
1
vote
Cartesian - polar conversion couple
PARI/GP, 34 + 24 = 58 bytes
f(x,y)=[abs(z=x+I*y),if(z,arg(z))]
g(r,a)=r*[cos(a),sin(a)]
Attempt This Online!
8
votes
Cartesian - polar conversion couple
Python, 49 + 48 = 97 bytes
-2 thanks to @Seb
lambda r,a,n=9e9:((x:=r*(a/n-1j)**n).real,x.imag)
Attempt This Online!
lambda x,y,n=1e-9:(abs(c:=x+1j*y),(c**n).imag/n)
Doesn't use any libraries, no exp, ...
0
votes
Find a Fixed Point
J, 3 bytes
^:_
Try it online!
When a conjunction in J is missing an operand, it becomes an adjective. This program produces an adjective which takes as an argument ...
1
vote
Cartesian - polar conversion couple
SageMath, 69 68 bytes
lambda x,y:((x^2+y^2)^.5,arctan2(y,x))
lambda r,t:(r*cos(t),r*sin(t))
Try it online!
Adjusted score correctly thanks to Steffan.
Saved a ...
0
votes
1
vote
Find a Fixed Point
dc, 30 bytes
[pq][Smrd3Rd3Rxd3R=mLmlmx]dsmx
Try it online!
Takes as input the function in the form of a macro and initial value on the stack(pushed in that order). ...
2
votes
Cartesian - polar conversion couple
MATLAB/Octave, 9+9=18 bytes, builtins
Simple builtins, convert between (x,y) and (angle[radians],radius)
Cartesian to polar:
@cart2pol
Try it online!
Polar to ...
3
votes
Cartesian - polar conversion couple
J 10 (5 + 5)
to polar, 5 bytes
*.@j.
Try it online!
to cartesian, 5 bytes
+.@r.
Try it online!
Both of these amount to one ...
1
vote
Cartesian - polar conversion couple
lin, 28 + 17 = 45 bytes
To Polar ([a b] -> [a b]):
"2^.$_ +.5^"".$_.~ atant", Q
To Cartesian (...
5
votes
Cartesian - polar conversion couple
Wolfram Language (Mathematica), 14+11=25 bytes
AbsArg[#+I#2]&
AngleVector
Try it online!
Input [x,y]/...
2
votes
Cartesian - polar conversion couple
Python, 48+48 = 96 bytes
lambda*t:(hypot(*t),atan2(*t))
from math import*
Attempt This Online!
-4 bytes thanks to xnor.
lambda a,b:(a*cos(b),a*sin(b))
from math import*
Attempt This Online!
1
vote
Cartesian - polar conversion couple
C (gcc), 88 bytes
C(x,b,t)float*x,t;{t=x[1];x[1]=b?*x*sin(t):atan(t/(*x));*x=b?*x*cos(t):sqrt(*x**x+t*t);}
86 bytes
2 bytes can be saved by inverting the order of ...
2
votes
Cartesian - polar conversion couple
APL (Dyalog Classic), 22 + 15 = 37 bytes
Cartesian to Polar: 22 bytes
{(.5*⍨+/⍵⍺*2),¯3○⍵÷⍺}
Polar to Cartesian: 15 bytes
...
3
votes
Cartesian - polar conversion couple
Jelly, 7 + 6 bytes = 13
Polar to Cartesian:
×ıÆeׯi
A dyadic Link accepting \$\theta\$ on the left and \$r\$ on the right that yields a list \$[x, y]\$.
Try it ...
1
vote
Cartesian - polar conversion couple
Vyxal, 10 + 7 = 17 bytes
Cartesian to Polar, 10 bytes
²∑√?Ṙƒ/∆T"
Try it Online!
Polar to Cartesian, 7 bytes
⁰₍∆c∆s*
Try ...
4
votes
Cartesian - polar conversion couple
Pip -p, 10 + 12 = 22 bytes
Polar to Cartesian:
a*[CObSIb]
Takes angle in radians. Outputs a list containing x and y. Try it ...
4
votes
Cartesian - polar conversion couple
Mathematica, 18+20 = 38 bytes
ToPolarCoordinates
FromPolarCoordinates
Try it online!
For the ...
4
votes
Cartesian - polar conversion couple
Desmos, 33+19 = 52 score
Both functions take in two arguments representing either polar or Cartesian coordinates (depending on which function is being used), and returns a list representing the ...
1
vote
Anti-divisors of a number
Perl 5 -n, 35 bytes
//;map{abs($'%$_*2-$_)<2&&say}2..$_
Try it online!
Uses a take on xnor's formula in his python ...
1
vote
Output the nth Even Perfect Number
Haskell, 52 bytes
([n|n<-[1..],n==sum[d|d<-[1..div n 2],mod n d<1]]!!)
Try it online!
Starts at n = 0. Not particularly fast
1
vote
Anti-divisors of a number
lin, 33 bytes
.#n.n.<1drop".n.+_ %.~2/ -2^1<".#
Try it here!
For testing purposes (use -i flag when running ...
1
vote
Anti-divisors of a number
Haskell, 38 bytes
h n=[m|m<-[2..n-1],abs(mod n m*2-m)<2]
Try it online!
0
votes
What is the average of n, the closest prime to n, the square of n and the closest Fibonacci number to n?
Haskell, 150 bytes
...
4
votes
Anti-divisors of a number
APL (Dyalog Classic), 23 bytes
{1↓⍵{(2>|⍵-2×⍵|⍺)/⍵}⍳⍵}
Try it online!
Usage:
...
1
vote
Anti-divisors of a number
Charcoal, 16 bytes
NθIΦ…²θ‹↔⁻⊗﹪θιι²
Try it online! Link is to verbose version of code. Explanation:
...
1
vote
Anti-divisors of a number
C (gcc), 58 52 bytes
m;f(n){for(m=1;++m<n;)(n%m*2-m)/2||printf("%d ",m);}
Try it online!
Saved 6 bytes thanks to the suggestion of porting Kevin's ...
2
votes
Anti-divisors of a number
Java 8, 69 64 bytes
n->{for(int i=1;++i<n;)if((n%i*2-i)/2==0)System.out.println(i);}
-5 bytes thanks to @Deadcode
Outputs the results to STDOUT on separated ...
1
vote
3
votes
Anti-divisors of a number
05AB1E, 8 bytes
L¦ʒ%·yα!
Try it online or verify all test cases.
Explanation:
...
3
votes
Anti-divisors of a number
Desmos, 40 bytes
l=[1...n][2...]
f(n)=l[-2<2mod(n,l)-l<2]
Try It On Desmos!
Try It On Desmos! - Prettified
5
votes
Anti-divisors of a number
Knight, 40 34 bytes
-6 bytes thanks to @Bubbler by looping backwards
;=i=pE P W<1=i-iT&>4^-*2%p i i 2Oi
Try It Online!
Outputs each anti-divisor in a ...
3
votes
Delannoy numbers
K (ngn/k), 18 bytes
{0/x(+':+\)/1,y#1}
Try it online!
Port of my APL answer that does not use the binomial coefficient built-in. See the linked answer for the ...
Top 50 recent answers are included
Related Tags
math × 1652code-golf × 1488
number × 282
sequence × 209
arithmetic × 180
number-theory × 162
geometry × 108
integer × 87
primes × 85
combinatorics × 82
decision-problem × 79
code-challenge × 74
array × 66
matrix × 62
string × 55
polynomials × 51
rational-numbers × 48
fastest-code × 44
abstract-algebra × 38
ascii-art × 36
base-conversion × 34
linear-algebra × 31
restricted-source × 28
open-ended-function × 28
fibonacci × 27