New answers tagged

1 vote

80% of respondents agreed…

R, 53 bytes f=\(n,x=1)`if`(all(abs(n-100*(1:x)/x)>.5),f(n,x+1),x) Try it online!
Evargalo's user avatar
  • 313
2 votes

The vanilla factorial challenge

Vyxal 3L, 2 bytes /* Try it Online! Fold / the input by multiplication *. Fold treats whole ...
noodle man's user avatar
  • 5,497
3 votes

80% of respondents agreed…

Python 3, 85 72 bytes -13 bytes since I saw answers to other questions use a function lambda x:[a for a in range(68)for b in range(a)if abs(x-100*b/a)<=.5][0] ...
guest4308's user avatar
  • 179
5 votes

80% of respondents agreed…

C (gcc), 56 bytes i;j;f(n){for(i=j=1;fabs(100.*j/i-n)>.5;j=--j?:++i);j=i;} Try it online!
Noodle9's user avatar
  • 20k
4 votes

80% of respondents agreed…

APL+WIN, 35 bytes Prompts for input: ⌊/(⎕=(⌈n-.5),⌊.5+n←100×÷m)/m,m←⍳100 Try it online! Thanks to Dyalog Classic
Graham's user avatar
  • 5,506
4 votes

80% of respondents agreed…

Vyxal 3, 14 bytes ₅Dᵒ÷×ṚTȧd1≤ᶤaꜝ Try it Online! Takes an integer argument and returns an integer argument. This is a Vyxal 3 translation of @JonathanAllan’s Jelly ...
Nick Kennedy's user avatar
  • 19.1k
1 vote

Shift right by half a bit

JavaScript (Node.js), 31 bytes n=>(g=i=>i*i*2<n*n?g(++i):i)(0) Try it online! or BigInt version, anyway really large values impractical to run Brute-...
l4m2's user avatar
  • 20.7k
1 vote

Shift right by half a bit

Python 3.8 (pre-release), 40 bytes This one works with python integers, giving the correct result even for arbitrarily large integers. Always rounds down. ...
Stef's user avatar
  • 699
7 votes

80% of respondents agreed…

Jelly,  14  12 bytes -2 thanks to Nick Kennedy! (Make a 100 by 100 table with values over 100% rather than a triangle of values.) ạȷ2÷þפḤỊ§TḢ A monadic Link that ...
Jonathan Allan's user avatar
3 votes

80% of respondents agreed…

05AB1E, 15 bytes ∞.ΔDÝs/т*α2zs@à Try it online! Explanation: ...
Flummox's user avatar
  • 69
2 votes

80% of respondents agreed…

Charcoal, 24 bytes NθI⌊Φφ∧ιΦφ¬‹·⁵↔⁻θ∕×λ¹⁰⁰ι Try it online! Link is to verbose version of code. Very slow as it does about 1,000 times as much work as necessary. ...
Neil's user avatar
  • 166k
3 votes

80% of respondents agreed…

05AB1E, 15 bytes ∞.ΔтLт*s/α2zs@à Try it online or verify all outputs. Explanation: ...
Kevin Cruijssen's user avatar
9 votes

80% of respondents agreed…

K (ngn/k), 27 bytes **&~`i$(199*%/:/&=69)-1.99* Try it online! Based on the formula from the OEIS entry: Find the smallest N such that there is some x >...
ovs's user avatar
  • 58.3k
5 votes

80% of respondents agreed…

JavaScript (Node.js), 45 bytes x=>g=i=>(x-i%69/(y=i>>7)*100)**2<.26?y:g(-~i) Try it online!
l4m2's user avatar
  • 20.7k
2 votes

Count without 3

Swift, 84 bytes func f(_ n:Int)->Int{var n=n+1;while String(n).contains("3")||n%3==0{n+=1};return n}
Annett Schwarze's user avatar
1 vote

Find the Factorial!

Kotlin, 46 bytes {x:Int->x.downTo(1).reduceOrNull{a,i->a*i}?:1} Bit of a shame that we need that type hint... Attempt This Online!
Ginger's user avatar
  • 5,420
2 votes

Multiplicative persistence

05AB1E, 13 bytes ,[1svy*}Ð,gΘ# Try it online! Explanation: ...
Flummox's user avatar
  • 69
1 vote

Find the Factorial!

Vyxal 3, 3 bytes Ω}Π Try it Online! -2 bytes thanks to @lyxal Explanation (outdated): ...
Fmbalbuena's user avatar
  • 3,207
1 vote

Count without 3

Google Sheets, 63 bytes =+let(n,sequence(254),filter(n,n>A1,mod(n,3),iserr(find(3,n)))) Put the input in cell A1 and the ...
doubleunary's user avatar
1 vote

Count without 3

GNU sed -E, 148 bytes Could be easier with a language with a modulo operator. Or division. Or counting. Or some idea about what numbers are. ...
Philippos's user avatar
  • 1,911
2 votes

Multiplicative persistence

Go, 87 bytes import."fmt" func f(n int){Println(n) s:=1 if n<10{return} for;n>0;n/=10{s*=n%10} f(s)} Attempt This Online!
bigyihsuan's user avatar
  • 8,618
0 votes

Additive Persistence

Go, 77 bytes func f(n int)int{s:=0 if n<10{return 0} for;n>0;n/=10{s+=n%10} return 1+f(s)} Attempt This Online!
bigyihsuan's user avatar
  • 8,618
1 vote

Multiplicative persistence

Vyxal 3, 2 bytes ᵘΠ Try it Online! 2 bytes with a new modifier. Come try Vyxal 3!
Pacmanboss256's user avatar
1 vote

Count without 3

Vyxal 3, 9 bytes э∥3c3Ḋ∵¬Ẇ Try it Online!
Pacmanboss256's user avatar
0 votes

German pharmacy payment

*><>, 90 89 bytes -1 byte by removing a semicolon that shouldn't have been there I'm still trying to condense it using the dive u and rise ...
Geoffrey H.'s user avatar
4 votes

German pharmacy payment

APL (Dyalog Unicode), 13 bytes 2⍕⊢⌊10⌊5⌈.1×⊢ Try it online! Tacit prefix function. Takes input as number. Thanks to Graham for original APL solution. How it works:...
Tbw's user avatar
  • 241
1 vote

Sum the array times n, except the last

Desmos, 32 31 bytes f(a,n)=na.total-(n-1)a[a.count] Try it on Desmos -1 byte thanks to Aiden Chow.
Yousername's user avatar
  • 3,650
2 votes

Sum the array times n, except the last

TI-BASIC, 17 bytes Input N Nsum(Ans)-(N-1)Ans(dim(Ans Takes input of \$A\$ in Ans. Alternatives that are also 17 bytes: ...
Yousername's user avatar
  • 3,650
1 vote

Sum the array times n, except the last

Uiua, 7 bytes /+⍜↘ׯ1 Try it! ...
chunes's user avatar
  • 22.8k
0 votes

German pharmacy payment

Rust, 50 bytes |x|(500f64.max(1e1*x).min(1e3).round()/1e2).min(x) Try it online!
cg909's user avatar
  • 341
-1 votes

German pharmacy payment

Desmos, 30 actually 35 bytes A one-liner Desmos equation for once (thanks to Aiden Chow for the fix and optimization): f(x)=round([x,5,10,x/10].sort[2],2) Try it ...
Infigon's user avatar
  • 561
1 vote

German pharmacy payment

Python, 41 bytes lambda x:min(max(5,(x*20+1)//2/100),x,10) Attempt This Online! Straight-forward implementation of OP's formula. For the rounding it uses floor ...
Albert.Lang's user avatar
  • 2,329
0 votes

German pharmacy payment

Scala 3, 106 100 bytes Saved 6 bytes thanks to @corvus_192 Golfed version. Attempt This Online! ...
138 Aspen's user avatar
  • 4,815
0 votes

German pharmacy payment

AWK, 48 bytes {y=$0/10;a=y>5?y>10?10:y:5>$0?$0:5;print a+1e-4} Try it online! Ungolfed : ...
Marius_Couet's user avatar
0 votes

German pharmacy payment

05AB1E, 16 (or 25) bytes T/5‚à‚Tªß4°z+2.ò Try it online or verify all test cases. This outputs 5.0 or ...
Kevin Cruijssen's user avatar
0 votes

German pharmacy payment

PARI/GP, 44 bytes x->printf("%.2f",min(x,min(max(x/10,5),10))) Attempt This Online! A port of @Evargalo's R answer. Prints the result to stdout.
alephalpha's user avatar
  • 46.6k
0 votes

German pharmacy payment

Wolfram Language (Mathematica), 36 bytes #~Min~Max[.1#,5]~Min~10~Round~.01&@x Alas, we cannot save an extra byte by using infix notation with ...
dalamajama's user avatar
0 votes

German pharmacy payment

sclin, 26 bytes dup.1*5|10,` &/100* |~100/ Try it on scline! sclin's default real/rational number representation comes in handy here. Explanation Prettified ...
Mama Fun Roll's user avatar
5 votes

German pharmacy payment

R, 39 bytes \(x)round(.001+min(x,max(.1*x,5),10),2) Basically using the formula given by the OP. -5 bytes thanks to @doubleunary -3 bytes and fix a rounding error ...
Evargalo's user avatar
  • 313
0 votes

German pharmacy payment

Uiua 0.3.1, 16 bytes ↧↧↥5⍜×⁅100⊃÷∘10. See it in action
RomanPro100's user avatar
2 votes

German pharmacy payment

Ruby, 42 36 bytes ->a{[a,[a/10,5].max,10].min.round 2} Try it online! Ruby, 38 bytes Formatted as per initial requirement: ...
G B's user avatar
  • 21.3k
2 votes

German pharmacy payment

Google Sheets / Microsoft Excel, 31 bytes =fixed(min(10,A1,max(5,A1/10))) Put the input in cell A1 and the formula in ...
doubleunary's user avatar
0 votes

German pharmacy payment

Charcoal, 21 bytes NθI⌊⟦θχ⌈⟦⁵∕⌊⁺·⁵×θχ¹⁰⁰ Try it online! Link is to verbose version of code. Explanation: Port of the formula given in the question, but with ...
Neil's user avatar
  • 166k
2 votes

German pharmacy payment

Retina 0.8.2, 95 92 bytes \. .+ $* ^(.{1000}(?=.{8995})|.(.{499,998})(?=\2{9}....)|.{0,500}).* 00$.1 0*(.+)(..) $1.$2 Try it online! Link includes test cases. ...
Neil's user avatar
  • 166k
8 votes

German pharmacy payment

Jelly, 14 bytes ÷⁵«⁵»5«+ȷ-4ær2 A monadic Link that accepts the full price as a float and outputs the charge as a float. Try it online! How? ...
Jonathan Allan's user avatar
1 vote

German pharmacy payment

JavaScript (ES6), 45 bytes x=>~~(Math.min(x*10,x<50?50:x,100)*10+.5)/100 Try it online! 40 bytes This one works in theory, but fails on some test cases ...
Arnauld's user avatar
  • 189k
6 votes

German pharmacy payment

APL+WIN, 21 bytes Prompts for input 2⍕(n⌊((.1×n←⎕)⌈5))⌊10 Try it online! Thanks to Dyalog Classic
Graham's user avatar
  • 5,506
3 votes

German pharmacy payment

JavaScript (Node.js), 40 bytes x=>Math.min(x,x<50?5:(x*10+.5|0)/100,10) Try it online! Python 3, 45 bytes ...
l4m2's user avatar
  • 20.7k
0 votes

Is it a Cyclic number?

Scala 3, 85 bytes n=>(2 to n.size).forall(i=>n.sorted==(BigInt(n)*i).toString.padTo(n.size,'0').sorted) Attempt This Online!
138 Aspen's user avatar
  • 4,815
0 votes

Column-wise Sum

Scala, 64 bytes Golfed version. Try it online! l=>{l.map(x=>x.padTo(l.map(_.size).max,0)).transpose.map(_.sum)} Ungolfed version. Try it online! ...
138 Aspen's user avatar
  • 4,815

Top 50 recent answers are included