New answers tagged arithmetic
0
votes
Addition/Multiplication table generator
Vyxal, 18 bytes
ɾ?\vdpĖ:vvS$fGL↲Ṡ⁋
Try it Online!
Without strict IO formats, the whole :vvS$fGL↲Ṡ⁋ could be omitted
1
vote
1, 2, Fizz, 4, Buzz
D, 90 bytes
import std;void main(){foreach(i;1..101)max("FizzBuzz"[i%3?4:0..i%5?4:8],i.text).writeln;}
Try it online!
1
vote
The vanilla factorial challenge
Regex 🐇 (RME / PCRE2 v10.35+), 12 bytes
^((?*x+)x)*$
Attempt This Online! - PCRE2
Try it on replit.com! - RegexMathEngine, in ...
1
vote
The vanilla factorial challenge
Carbon, 53 bytes
fn f(x:i32)->i32{return if(x==0)then 1else x*f(x-1);}
Try it Online!
Here is a full program for testing at the above site:
...
1
vote
The vanilla factorial challenge
StackCell, 14 bytes
Uses this input format and this output format
The below code uses the Unicode control character glyphs [U+24XX] to represent ASCII unprintable control characters embedded in the ...
1
vote
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 ...
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 ...
0
votes
Iterated partial sums
PARI/GP, 31 bytes
f(a,n)=Vec(Ser(a)/(1-x)^n+.5)\1
Attempt This Online!
Converts the list to a power series, divides it by \$(1-x)^n\$, and then converts it back to ...
1
vote
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, ...
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 ...
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 ...
0
votes
The plus-minus sequence
C (gcc), 62 bytes
int f(int a,int b){for(;1;b=(a+=b)-2*b)printf("%d %d\n",a,b);}
Try it online!
Theoretically outputs indefinitely, however, it only ...
1
vote
Cryptic Multiplications
Charcoal, 36 bytes
FXχLθFEXχLη⪫⟦ικ×ικ⟧¶⊞υEκ⌕κλI№υ§υI⁺θη
Try it online! Link is to verbose version of code. Explanation:
FXχLθ
...
3
votes
Cryptic Multiplications
05AB1E, 20 bytes
€g°Ý`âIšεDPª»DSk»}ć¢
Port of @Steffan's Vyxal answer, but with less convenient builtins.
Try it online or verify (almost) all test cases (the last ...
1
vote
Cryptic Multiplications
Ruby, 108 bytes
->a,b{[*0..9].permutation.map{|c|"#{a}*#{b}==#{a*b}".tr('0-9',c*'')}.uniq.count{|c|/^0|\*0|=0/!~c&&eval(c)}}
Try it online!
4
votes
4
votes
Cryptic Multiplications
Vyxal s, 17 bytes
vL↵ʀΠƛ?"ƛΠJṄ:vḟ;≈
Try it Online!
This would flaglessly be 19 bytes. It can be shorter flagless, though:
...
3
votes
Cryptic Multiplications
Jelly, 20 18 17 bytes
Thanks to Steffan for a speed up! (‘×⁵ -> æċ⁵) and a byte that ended up saving elsewhere!
Save of 2 ...
7
votes
Cryptic Multiplications
K (ngn/k), 41 36 bytes
-5 bytes inspired by Jonathan Allan's answer.
{#*={.(=`k@x,*/x)_" "}'?+x,'!10*1+x}
Try it online! The last 4 cases are too slow to ...
3
votes
1
vote
Additive Persistence
Ly, 21 bytes
0s+1[pSy,![lu;]&+l`s]
Try it online!
A pretty straight forward interpretation of the challenge rules this time.
...
1
vote
Summation from a to b
Factor + math.unicode, 12 bytes
[ [a,b] Σ ]
Try it online!
Interesting tidbit: sum (and ...
1
vote
Additive Persistence
Knight, 54 bytes
;=iP;=r 0;W<1Li;=s 0;Wi;=s+sA Ai=iGi 1Li;=i+""s=r+1rOr
Try it online!
1
vote
Strange Addition
Knight, 45 bytes
;=aP;=bP Wa;O+A I>a bAaAb"\";=aGa 1La=bGb 1Lb
Try it online!
Takes two zero-padded numbers (it works with spaces as well).
1
vote
Summation from a to b
Knight, 19 bytes
O/*+E=aP=bP+1-b a 2
Try it online!
Uses the formula (a+b)*(b-a+1)/2.
0
votes
2
votes
The vanilla factorial challenge
Brachylog, 1 byte
ḟ
Try it online!
Also works with a fixed output and an unknown input, with decent performance.
No built-in, 3 bytes
...
2
votes
The vanilla factorial challenge
JavaScript, 19 bytes
f=n=>n?f(n-1n)*n:1n
2 bytes longer than the other JS answers, but can safely calculate as high as 11190! instead of 18!, with anything ...
3
votes
The vanilla factorial challenge
Knight, 25 bytes
;=x+=y 1P;W=x-x 1=y*x yOy
Try it online!
Ungolfed:
...
1
vote
1
vote
Add two numbers
Quipu, 11 bytes
\/
\/
++
/\
Attempt This Online!
Explanation
Each side-by-side pair of characters is a command ("knot"), and execution proceeds from top ...
2
votes
Add two numbers
Trianguish, 15 bytes
00000000: 1020 c301 a050 c008 b105 0c01 0710 19
Try it online!
Top 50 recent answers are included
Related Tags
arithmetic × 531code-golf × 494
math × 180
number × 144
sequence × 59
integer × 56
number-theory × 47
array × 39
string × 37
decision-problem × 18
expression-building × 16
code-challenge × 14
ascii-art × 12
restricted-source × 12
combinatorics × 12
base-conversion × 12
geometry × 11
primes × 11
matrix × 10
atomic-code-golf × 10
kolmogorov-complexity × 9
grid × 9
parsing × 9
binary × 9
game × 8