17
\$\begingroup\$

Introduction

I have an even number of bottles, all of different sizes. Unfortunately, I only know the size of the smallest bottle: 300ml.
I also know the following:

  • Half of the bottles are twice the size of the other half, meaning that the smallest small bottle and the smallest large bottle are in a ratio of 2:1.
  • The smaller bottles, from smallest to largest, increase in size by n%, where n is the number of bottles multiplied by 3.

Could you help find what sizes my bottles are?

Challenge

Your input is to be an even number of bottles.
The output should be the size of all of the small bottles (from smallest to largest), then all of the large bottles (from smallest to largest).

Example I/O

In: 2
Out: 300, 600

In: 4
Out: 300, 336, 600, 672

In: 10
Out: 300, 390, 507, 659.1, 856.83, 600, 780, 1014, 1318.2, 1713.66

(Note: commas are unnecessary; this answer can be formatted in any way you want as long as all of the "small" bottles come before the "large" bottles.)

Rules

Standard loophole rules apply.
This is , so shortest answer in bytes wins!

Winners

Esoteric Languages
15 bytes
05AB1E by Kevin Cruijssen

Standard Languages
36 bytes
Mathematica by attinat

\$\endgroup\$
  • \$\begingroup\$ In the third testcase, does it mean 856.83 is smaller one but 600 is larger one? It is confusing. \$\endgroup\$ – tsh Nov 12 '19 at 10:38
  • 1
    \$\begingroup\$ Yes - the size of "smaller" bottles can be larger than the "larger" bottles. \$\endgroup\$ – Corsaka Nov 12 '19 at 10:39
  • \$\begingroup\$ Essentially, the first half of your output should be the "smaller" bottles, and the second half should be the "larger" bottles. \$\endgroup\$ – Corsaka Nov 12 '19 at 10:40
  • 1
    \$\begingroup\$ Doesn't "(at least referring to bottles)" make the title even worse when you think about it? \$\endgroup\$ – Night2 Nov 12 '19 at 12:50
  • 1
    \$\begingroup\$ Let's not go there. \$\endgroup\$ – Corsaka Nov 12 '19 at 13:40

22 Answers 22

3
\$\begingroup\$

05AB1E, 15 bytes

₆v;F.03*>NmyтP,

Port of @TFeld's Python 2 answer, so make sure to upvote him.

Try it online or verify all test cases.

Explanation:

₆                # Push builtin integer 36
 v               # Loop `y` over both digits:
  ;              #  Halve the (implicit) input-integer
   F             #  Inner loop `N` in the range [0, input/2):
    .03*         #   Multiply the (implicit) input by 0.03
                 #   (alternative 4-byter: `т/3*` # divide by 100, multiply by 3)
        >        #   Increase this by 1
         Nm      #   Take it to the power `N`
           yт    #   Push both `y` and 100
             P   #   And take the product of the entire stack
              ,  #   Then pop and print this number with trailing newline
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Wait, 05AB1E has floating-point literals‽ I always assumed this wouldn't work, since . is used for extended commands. \$\endgroup\$ – Grimmy Nov 12 '19 at 15:57
  • 1
    \$\begingroup\$ Here's another 15, another 15, and yet another one. There are lots of possible approaches, but I'm not finding anything shorter. \$\endgroup\$ – Grimmy Nov 12 '19 at 16:24
  • \$\begingroup\$ @Grimmy The new version of 05AB1E indeed had floating point literals :) In the legacy version this wasn't available yet, but it's something new Adnan added in the rewrite. \$\endgroup\$ – Kevin Cruijssen Nov 12 '19 at 21:39
6
\$\begingroup\$

Python 2, 61 60 59 bytes

lambda n:[a*(1+.03*n)**i*75for a in 4,8for i in range(n/2)]

Try it online!

-1 byte, thanks to Joseph Sible

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ It confuses me that you've managed to get [300.0, 336.00000000000006, 600.0, 672.0000000000001]. Where did the extra 0's come from? \$\endgroup\$ – Corsaka Nov 12 '19 at 10:57
  • 8
    \$\begingroup\$ That's floating point precision for you.. \$\endgroup\$ – TFeld Nov 12 '19 at 10:59
  • \$\begingroup\$ @Corsaka That's caused by the same thing that makes many languages say 0.1 + 0.2 != 0.3 is true \$\endgroup\$ – Redwolf Programs Nov 12 '19 at 16:26
  • 6
    \$\begingroup\$ -1 byte: use 75, 4, and 8 in place of 100, 3, and 6. \$\endgroup\$ – Joseph Sible-Reinstate Monica Nov 12 '19 at 21:40
  • \$\begingroup\$ @JosephSible Thanks :) \$\endgroup\$ – TFeld Nov 13 '19 at 15:59
5
\$\begingroup\$

Wolfram Language (Mathematica), 36 bytes

{#,2#}&[300(1+.03#)^Range[0,#/2-1]]&

Try it online!

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Jelly, 16 bytes

×.03‘*HḶ$×300;Ḥ$

Try it online!

-2 bytes thanks to Nick Kennedy

Explanation

×.03‘*HḶ$×300;Ḥ$  Main Link
×.03              Multiply the number of bottles by 3%
    ‘             Increment (add 100%)
     *            (Vectorized) exponent to the power of:
      HḶ$         [0, 1, ..., n-1]
         ×300     Multiply each factor by 300
             ;Ḥ$  Double the list and append it
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ ×.03 saves two bytes. \$\endgroup\$ – Nick Kennedy Nov 12 '19 at 14:58
  • 1
    \$\begingroup\$ @NickKennedy Thanks! \$\endgroup\$ – HyperNeutrino Nov 12 '19 at 15:14
3
\$\begingroup\$

Haskell, 47 bytes

f n=[75*a*(1+0.03*n)**i|a<-[4,8],i<-[0..n/2-1]]

Try it online!

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Julia 1.0, 42 38 bytes

f(n,z=[75*(1+.03n).^(0:n÷2-1)])=4z,8z

-4 bytes using ideas from John and Joseph Sible.

Try it online!

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Python 2, 55 bytes

n=input()/2
for c in 4,8:exec"print c*75;c*=1+.06*n;"*n

Try it online!

The *75 trick is taken from other answers.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 63 bytes

f=(n,b=300,r=1+n*9/b,h=n/2)=>n?[b,...f(n-1,--h?b*r:600,r,h)]:[]

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 59 bytes \$\endgroup\$ – Shaggy Nov 12 '19 at 11:29
  • 2
    \$\begingroup\$ 57 bytes \$\endgroup\$ – Arnauld Nov 12 '19 at 11:37
  • 3
    \$\begingroup\$ 55 bytes, expanding on @Arnauld's improvements. \$\endgroup\$ – Shaggy Nov 12 '19 at 12:08
  • \$\begingroup\$ @Arnauld Maybe you could post as another answer. It is different enough as another answer, imo. \$\endgroup\$ – tsh Nov 13 '19 at 2:58
  • \$\begingroup\$ @Arnauld And use the idea from here, it is 54 bytes \$\endgroup\$ – tsh Nov 13 '19 at 3:01
2
\$\begingroup\$

PHP, 70 62 bytes

for($s=300;$i++<$n=$argn;$s=$n/2-$i?$s+$s*$n*.03:600)echo$s,_;

Try it online!

Output numbers are seperated by _.

Alternative for $s+$s*$n*.03 can be $s*=1+$n*.03 too, but both are same length.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I'm getting errors with this one. Seems to be complaining that i was never defined \$\endgroup\$ – Corsaka Nov 12 '19 at 13:42
  • \$\begingroup\$ @Corsaka those are warnings or notices in stderr and are totally fine. \$\endgroup\$ – Night2 Nov 12 '19 at 15:46
2
\$\begingroup\$

PowerShell, 66 54 bytes

-12 bytes thanks to mazzy

param($n)300,600|%{$y=$_;1..($n/2)|%{$y;$y*=1+$n*.03}}

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 54 bytes \$\endgroup\$ – mazzy Nov 12 '19 at 17:52
  • 1
    \$\begingroup\$ @mazzy breaks on the last test case. The last Small Bottle (856.83) is larger than the first Big Bottle (600) \$\endgroup\$ – Veskah Nov 12 '19 at 18:01
  • 1
    \$\begingroup\$ oO! thanks. Very strange comment "the size of "smaller" bottles can be larger than the "larger" bottles". Ok. Another 54 bytes \$\endgroup\$ – mazzy Nov 12 '19 at 18:04
2
\$\begingroup\$

Icon, 60 58 bytes

procedure f(n)
write(!36*(1+.03*n)^(0to n/2-1)*100)&\z
end

Try it online!

Saved 2 bytes by replacing (3|6)(alternate 3 with 6) with !36. !generates the components of a data object. When applied to a number it generates its digits. In Unicon - the descendent of Icon - !n generates the numbers in the range 1..n.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ What's the point of \z? TIO doesn't understand it. \$\endgroup\$ – Corsaka Nov 12 '19 at 13:43
  • \$\begingroup\$ @Corsaka 3|6 and 0to n/2-1 are generators and normally I would write every write((3|6)*...). Icon have a bactracking mechanism though and when an expression fails, it backtracks to fetch another value from the preceding generator(s). \z checks if the value z is non-null and since z is not present (declared), it backtracks until the 2 generators are exhausted. \$\endgroup\$ – Galen Ivanov Nov 12 '19 at 13:49
  • \$\begingroup\$ @Corsaka TIO only complains that I use a variable that is not declared. Here I declared the variable n in the main procedure and it stopped compaining about n, only z remained. \$\endgroup\$ – Galen Ivanov Nov 12 '19 at 13:52
2
\$\begingroup\$

Ruby, 57 53 bytes

->n{n.times.map{|a|300*(1+a*2/n)*(1+0.03*n)**a%=n/2}}

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ -1 byte: use 75, 4, and 8 in place of 100, 3, and 6. \$\endgroup\$ – Joseph Sible-Reinstate Monica Nov 12 '19 at 21:43
  • \$\begingroup\$ Thanks, but I've found a better way. \$\endgroup\$ – G B Nov 12 '19 at 22:36
2
\$\begingroup\$

K (oK), 32 bytes

{s,2*s:(-1+x%2)((1+.03*x)*)\300}

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 23 bytes

NθF²E⊘θI×׳⁰⁰⊕ιX⊕×θ·⁰³κ

Try it online! Link is to verbose version of code. Outputs each list element on a separate line. Explanation:

Nθ

Input n

F²

Loop i twice, once for the small sizes, once for the large sizes.

E⊘θ

Loop k over half of the number of bottles, and implicitly output each calculation on its own line.

I×׳⁰⁰⊕ιX⊕×θ·⁰³κ

Calculate 300(i+1)(.03n+1)ᵏ and cast the result to string.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Forth (gforth), 84 bytes

: x dup 2/ 0 do fdup f. fover f* loop ; : f dup s>f .03e f* 1e f+ 3e2 x 6e2 fnip x ;

Try it online!

Code Explanation

\ helper function to extract out common logic from the small and large numbers
: x               \ start a new word definition
  dup 2/          \ duplicate the input and divide by 2
  0 do            \ loop from 0 to n/2
    fdup f.       \ print the top of the floating point stack
    fover f*      \ multiple the top float stack value by the 2nd float stack value
  loop            \ end the loop
;

: f               \ start a new word definition
  dup s>f         \ duplicate n and place a copy on the float stack
  0.03e f*        \ multiple by 0.03 (multiply by 3 and divide by 100)
  1e f+           \ add 1 to get our increase multiplier
  3e2 x           \ print the smaller numbers by starting with 300
  6e2 fnip x      \ drop the remaining small number and print the large numbers from 600
;                 \ end word definition
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Pyth, 23 bytes

Fk2Fb/Q2*300*hk^h*.03Qb

Try it online!

Port of @TFeld's answer, which I was able to make decently concise. Cant help but feel like there's a more clever answer with Pyth but I wasnt able to find it.

How it Works

Fk2Fb/Q2*300*hk^h*.03Qb
Fk2                     - For k in range(2)
   Fb/Q2                - For b in range(input/2)
        *300*hk         - 300 times k+1 times...
                h*.03Q  - 1 + 0.03 times input
               ^      b - The above to the exponent b
                          Implicitly prints the result
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica), 40 bytes

Two independent 40-byte answers: the first is an unnamed function, the second is a named function g, both taking one argument.

Table[300i(1+.03#)^j,{i,2},{j,0,#/2-1}]&

g@n_:=300#(1+.03n)^(#2-1)&~Array~{2,n/2}
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

R, 46 bytes

x=scan();b=300*(1+0.03*x)^(0:(x/2-1));c(b,b*2)

Try it online

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Java 8, 89 bytes

n->{for(int k=0,i;++k<3;)for(i=0;i<n/2;)System.out.println(Math.pow(.03*n+1,i++)*k*300);}

Port of @TFeld's Python 2 answer, so make sure to upvote him.

Try it online.

Explanation:

n->{                              // Method with integer parameter and no return-type
  for(int k=0,i;++k<3;)           //  Loop `k` in the range (0,3) (basically [1,2]):
    for(i=0;i<n/2;)               //   Inner loop `i` in the range [0, i/2):
      System.out.println(         //    Print with trailing newline:
        Math.pow(.03*n            //     `n` multiplied by 0.03
                 +1               //     incremented by 1
                   ,i++)          //     to the power `i`
                        *k*300);} //     multiplied by `k` and 300
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Wren, 79 bytes

Fn.new{|n|
for(a in[300,600])for(i in 1..n/2){
System.print(a)
a=a+a*n*0.03
}
}

Try it online!

Wren, 81 bytes

TField answer turns out to be longer.

Fn.new{|n|
for(i in 0...n/2)for(a in[3,6])System.print(a*(1+0.03*n).pow(i)*100)
}

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Japt, 27 23 bytes

_+3/L*Z*U}h[300]Uz
cUmÑ

Try it

_+3/L*Z*U} // function returning next element
h[300]Uz // runs the above func. U/2 times, starting from 300
cU®Ñ // concat the array obtained with the array multiplied * 2

Saved 4 thanks to @Shaggy

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ 23 bytes \$\endgroup\$ – Shaggy Nov 14 '19 at 16:19
  • \$\begingroup\$ #Ĭ == 300 in terms of bytes! Lol \$\endgroup\$ – AZTECCO Nov 14 '19 at 19:22
  • 1
    \$\begingroup\$ yup. But you save a byte by avoiding UTF encoding, where Ñ is 2 bytes. \$\endgroup\$ – Shaggy Nov 14 '19 at 23:26
0
\$\begingroup\$

C (gcc), 79 74 77 bytes

78 if the dash in compile arg is ignored. Port of TField answer. Increase in bytes is to comply with rules.

-5 bytes thanks to ceilingcat and bznein

b;c;f(a){for(b=0;++b<3;c=0)while(c<a/2)printf("%f ",pow(.03*a+1,c++)*b*300);}

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You can also replace for(;c<a/2;) with while(c<a/2) \$\endgroup\$ – bznein Nov 13 '19 at 10:19
  • \$\begingroup\$ Is it required for the function to be able to be called multiple times? \$\endgroup\$ – girobuz Nov 14 '19 at 4:44
  • 1
    \$\begingroup\$ Yes \$\endgroup\$ – ceilingcat Nov 14 '19 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.