Skip to main content
added 663 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 115 112112 102 bytes

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online!Try it online! Link is to verbose version of code. Explanation:

≔⟦⟦⟦⟧⟦⟧⟧⟧η

Start with no mushrooms placed.

FEθ÷×÷⊖X⁴ι²X²κX²ιFEθ÷×÷⊖X⁴ι²X²κX²ι«

For each mushroom, calculate a bitmask corresponding to the space that it occupies. Edit: Saved 3 bytes by using my golf to @Arnauld's formula.

¿ι«

If this mushroom occupies space, then:

≔⟦⟧ζ

Start collecting placements that include this mushroom.

Fη«

Loop over the existing placements.

≔§κ¹ε

Get the bitmasks for the heights as this gets used a lot.

FΦLε¬&§ελι

Find whether this mushroom can be placed at any existing height.

⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧

Generate a placement for putting this mushroom at that height.

⊞§κ⁰Lε⊞ει⊞ζκ

Generate a placement for putting this mushroom at a new height.

»≔ζη

Save the new placements as the current placements.

»Fη⊞§κ⁰¦⁰

If this mushroom occupies no space then place it at zero height.

≔EηL⊟ιζ

Get the heights of all of the placements.

I§η⌕ζ⌊ζ

Output one of the placements with minimal height.

Previous less inefficient 112-byte version:

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online! Link is to verbose version of code. Explanation: Always places zero-width mushrooms at zero height instead of at all possible heights.

Charcoal, 115 112 bytes

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online! Link is to verbose version of code. Explanation:

≔⟦⟦⟦⟧⟦⟧⟧⟧η

Start with no mushrooms placed.

FEθ÷×÷⊖X⁴ι²X²κX²ι

For each mushroom, calculate a bitmask corresponding to the space that it occupies. Edit: Saved 3 bytes by using my golf to @Arnauld's formula.

¿ι«

If this mushroom occupies space, then:

≔⟦⟧ζ

Start collecting placements that include this mushroom.

Fη«

Loop over the existing placements.

≔§κ¹ε

Get the bitmasks for the heights as this gets used a lot.

FΦLε¬&§ελι

Find whether this mushroom can be placed at any existing height.

⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧

Generate a placement for putting this mushroom at that height.

⊞§κ⁰Lε⊞ει⊞ζκ

Generate a placement for putting this mushroom at a new height.

»≔ζη

Save the new placements as the current placements.

»Fη⊞§κ⁰¦⁰

If this mushroom occupies no space then place it at zero height.

≔EηL⊟ιζ

Get the heights of all of the placements.

I§η⌕ζ⌊ζ

Output one of the placements with minimal height.

Charcoal, 115 112 102 bytes

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online! Link is to verbose version of code. Explanation:

≔⟦⟦⟦⟧⟦⟧⟧⟧η

Start with no mushrooms placed.

FEθ÷×÷⊖X⁴ι²X²κX²ι«

For each mushroom, calculate a bitmask corresponding to the space that it occupies. Edit: Saved 3 bytes by using my golf to @Arnauld's formula.

≔⟦⟧ζ

Start collecting placements that include this mushroom.

Fη«

Loop over the existing placements.

≔§κ¹ε

Get the bitmasks for the heights as this gets used a lot.

FΦLε¬&§ελι

Find whether this mushroom can be placed at any existing height.

⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧

Generate a placement for putting this mushroom at that height.

⊞§κ⁰Lε⊞ει⊞ζκ

Generate a placement for putting this mushroom at a new height.

»≔ζη

Save the new placements as the current placements.

≔EηL⊟ιζ

Get the heights of all of the placements.

I§η⌕ζ⌊ζ

Output one of the placements with minimal height.

Previous less inefficient 112-byte version:

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online! Link is to verbose version of code. Explanation: Always places zero-width mushrooms at zero height instead of at all possible heights.

added 60 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 115115 112 bytes

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ∧ι⁻X²⁺κι⌈∕X²κX²⊖ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online!Try it online! Link is to verbose version of code. Explanation:

≔⟦⟦⟦⟧⟦⟧⟧⟧η

Start with no mushrooms placed.

FEθ∧ι⁻X²⁺κι⌈∕X²κX²⊖ιFEθ÷×÷⊖X⁴ι²X²κX²ι

For each mushroom, calculate a bitmask corresponding to the space that it occupies. Edit: Saved 3 bytes by using my golf to @Arnauld's formula.

¿ι«

If this mushroom occupies space, then:

≔⟦⟧ζ

Start collecting placements that include this mushroom.

Fη«

Loop over the existing placements.

≔§κ¹ε

Get the bitmasks for the heights as this gets used a lot.

FΦLε¬&§ελι

Find whether this mushroom can be placed at any existing height.

⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧

Generate a placement for putting this mushroom at that height.

⊞§κ⁰Lε⊞ει⊞ζκ

Generate a placement for putting this mushroom at a new height.

»≔ζη

Save the new placements as the current placements.

»Fη⊞§κ⁰¦⁰

If this mushroom occupies no space then place it at zero height.

≔EηL⊟ιζ

Get the heights of all of the placements.

I§η⌕ζ⌊ζ

Output one of the placements with minimal height.

Charcoal, 115 bytes

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ∧ι⁻X²⁺κι⌈∕X²κX²⊖ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online! Link is to verbose version of code. Explanation:

≔⟦⟦⟦⟧⟦⟧⟧⟧η

Start with no mushrooms placed.

FEθ∧ι⁻X²⁺κι⌈∕X²κX²⊖ι

For each mushroom, calculate a bitmask corresponding to the space that it occupies.

¿ι«

If this mushroom occupies space, then:

≔⟦⟧ζ

Start collecting placements that include this mushroom.

Fη«

Loop over the existing placements.

≔§κ¹ε

Get the bitmasks for the heights as this gets used a lot.

FΦLε¬&§ελι

Find whether this mushroom can be placed at any existing height.

⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧

Generate a placement for putting this mushroom at that height.

⊞§κ⁰Lε⊞ει⊞ζκ

Generate a placement for putting this mushroom at a new height.

»≔ζη

Save the new placements as the current placements.

»Fη⊞§κ⁰¦⁰

If this mushroom occupies no space then place it at zero height.

≔EηL⊟ιζ

Get the heights of all of the placements.

I§η⌕ζ⌊ζ

Output one of the placements with minimal height.

Charcoal, 115 112 bytes

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ÷×÷⊖X⁴ι²X²κX²ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online! Link is to verbose version of code. Explanation:

≔⟦⟦⟦⟧⟦⟧⟧⟧η

Start with no mushrooms placed.

FEθ÷×÷⊖X⁴ι²X²κX²ι

For each mushroom, calculate a bitmask corresponding to the space that it occupies. Edit: Saved 3 bytes by using my golf to @Arnauld's formula.

¿ι«

If this mushroom occupies space, then:

≔⟦⟧ζ

Start collecting placements that include this mushroom.

Fη«

Loop over the existing placements.

≔§κ¹ε

Get the bitmasks for the heights as this gets used a lot.

FΦLε¬&§ελι

Find whether this mushroom can be placed at any existing height.

⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧

Generate a placement for putting this mushroom at that height.

⊞§κ⁰Lε⊞ει⊞ζκ

Generate a placement for putting this mushroom at a new height.

»≔ζη

Save the new placements as the current placements.

»Fη⊞§κ⁰¦⁰

If this mushroom occupies no space then place it at zero height.

≔EηL⊟ιζ

Get the heights of all of the placements.

I§η⌕ζ⌊ζ

Output one of the placements with minimal height.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 115 bytes

≔⟦⟦⟦⟧⟦⟧⟧⟧ηFEθ∧ι⁻X²⁺κι⌈∕X²κX²⊖ι¿ι«≔⟦⟧ζFη«≔§κ¹εFΦLε¬&§ελι⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧⊞§κ⁰Lε⊞ει⊞ζκ»≔ζη»Fη⊞§κ⁰¦⁰≔EηL⊟ιζI§η⌕ζ⌊ζ

Try it online! Link is to verbose version of code. Explanation:

≔⟦⟦⟦⟧⟦⟧⟧⟧η

Start with no mushrooms placed.

FEθ∧ι⁻X²⁺κι⌈∕X²κX²⊖ι

For each mushroom, calculate a bitmask corresponding to the space that it occupies.

¿ι«

If this mushroom occupies space, then:

≔⟦⟧ζ

Start collecting placements that include this mushroom.

Fη«

Loop over the existing placements.

≔§κ¹ε

Get the bitmasks for the heights as this gets used a lot.

FΦLε¬&§ελι

Find whether this mushroom can be placed at any existing height.

⊞ζ⟦⁺§κ⁰⟦λ⟧Eε⎇⁼νλ⁺μιμ⟧

Generate a placement for putting this mushroom at that height.

⊞§κ⁰Lε⊞ει⊞ζκ

Generate a placement for putting this mushroom at a new height.

»≔ζη

Save the new placements as the current placements.

»Fη⊞§κ⁰¦⁰

If this mushroom occupies no space then place it at zero height.

≔EηL⊟ιζ

Get the heights of all of the placements.

I§η⌕ζ⌊ζ

Output one of the placements with minimal height.