# Lumberjaxe Code Golf

## JavaScript (Node.js), 52 bytes

Takes input as `(b)(n)`

, where `b`

is a Buffer (using the characters described in the challenge) and `n`

is the durability of the axe.

Returns a Boolean value and 2 integers as `[ broken, [ small, big ]]`

.

```
b=>n=>[b.some(c=>(n-=6&c+1)<0||!++a[c%3],a=[0,0]),a]
```

Try it online!

### How?

Given an ASCII code `c`

, we use `6 & (c + 1)`

to get the number of swings needed to chop the tree, and `c % 3`

to get an index into the tree-counting array `a[]`

(0 for *small*, 1 for *big*).

```
char. | c = ASCII code | 6 & (c + 1) | c % 3
-------+----------------+-------------+-------
'i' | 105 | 2 | 0
'|' | 124 | 4 | 1
```

## 05AB1E, 20 bytes

-5 bytes thanks to Kevin Cruijssen.

```
ηʒÇ3%·Ì[email protected]}θD¹Ês{γ€g‚
```

Try it online!

### Explanation

```
η Prefixes of the input. ["i", "i|", "i||", "i||i", "i||ii", "i||iii", "i||iii|"]
ʒ Filter:
Ç Ord codes. E.g. "i||i" -> [105, 124, 124, 105]
3% Mod 3. -> [0, 1, 1, 0]
· Double. -> [0, 2, 2, 0]
Ì Add 2. -> [2, 4, 4, 2]
O Sum the prefix. -> 12
@} Does it exceed
the second input? -> 50 >= 12 -> 1
θ The last item of the filtered prefixes: "i||iii|"
D Duplicate.
¹Ê Is it not equal to the first inupt? "i||iii|" != "i||iii|" -> 0
s Swap the other copy up. "i||iii|"
{ Sort. "iiii|||"
γ Group by consecutive equal items. ["iiii","|||"]
€g Map: length. [3, 4]
‚ Pair. [0, [3, 4]]
```

## J, ^{37} ^{34} 33 bytes

```
(](-:;+/@#:@])(>:2*+/\)#])' i'i.]
```

Try it online!

*-1 byte thanks to Bubbler*

Converts small to 1, big to 2. Now create a filter by doubling and scan summing, and apply filter to find entries less than or equal to the left input. Take just those entries, convert to binary, and sum to get the `<num big>, <num small>`

part of the answer. Check if the filtered list equals the unfiltered list to get the "chops down all trees?" part of the answer.