11
\$\begingroup\$

Tired of always wondering how many more Pokémon you need to catch to get those high-tier evolutions? Wonder no more! Now you will write a complete program or function to calculate it for you!

The Challenge:

As input, your program will receive a list of the costs in candy to evolve a Pokémon to the next tier. (This list may be separated by any delimiter of your choosing, or as function arguments). Your program will then return or print the number of Pokémon that must be caught, including the one that will be evolved, to evolve through all the tiers given.

How do you calculate this? Like so:
1. Add up all the candy costs: 12 + 50 = 62
2. Subtract 3 candies from the total, this being from the one Pokémon you keep for evolving: 62 - 3 = 59
3. Divide this number by 4 (3 for catching, 1 for giving it to the Professor), always taking the ceil() of the result: ceil(59/4) = 15
4. Finally, add 1 to this total to get the total number of Pokémon you must catch, 16!

Example Input -> Output:

[4] -> 2
[50] -> 13
[12, 50] -> 16
[25, 100] -> 32
[19, 35, 5, 200] -> 65

Winning:

The app has already taken up most of the space on your phone, so your program needs to be as short as possible. The complete program or function with the smallest byte count will be accepted in two weeks! (with any ties being settled by the earliest submitted entry!)

\$\endgroup\$
  • 3
    \$\begingroup\$ How is the output calculated? \$\endgroup\$ – Leaky Nun Aug 23 '16 at 21:55
  • 8
    \$\begingroup\$ In the future, please use the Sandbox to work out kinks in your challenges and to get feedback on them before posting. \$\endgroup\$ – El'endia Starman Aug 23 '16 at 22:01
  • 7
    \$\begingroup\$ If you want a slightly less nonsensical rationale for short code length, you could go with "because the app has almost killed your battery, you want your code to be as short as possible, so you can type it in before your battery dies." \$\endgroup\$ – Mego Aug 23 '16 at 22:02
  • 2
    \$\begingroup\$ Shouldn't the formula be floor(Sum(L)/4)+1? The current formula doesn't work for sums divisible by 4. For example [400] would return 100, when in reality it needs to be 101 for the extra one to evolve. \$\endgroup\$ – Emigna Aug 23 '16 at 22:40
  • 6
    \$\begingroup\$ I hope someone posts an answer in Go \$\endgroup\$ – Kodos Johnson Aug 24 '16 at 0:50

17 Answers 17

9
\$\begingroup\$

05AB1E, 4 bytes

O4÷>

Explanation

O    # sum
 4÷  # integer division by 4
   > # increment

Try it online

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ ÷ is 2 bytes ... \$\endgroup\$ – user23127 Aug 24 '16 at 11:21
  • 3
    \$\begingroup\$ @user23127: 05AB1E uses the CP-1252 encoding. \$\endgroup\$ – Emigna Aug 24 '16 at 11:27
9
\$\begingroup\$

Jelly, 5 4 bytes

S:4‘

Try it online!

Sum, integer divide : by 4 and increment .

| improve this answer | |
\$\endgroup\$
  • 8
    \$\begingroup\$ ;-; I'm 4 seconds late \$\endgroup\$ – acrolith Aug 23 '16 at 22:15
  • \$\begingroup\$ It doesn't work when the sum is divisible by 4. \$\endgroup\$ – milk Aug 23 '16 at 23:56
  • \$\begingroup\$ Gives wrong answer for [4]. \$\endgroup\$ – orlp Aug 24 '16 at 0:41
  • \$\begingroup\$ Fixes. Apparently the spec changed when I was sleeping. \$\endgroup\$ – PurkkaKoodari Aug 24 '16 at 4:03
5
\$\begingroup\$

Brain-Flak 112 bytes

([]<([()])>){{}({}{})([][()])}{}{({}[()])<>(({}[()()()]<({}())>)){{}(<({}()()()()<({}[()])>)>)}{}<>}{}<>{}({}())

Try It Online!

Explanation

It sums the stack, subtracts one, divides by four, and adds one.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ How do I run this on try it online? It only outputs 1 for me for any input scheme I've tried. \$\endgroup\$ – orlp Aug 24 '16 at 0:46
  • 1
    \$\begingroup\$ Gives wrong answer for [4]. \$\endgroup\$ – orlp Aug 24 '16 at 0:50
  • \$\begingroup\$ @orlp Fixed. I put the wrong code in try it online. \$\endgroup\$ – Ad Hoc Garf Hunter Aug 24 '16 at 0:50
3
\$\begingroup\$

C# REPL, 15 bytes

n=>n.Sum()/4+1;

Casts to Func<IEnumerable<int>, int>.

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

Actually, 4 bytes

Σ¼≈u

Try it online!

Explanation:

Σ¼≈u
Σ     sum
 ¼    divide by 4
  ≈   floor
   u  add 1
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Aren't these unicode characters 2 bytes each? \$\endgroup\$ – user23127 Aug 24 '16 at 11:18
  • 1
    \$\begingroup\$ @user23127 If this were encoded in UTF-8, yes. Actually (and its predecessor Seriously) use CP437. \$\endgroup\$ – Mego Aug 24 '16 at 21:01
3
\$\begingroup\$

Brachylog, 5 bytes

+:4/+

Try it online!

Explanation

A very original answer…

+        Sum
 :4/     Integer division by 4
    +    Increment
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Python 2, 21 bytes

lambda a:~-sum(a)/4+1

Ideone it!

Formula: ((sum(a)-1)//4)+1 where // is floor-div.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Gives wrong answer for [4]. \$\endgroup\$ – orlp Aug 24 '16 at 0:38
2
\$\begingroup\$

BASH (sed + bc) 19

sed 's~)~+4)/4~'|bc

Input is a + separate list on stdin
E.g.:
echo '(19+35+5+200)'| sed 's~)~+4)/4~'|bc

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

Haskell, 17 bytes

(+1).(`div`4).sum
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Pyke, 4 bytes

seeh

Try it here!

((sum(input)/2)/2)+1
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Pyth, 5 bytes

h/sQ4

Try it here!

Sum input with sQ, divide by 4 with /4 and finally increment h.

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

CJam, 7 bytes

{:+4/)}

Try it here!

Defines an unnamed block that expects the input on the stack and leaves the result there.
:+ sums the list, 4/ divides the result by 4 and ) increments that.

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

Retina, 18 17 bytes

Byte count assumes ISO 8859-1 encoding.

$
¶4
.+|¶
$*
1111

Input is linefeed-separated.

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ @orlp yay for rule changes. fixed. \$\endgroup\$ – Martin Ender Aug 24 '16 at 7:29
1
\$\begingroup\$

R, 22 bytes

floor(sum(scan())/4+1)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 29 Bytes

x=>x.reduce((a,b)=>a+b)/4+1|0
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

S.I.L.O.S 100 99 103 characters + 22 for sample input

Code with testing harness.

set 512 52
set 513 10
GOSUB e
GOTO f
funce
a = 0
i = 511
lblE
i + 1
b = get i
a + b
if b E
a / 4
a + 1
return
lblf
printInt a

input as a series of set commands to modify the spots of the heap starting at spot 512.
Try it Online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Just because Pokemon Go doesn't have more than 8 tiers of evolution (it actually maxes out at 3), doesn't mean you aren't required to handle larget test cases. \$\endgroup\$ – Mego Aug 24 '16 at 4:28
  • \$\begingroup\$ @Mego the spec clearly references pokemon go, and thus we can assume that all input will be valid input. I would have posted a much better version that does indeed handle newline separaated input terminated with a zero sentinel, but the TIO is currently borked \$\endgroup\$ – Rohan Jhunjhunwala Aug 24 '16 at 12:38
  • \$\begingroup\$ @Mego let me clarify with the OP. If this is invalid I can modify it to work for even larger test casees \$\endgroup\$ – Rohan Jhunjhunwala Aug 24 '16 at 12:38
  • \$\begingroup\$ This is actually a standard loophole - you're assuming rules not present in the challenge. \$\endgroup\$ – Mego Aug 26 '16 at 7:28
  • \$\begingroup\$ @Mego modified for a cost of three bytes, it now should work up to 1000's of evolutions. \$\endgroup\$ – Rohan Jhunjhunwala Aug 26 '16 at 13:13
-1
\$\begingroup\$

Python 2, 40 bytes

import math
lambda s:math.ceil(sum(s)/4)
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This does not work because sum(s) is an integer and / in Python 2 would be integer division when both arguments are integers. \$\endgroup\$ – Leaky Nun Aug 23 '16 at 22:11
  • \$\begingroup\$ @LeakyNun what do you mean? it works for me \$\endgroup\$ – acrolith Aug 23 '16 at 22:16
  • 1
    \$\begingroup\$ Gives wrong answer for [4]. \$\endgroup\$ – orlp Aug 24 '16 at 0:40

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.