Hot answers tagged

19

Taxi, 1838 1601 1371 bytes -237 bytes. I forgot myself. In Taxi, it is much cheaper to hard-code each fare name rather than concatenate pieces. -230 bytes. Re-factored to not require reversing the fares. 'UberX' is waiting at Writer's Depot.'UberXL' is waiting at Writer's Depot.'UberPlus' is waiting at Writer's Depot.'UberBlack' is waiting at Writer's Depot....


11

R, 69 bytes function(a,b)c("Uber",c("X","XL","Plus","Black","SUV")[sum(a*b<=20)]) Try it online! The index of the best ride is equal to the number of affordable rides, i.e. sum(miles*fares <= 20).


10

Husk, 15 14 13 9 bytes §,▼▲f←ṁP* Try it online! Takes two input arrays, outputs pair (min,max). -1 byte from Dominic Van Essen. -1 more byte from Dominic Van Essen (after some more struggling). -4 bytes taking arrays of digits as input. Explanation §,▼▲f←ṁP* cartesian product pairs of the inputs ṁP map each to permuations, and flatten the ...


10

Java 8, 91 84 76 bytes -15 bytes thanks to @OlivierGrégoire. (m,a,b,c,d,e)->"Uber"+((m=20/m)<b?"X":m<c?"XL":m<d?"Plus":m<e?"Black":"SUV") Try it online. Original 91 84 bytes answer: m->f->{int i=5;for(;f[--i]*m>20;);return"Uber"+"X;XL;Plus;Black;SUV"....


9

JavaScript (Node), Unknown time due to TIO not liking 2.6 million characters as the input. If you want to see the previous tests, then Try it online!. Currently, we can't use TIO with all of the inputs. function iroot(base) { let s = base + 1n; let u = base; if (!base) { console.log(0n); return; } while (u < s) { s = u; u = (u + base / u) /...


9

C++, 140 µs This is a trivial answer that uses GMP, but I’m submitting it anyway to drive home the point that the test cases are way too small. Scores in the range of literally nanoseconds per input cannot meaningfully be compared. We need larger test cases for this to be an interesting challenge. #include <chrono> #include <gmpxx.h> #include &...


8

05AB1E, 11 10 bytes â€Â9ÝKWsà‚ -1 byte thanks to @ovs. Try it online or verify a few more test cases. Explanation: â # Take the cartesian product of the digits of the two (implicit) inputs €Â # Bifurcate each value within the list (short for Duplicate & Reverse copy) 9Ý # Push the list [0,1,2,3,4,5,6,7,8,9] K # ...


8

APL (Dyalog Unicode), 41 bytes (SBCS) Anonymous tacit infix function. Order of arguments doesn't matter. 'Uber',((∊∘⎕A⊂⊢)'XXlPlusBlackSuv')⊃⍨20⍸⍨× Try it online! × multiply the arguments 20⍸⍨ ɩndex of [a,b) ɩnterval in which 20 fits (…)⊃⍨ user that to pick from  (…)'XXlPlusBlackSuv' this string, processed by:   …⊂⊢ taking the string and splitting it on    ∊...


7

Rust 450 μs use std::time::SystemTime; use num_bigint::BigUint; fn main() { // Parse the numbers let mut numbers: Vec<_> = INPUT.iter().map(|i| { i.parse::<BigUint>().unwrap() }).collect(); let start = SystemTime::now(); // Do the calculation numbers.iter_mut().for_each(|s| *s = s.sqrt()); // Print the time....


7

05AB1E, 6 bytes Nega to Deca T(ö Try it online! Deca to Nega T(в Try it online!


7

JavaScript (ES6), 25 + 55 = 80 bytes Negadecimal to decimal (25 bytes) f=n=>n&&n%10-10*f(n/10|0) Try it online! How? This one is pretty straightforward. We recursively compute: $$f(n) = \cases{ 0, n=0\\ (n \bmod 10) - 10\times f\left(\left\lfloor\dfrac{n}{10}\right\rfloor\right), n>0}$$ Decimal to negadecimal (55 bytes) f=(n,i=n%10,k=n>0?-...


6

Jelly, 8 bytes 1w11¬$#Ṫ Try it online! Almost entirely printable ASCII! Takes input from STDIN How it works 1w11¬$#Ṫ - Main link. No arguments $ - Group the previous 2 links into a monad f(k): 11 - Yield 11 w - Yield 1 if 11 is a sublist of k's digit else 0 ¬ - Map 1 to 0 and 0 to 1 1 # - Count up k = 1, 2, 3, ... until ...


6

Brachylog, 15 bytes {∋ᵐpcℕ₁₀}ᶠ⟨⌋≡⌉⟩ Try it online! {∋ᵐpcℕ₁₀}ᶠ⟨⌋≡⌉⟩ { }ᶠ find all possible outputs: ∋ᵐ select a digit from each number p permute them c merge them to a number ℕ₁₀ that number is >= 10 with the list of all possible numbers: ⟨⌋≡⌉⟩ [minimum, ...


6

Jelly, 11 10 bytes p;p@ḷ/ƇṢ.ị Try it online! Dyadic link. Input and output is a list of digits. Explanation p;p@ḷ/ƇṢ.ị p Cartesian product ; Join with @ Reverse arguments p Cartesian product Ƈ Filter by / Reduce by ḷ First argument Ṣ Sort .ị First and ...


5

Python 2, 68 bytes lambda n:[`s`[:n]for s in 321654,381654729,123654][380712>>n*2&3::2] Try it online! Outputs a list a strings. 71 bytes lambda n:[0,1,12,[123,321],0,0,[123654,321654],0,38165472,381654729][n] Try it online! Just a boring straight hardcode. Outputs a single number, or a list of two numbers, or 0 for no output. None of the ...


5

Python 3, 81 bytes lambda a,b:[m(k for i in a for j in b for k in(i+j,j+i)if'1'<k)for m in(min,max)] Try it online!


5

Haskell, 62 bytes a!b=(`foldl1`[s|i<-a,j<-b,s<-[[i,j],[j,i]],s>"1"])<$>[min,max] Try it online! This is the same approach as Jitse's Python answer.


5

C (gcc), 233 \$\cdots\$ 189 185 Saved 4 bytes thanks to gastropner!!! Saved 9 13 bytes thanks to ceilingcat!!! #define d(a,i)for(qsort(a,i=3,1,L"\xf06be0f\xd02917beǃ");a[--i]<49;); s;j;i;f(a,b)char*a,*b;{d(a,i)d(b,j)s=a[2];i=a[i]<b[j]?s=b[2],a[i]:b[j];j=*a;*b++=j>*b?j=*b,*a:*b;*a++=i;*a=s;*b=j;} Try it online! Inputs two \$3\$-digit ...


5

C (gcc), 89 82 bytes -7 bytes thanks to @AZTECCO Runs the mileage check in reverse and prints the result. Because a valid result is guaranteed, I don't have to check for going out of array bounds! As this is a fairly simple function, I can make it a macro to save space. //f(m,f)=for(_=5;20/f[--_]<m;);printf("Uber%.5s","X XL Plus ...


5

Perl 5 -apl, 63 bytes $m=<>;1while@F&&20<$m*pop@F;$_=Uber.(X,XL,Plus,Black,SUV)[@F*1] Try it online! Input is on two lines. First is the list of fares; second is the distance.


5

Jelly, 8 bytes Negadecimal to decimal: ḅ-10 Try it online! Decimal to negadecimal b-10 Try it online! Input as an integer, output as a list of digits. +2 total bytes (+1 to each) to I/O as integers


5

Wolfram Language (Mathematica), 17+35 = 52 bytes From negadecimal: #~FromDigits~-10& Try it online! Straightforward base conversion from a string or list of digits. To negadecimal: f@0=0 f@a_:=f@-⌊a/10⌋||a~Mod~10 Try it online! Outputs a list of digits, including a leading zero, wrapped in Or. +1 byte to output as an integer: Try it online!


5

JavaScript (Node.js), 59 bytes f=(p,e=n=>n&&(i=(n%10+10)%10)-p*e((n-i)/p))=>e f(10) f(-10) Try it online! f defines a helper function. f(10) returns a function that converts from negadecimal to decimal while f(-10) returns a function that converts from decimal to negadecimal.


5

Lisp Flavored Erlang, 33 + 59 + 59 = 153 151 bytes (defun m(X Y)(rem(+(rem X Y)Y)Y)) (defun n(N)(if(== N 0)0(-(m N 10)(*(n(floor(/ N 10)))10)))) (defun d(N)(if(== N 0)0(+(m N 10)(*(d(ceil(/ N -10)))10)))) n computes the decimal, given a negadecimal. d computes the reverse. Both functions take & return a regular integer. Erlang's rem function works like ...


4

Husk, 3 bytes ►≠O Try it online! Explanation ►≠O O order the elements ► max by ≠ inequality(selects least frequent elements) then returns the last of the least frequent elements


4

Jelly, 12 11 bytes p;U$Ḍ>Ƈ9Ṣ.ị Try it online! Input as a list of digits (which the Footer does for you) -1 byte thanks to Unrelated String How it works p;U$Ḍ>Ƈ9Ṣ.ị - Main link. Takes x on the left and y on the right p - Cartesian product of the digits. Call this list X $ - Group the previous two commands into a monad f(X): U ...


4

Retina, 38 bytes Lw$`(.).*,.*(.) $1$2¶$2$1 A`0. O` ,,G` Try it online! Link includes test cases. Explanation: Lw$`(.).*,.*(.) $1$2¶$2$1 Take the cartesian product of the inputs and their reverses. A`0. Remove entries with leading zeros. O` Sort. ,,G` Take the first and last result.


4

JavaScript (ES6), 80 bytes Expects a pair of 3-digit strings. Returns a pair of 2-digit integers. a=>[(g=n=>(a+[,a]).match(~~(n/10)+'\\d*,\\d*'+n%10)?n:g(n+d%7-2))(d=10),g(d=99)] Try it online! How? We use a+[,a] to concatenate a[] with itself, with a comma in between. For instance, ['123', '912'] is turned into '123,912,123,912'. (We only need the ...


4

Python 2, 70 bytes lambda*l:[m(m(set(l[i])-{'0'})+m(l[~i])for i in(0,1))for m in min,max] Try it online! Python 3, 70 bytes lambda a,b:[m(m({*a}-{'0'})+m(b),m({*b}-{'0'})+m(a))for m in(min,max)] Try it online! These could be shorter if we can take a list of digits as numbers.


4

Ruby, ~16-28 ms on TIO def newtonRoot base s = base + 1 u = base if base == 0 return 0 end while u < s do s = u u = (u + base / u) / 2 end return s end t = Time.now outputs = inputs.map{ |i| newtonRoot i } puts "> time elasped: #{ (Time.now - t) * 1000 } ms.\n\n" puts outputs.map{ |v| v * ...


Only top voted, non community-wiki answers of a minimum length are eligible