New answers tagged

-1

Keg, 9 bytes ¿(:;|:)∑* Try it online! I said I'd count Keg's victories over 1+ as victories for mawp, so it's 2-1 to mawp!


0

x87 machine code, 27 bytes Binary: 00000000: 9bd9 2e19 01d9 e8df 2cd9 f19b dfe0 a804 ........,....... 00000010: 7404 d9e8 d9e0 df1c c37f 0f t.......... Listing: 9B D9 2E 013F FLDCW CW ; set FPU CW register for floor rounding D9 E8 FLD1 ; 1 * multplier into ST(1) DF 2C FILD QWORD PTR[SI] ; load ...


1

Java (JDK), 43+1 bytes s->{int i=0,t=s;for(;++i<s;t*=s);return t;} Try it online! Overflows for 10, so all ints need to be changed to long a the cost of +1. This has been done for the TIO link. I didn't think I could beat the IntStream though!


1

Google Sheets, 24 Input A1. =DECIMAL(1&REPT(0,A1),A1 Is base conversion ok? If not, here's one at 26 (but it's really boring): =PRODUCT(SEQUENCE(A1,1,A1,


0

Perl 5 + -p, 17 bytes $_=eval"$_*"x$_.1 Try it online!


2

Rust, 37 bytes |x|(|mut y|{for _ in 1..x{y*=x}y})(x) Try it online This might be able to be shortened once bindings_after_at stabilizes by using |mut y@x| instead.


2

x86-16 machine code, 27 25 bytes Binary: 00000000: 33db 4a51 56ac a20c 018a c2d4 0ae0 f675 3.JQV..........u 00000010: 0203 da5e 594a 75eb c3 ...^YJu.. Listing: 33 DB XOR BX, BX ; clear BX running sum 4A DEC DX ; N = N - 1 (only multiples below N) N_LOOP: 51 PUSH CX ...


0

Arn, 15 bytes pIÔX╗▀‹·¬○¯vËa? Explained Unpacked: +\$v{$:{!v%}?1}1-> \ Fold with... + ...addition $ Filter with... v{ ...block with key of v $: Any operation { Block with key of _ ! Boolean not v% v modulo _ (implied) } ?1 Each element on second line of _ (implied) } ...


2

Arn, 8 bytes xõPÑ_=>$ Explained Unpacked: *v{_}\1=> \ Fold... * ...with multiplication after... v{ ...mapping with key of v... _ ...by replacing with input } End map 1 Literal one => inclusive range to... _ ...input, implied


1

Integral, 5 Bytes v↕♦▼e Try it! Explanation v↕ Multiply two items of the stack, to be evaluated ♦ Swap the top two items ▼ Decrement e Evaluate ↕ that many times


2

1+, 29 27 25 24 bytes 1."1##/"\*\1+\"/^"/<1+#: This was already shockingly short, given how messy it is to create a halting loop... I did a poor job on stack manipulation, so it can probably be improved. Special notes on 25 -> 24 Remember that you're programming in brainfuck. It's tempting to avoid confusion and tedium by thinking ...


1

MAWP, 40 25 22 bytes %@![~!~1A]%1A[1A~W~]%: -15 from Dion's improved input methods. -3 after modifying first loop to happen x+1 times. Try it! Explanation %@ Gets multi digit input ![~!~1A]% x gets cloned x+1 times in the stack 1A[1A~W~]%: multiplies top 2 numbers x-1 times


2

Flurry, 16 bytes <>{{}}<<>()>{}{} Run example $ ./flurry -nin -c "<>{{}}<<>()>{}{}" 4 256 $ ./flurry -nin -c "<>{{}}<<>()>{}{}" 5 3125 Multiply n n times to 1. The lambda expression is n (\x. \y. n (x y)) I where \y. n (x y) or n ∘ x is the product of Church numeral of n and x, and ...


0

Scala, 45 bytes _.to(_)map(_.toBinaryString.map(_-48)sum)sum Try it in Scastie


0

Google Sheets, 52 Closing Parens discounted. Input cells is Row 1, starting in column B. A2 - =COUNTA(1:1). Rules say that we can take this as input too, so I have discounted this as well. (Our "k") A3 - =ArrayFormula(IFERROR(0^MOD(SEQUENCE(A2-1,A2)-1,A2+1))) The output matrix starts in B1. How it works Since this is a spreadsheet, the input ...


0

Wolfram Language (Mathematica), 28 bytes Tr@DigitCount[Range@##,2,1]& Try it online!


1

Jelly, 24 bytes JṖŒPỊẸ$Ƈ,ḟ@Œp;U$ʋ€Jœị⁸§Ṃ A monadic Link accepting a list of lists of non-negative integers (an adjacency matrix), which yields the maximal flow integer. Try it online! Or see the test-suite. How? Implements the minimum-cut maximal-flow method. JṖŒPỊẸ$Ƈ,ḟ@Œp;U$ʋ€Jœị⁸§Ṃ - Link: adjacency matrix, A (n by n) J - range of ...


5

JavaScript (ES6), 96 bytes f=(m,k=1,b)=>k*2>>m.length?b:f(m,k+2,m.map((r,y)=>r.map((v,x)=>t+=k>>y&~k>>x&1&&v),t=0)|t>b?b:t) Try it online! Commented f = ( // f is a recursive function taking: m, // m[] = adjacency matrix k = 1, // k = counter, ...


3

05AB1E, 27 bytes ā2.ŒʒD{Q}<ʒZ%PË}εнèøyθè˜O}ß Takes the input in a similar format as the test cases in the challenge description. Try it online or verify all test cases. Explanation: ā # Push a list in the range [1, (implicit) input-length] # (without popping the input itself) 2.Œ # Get all partitions of two parts of this list ...


0

Rust, 38 bytes |n|print!("{:.2}",((n-31.)/16.).exp()) Try it online


7

Charcoal, 37 36 34 bytes I⌊EEX²⁻Lθ²↨⁺X²⊖Lθ⊗ι²ΣEθ∧§ιμΣΦ묧ιξ Try it online! Link is to verbose version of code. Explanation: E…X²⁻Lθ²X²⊖Lθ Loop over all cuts... E ↨⊗ι² ... converted to base 2 ΣEθ∧§ιμ Sum rows in source cut ΣΦ묧ιξ Sum columns in sink ...


1

MathGolf, 19 bytes T-☻/e▬♪*i♂‼/%5≥+♀∩* If only MathGolf had a round builtin.. :/ 6 bytes are used for the actual formula, 13 for rounding to 2 decimals, haha. I/O both as a float. Try it online. Explanation: T- # Subtract 31 from the (implicit) input-float # i.e. 50.0 → 19.0 ☻/ # Divide it by 16 # → 1....


1

05AB1E, 7 bytes āDδQ`\) Outputs reversed in both dimensions. Try it online or verify all test cases. Explanation: ā # Push a list in the range [1,length] (without popping the implicit input-list) D # Duplicate it δ # Apply double-vectorized: Q # Check if it's equal # (this results in an L by L matrix filled with 0s, ...


2

Integral, 14 11 Bytes My first Integral answer! x▼◄w‼5*↕u*‼ Try it! An alternative: ▲w‼!◄5*↕u*‼ (11 bytes) Explanation x Push 32 ▼ x-1 ◄ Subtraction w Push 16 ‼ Divide 5 e ^ a * 100 ↕ Multiplicaiton u Round to the closest integer * ...


0

Scala, 45 bytes (n,s)=>0 to n-1 filter(x=>s.exists(x%_<1))sum Try it in Scastie Takes as its input an Int n and a List[Int] s, creates a range from 0 to n, filters every number in that range that's divisible by an element in s, and sums it. Requires language:postfixOps.


0

Charcoal, 20 bytes ﹪%.2fX¹·⁰⁶⁴⁴⁹⁴⁴⁵⁻N³¹ Try it online! Link is to verbose version of code. Numeric constant stolen from @JonathanAllen. Explanation: N Input as a number ⁻ ³¹ Subtract literal 31 X¹·⁰⁶⁴⁴⁹⁴⁴⁵ Raise literal 1.06449445 to that power ﹪%.2f Format using literal format string `%....


0

Japt, 12 11 bytes -1 byte thanks to @Shaggy Me°U/G-2 x2 Try it Explanation Me°U/G-2 x2 Me // exp( °U // (U + 1) /G-2 // / 16 - 2 // ) x2 // round to 2 decimal digits


0

bc, 40 bytes scale=2 define f(n){return e((n-31)/16)} Try it online!


1

R, 28 bytes round(exp((scan()-31)/16),2) Try it online! There seems to be some controversy about whether trailing zeros must be printed. If so, the following 35 byte solution works: sprintf("%.2f",exp((scan()-31)/16))


1

Jelly, 10 bytes _31÷⁴Æeær2 A monadic Link accepting a float which yields a float. (As a full program a decimal input causes the result to be printed.) Try it online! How? _31÷⁴Æeær2 - Link: float, n 31 - 31 _ - subtract -> n-31 ⁴ - 16 ÷ - divide -> (n-31)/16 Æe - exp(x) -> exp((...


1

cQuents, 24 bytes :b$)/100 :R100*x_+$/16-2 Try it online! For some reason, rounding works on the whole line. I would do /100/R100*, but floats went all 9y on me.


0

Python 3, 52 36 35 bytes Saved a whopping 16 17 bytes thanks to Jonathan Allan!!! lambda n:round(1.0644944**(n-31),2) Try it online!


5

05AB1E, 12 bytes -1 thanks to @mypronounismonicareinstate >16/Ížrsm2.ò Try it online! Explanation > Increment 16/ Divide by 16 Í -2 žr Push Euler's constant s Swap operands m Exponentiation 2.ò Round to 2 decimal places


2

APL+WIN, 13 bytes Prompts for input of n: ⍎2⍕*(⎕-31)÷16 Try it online! Courtesy of Dyalog Classic


3

Io, 114 bytes While you all are enjoying rounding built-ins in your language, Io doesn't have any of those convenient rounding built-ins... method(x,I :=((((x-31)/16)exp*100)round asString);I=if(I size<3,"0","").. I;I asMutable atInsertSeq(I size-2,".")) Try it online!


4

Perl 5, 36 31 bytes printf"%.2f",1.0644944**($_-31) Try it online! Command line one-liner examples: echo 52 | perl -ne 'printf"%.2f\n",2.71828**(($_-31)/16)' echo 52 | perl -ne 'printf"%.2f\n",1.06449445**($_-31)' echo 52 | perl -ne 'printf"%.2f",1.06449445**($_-31)' echo 52 | perl -ne 'printf"%.2f",1....


1

C (gcc), 35 44 38 36 bytes Saved a byte thanks to my pronoun is monicareinstate!!! Saved 2 bytes thanks to Arnauld!!! Added 10 bytes to fix a bug kindly pointed out by Kjetil S. f(n){printf("%.2f",exp(-~n/16.-2));} Try it online!


1

JavaScript (V8), 33 32 bytes a=>Math.exp(-~a/16-2).toFixed(2) Try it online! Thanks to @my pronoun is monicareinstate for -1 byte


0

Prolog, 44 bytes r(X,N,D):-A is N/D,A==1,X is D;r(X,N/D,D+1). The third argument has to be 1 the first time (e.g. r(X,24,1)) If N equals D, sets X to D, otherwise, it calls itself with N/D and D+1. I originally meant to write something like the following, but it never stopped. r(X,N,N):-X is N. r(X,N,D):-r(X,N/D,D+1). Try it online on SWISH (I don't know ...


0

Scala, 67 bytes For those who like to live dangerously and assume things beyond a method's contract... Seq(io.StdIn.readLine split ":"map(_.toInt)reduce(_*60+_),6000)min reduce is not guaranteed to work from left to right, but it seems to do so by default. Try it in Scastie


1

Rust, 82 bytes |s:&str|6000.min(60*s[..2].parse::<u32>().unwrap()+s[3..].parse::<u32>().unwrap()) Try it online! Unfortunately type inference for parse is very restricted and the turbofish must be used every time. I also made some versions using fold instead of parse, but they are longer: With a tuple accumulator and a closure to combine ...


1

Rust, 41 32 bytes |mut y|(1..).find(|x|{y/=x;y<2}) Try it online! The .unwrap() was unnecessary (Meta post), saving 9 bytes


0

C (gcc), 3 tiebreakers I take no credit for this, as this is not an original answer, but merely an amalgamation of the following answers to this same challenge: https://codegolf.stackexchange.com/a/5701/97511, https://codegolf.stackexchange.com/a/4613/97511 #include <stdio.h> #define OP ( #define CP ) #define CO , int main OP ac CO av CP int ac; ...


2

Python 2, 46 bytes lambda l,k:[l]+zip(*[iter(([1]+[0]*k)*~-k)]*k) Try it online! Takes input as a tuple l and number of terms k, and outputs with both rows and columns reversed. The idea is to use the zip/iter trick to create an identity-like matrix by splitting a repeating list into chunks. The is similar to my solution to construct the identity matrix ...


0

Lua, 46 bytes print(load'return io.read"n"\x2Bio.read"n"'()) Try it online! How It Works load loads a string and returns a function, we pass a hexadecimal to it and call the function.


0

C (gcc), 77 bytes *s;f(){for(s=L"pp!'JO~S<kx`[zQ]g kf YVDp ";*s;)printf("%d",*s++-' ');} Assumes that wchar_t and int have the same size. This way we can make the string wide and we can omit the type when declaring s. A naive approach: group the digits in blocks of 1–3, each of which is an integer between 0 and 127 with no ...


1

R, 34 bytes function(r,k)rbind(diag(k)[-1,],r) Try it online! Takes the length as well; the TIO link has a k=length(r) argument so you can just input the recurrence relation.


2

APL (Dyalog Unicode), 10 bytes ⊢⍪¯1↓⍋∘.=⍋ Try it online! Tacit function taking the list of coefficients on the right. Explanation ⊢⍪¯1↓⍋∘.=⍋ ⍋ ⍋ ⍝ Grade up to obtain a list of k distinct values ∘.= ⍝ Outer product with operation `equals` (identity matrix) ¯1↓ ⍝ Drop the last row ⊢⍪ ⍝ Prepend the list of coefficients


2

Google Sheets, 141 140 134 132 90 Closing parens already discounted. Phew! That was more work than I bargained for. The hard part was getting something that worked for all ranges. Inputs: A1 - N Row 2 - A1, A2, ... Formulae: A3 - =A1-1 (N - 1) A4 - =SUM(ArrayFormula(SEQUENCE(A3)*LT(,COUNTIF(MMULT(SEQUENCE(A1),FILTER(2:2,2:2)),SEQUENCE(A3))))) Where A4 is ...


2

Io, 56 bytes method(a,a map(i,v,if(i<1,a,a map(I,v,if(I==i-1,1,0))))) Try it online! Explanation method(a, ) // Input an array. a map(i,v, ) // Map. i = index, v = value if(i<1, ) // If the indice is 0, ...


Top 50 recent answers are included