Skip to main content
added 2313 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

33 bytes for a more efficient version that can suffer from floating-point inaccuracy:

NθIE⟦¹±¹⟧×ι⌈E₂θ×ιX×ι⌊×ιXθ∕¹⁺²λ⁺²λ 

Try it online! Link is to verbose version of code. Explanation: Port of @bsolech's golf to @corvus_192's Python answer.

Nθ Input `N` as a number ¹ Literal integer `1` ¹ Literal integer `1` ± Negated ⟦ ⟧ Make into list E Map over units θ Input `N` ₂ Square root E Map over implicit range θ Input `N` X Raised to power ¹ Literal integer `1` ∕ Divided by λ Current value ⁺ Plus ² Literal integer `2` × Multiplied by ι Current unit ⌊ Floored to integer × Multiplied by ι Current unit X Raised to power λ Current value ⁺ Plus ² Literal integer `2` × Multiplied by ι Current unit ⌈ Take the maximum × Multiplied by ι Current unit I Cast to string Implicitly print 

33 bytes for a more efficient version that can suffer from floating-point inaccuracy:

NθIE⟦¹±¹⟧×ι⌈E₂θ×ιX×ι⌊×ιXθ∕¹⁺²λ⁺²λ 

Try it online! Link is to verbose version of code. Explanation: Port of @bsolech's golf to @corvus_192's Python answer.

Nθ Input `N` as a number ¹ Literal integer `1` ¹ Literal integer `1` ± Negated ⟦ ⟧ Make into list E Map over units θ Input `N` ₂ Square root E Map over implicit range θ Input `N` X Raised to power ¹ Literal integer `1` ∕ Divided by λ Current value ⁺ Plus ² Literal integer `2` × Multiplied by ι Current unit ⌊ Floored to integer × Multiplied by ι Current unit X Raised to power λ Current value ⁺ Plus ² Literal integer `2` × Multiplied by ι Current unit ⌈ Take the maximum × Multiplied by ι Current unit I Cast to string Implicitly print 
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 30 bytes

NθFθFθ⊞υX⊕ι⁺²κI⟦⌈Φυ¬›ιθ⌊Φυ¬‹ιθ 

Try it online! Link is to verbose version of code. Explanation: Port of @Guiseppe's R answer.

Nθ 

Input n.

FθFθ⊞υX⊕ι⁺²κ 

Generate a list of perfect powers from to nⁿ⁺¹.

I⟦⌈Φυ¬›ιθ⌊Φυ¬‹ιθ 

Find the largest one not greater than n and the smallest one not less than n.

42 bytes for a less inefficient version:

NθFE⊕₂θX⊕ι…·²⎇ιL↨θ⊕ι²Fι⊞υκI⟦⌈Φυ¬›ιθ⌊Φυ¬‹ιθ 

Try it online! Link is to verbose version of code. Explanation: As above but only loops up to ⌊√n⌋ and only powers up to 1+⌊logᵢn⌋ (or 2 if i=1).