Skip to main content
added 157 characters in body
Source Link
marinus
  • 31.2k
  • 7
  • 71
  • 112

APL (35)

(Yes, it does fit in 35 bytes, here's a 1-byte APL encoding)

{∇⍵+⌈⎕DL.05⊣⎕←'|'↑⍨-21+⌈20×1○⍵×.1}1

Explanation:

  • {...}1: call the function with 1 at the beginning
  • 1○⍵×.1: close enough for government work to sin(⍵×π÷30). (1○ is sin).
  • -21+⌈20: normalize to the range 1..40 and negate
  • '|'↑⍨: take the last N characters from the string '|' (which results in a string of spaces with a | at the end
  • ⎕←: display
  • ⌈⎕DL.05: wait 50 ms and return 1. (⎕DL returns the amount of time it actually waited, which is going to be close to 0.05, rounding that value up gives 1).
  • ∇⍵+: add that number (1) to and run the function again.

APL (35)

{∇⍵+⌈⎕DL.05⊣⎕←'|'↑⍨-21+⌈20×1○⍵×.1}1

Explanation:

  • {...}1: call the function with 1 at the beginning
  • 1○⍵×.1: close enough for government work to sin(⍵×π÷30). (1○ is sin).
  • -21+⌈20: normalize to the range 1..40 and negate
  • '|'↑⍨: take the last N characters from the string '|' (which results in a string of spaces with a | at the end
  • ⎕←: display
  • ⌈⎕DL.05: wait 50 ms and return 1. (⎕DL returns the amount of time it actually waited, which is going to be close to 0.05, rounding that value up gives 1).
  • ∇⍵+: add that number (1) to and run the function again.

APL (35)

(Yes, it does fit in 35 bytes, here's a 1-byte APL encoding)

{∇⍵+⌈⎕DL.05⊣⎕←'|'↑⍨-21+⌈20×1○⍵×.1}1

Explanation:

  • {...}1: call the function with 1 at the beginning
  • 1○⍵×.1: close enough for government work to sin(⍵×π÷30). (1○ is sin).
  • -21+⌈20: normalize to the range 1..40 and negate
  • '|'↑⍨: take the last N characters from the string '|' (which results in a string of spaces with a | at the end
  • ⎕←: display
  • ⌈⎕DL.05: wait 50 ms and return 1. (⎕DL returns the amount of time it actually waited, which is going to be close to 0.05, rounding that value up gives 1).
  • ∇⍵+: add that number (1) to and run the function again.
Source Link
marinus
  • 31.2k
  • 7
  • 71
  • 112

APL (35)

{∇⍵+⌈⎕DL.05⊣⎕←'|'↑⍨-21+⌈20×1○⍵×.1}1

Explanation:

  • {...}1: call the function with 1 at the beginning
  • 1○⍵×.1: close enough for government work to sin(⍵×π÷30). (1○ is sin).
  • -21+⌈20: normalize to the range 1..40 and negate
  • '|'↑⍨: take the last N characters from the string '|' (which results in a string of spaces with a | at the end
  • ⎕←: display
  • ⌈⎕DL.05: wait 50 ms and return 1. (⎕DL returns the amount of time it actually waited, which is going to be close to 0.05, rounding that value up gives 1).
  • ∇⍵+: add that number (1) to and run the function again.