Inspired by this challenge


The goal is to draw waves crashing onto a beach.


You will be given 3 integers (in whatever format you want) as input.
The first integer will be the length of the drawing The second integer will be the index of the sandbar, where the waves start to crest (at least 3 spaces from beach)
The third integer will be the spacing between waves (at least 3, can be greater than length of drawing, in which case you only draw one wave)


The output will be a box of characters which shows the waves crashing into the beach. The drawing should end when the first wave has completed crashing into the beach.

At first, the wave is shown as a swell (_-_).
As the wave passes the sandbar, it starts to crest (/c_).
Finally, the wave crashes into the beach (/c. => _-_ => ___ => __. ).


Input: 14 4 6



Input: 10, 2, 11



Input: 6 0 3



Standard Loopholes apply

This is so shortest code wins

  • 2
    \$\begingroup\$ · is not ASCII, which may exclude some languages. Can it be replaced by .? \$\endgroup\$
    – Luis Mendo
    Commented Feb 14, 2017 at 15:23
  • \$\begingroup\$ @LuisMendo The beach is supposed to be the ASCII period. The example of wave crashing into the beach is due to the period being practically invisible otherwise. \$\endgroup\$ Commented Feb 14, 2017 at 17:00
  • 1
    \$\begingroup\$ Which leads me to the opposite question: can we use · instead of the ASCII period? (It's actually a rather big win in my code.) \$\endgroup\$
    – Arnauld
    Commented Feb 14, 2017 at 17:12
  • \$\begingroup\$ Using either or should be fine. The idea is that the code output appears consistent with the example outputs. \$\endgroup\$ Commented Feb 14, 2017 at 17:14

2 Answers 2


JavaScript (ES6), 250 243 bytes

This code is assuming code page #1252 and is using the · character (0xB7). Takes input as 3 distinct parameters (a,b,c).


How it works

This code starts with a string such as -______·· and applies successive regular expressions on each iteration to animate the waves.

For instance -__ is replaced with _-_.

At first, it looked like a reasonable idea. However, the fact that the string may start with a c (like it does in the 3rd test case) makes things significantly more complicated.

Test cases

f =


console.log(f(14, 4, 6))
console.log(f(10, 2, 11))
console.log(f(6, 0, 3))


Batch, 273 243 bytes

@echo off
set f=for /l %%i in (0,1,%1)do call
set s=set b=
%f% %s%_%%b%%
%f%:c %%i %2 %3
if %w%==0 %s%__-%b:~3%
if %w%==%2 %s%%b:_-=/c%
%s%%b:__. =_.. %
echo %b:~3%

Note: Trailing space on line 4. If only the two beach characters were different, I could save 3 bytes and actually beat JavaScript!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.