JSFiddle - React, Tailwind, and code Playground

by TimWolla

HTML

<textarea id="in" rows="10" cols="40">YRYGR
grG
GyRyGyG
pbgbrgrp
aaaaaaaa
hyghgy</textarea><br />
<textarea id="out" disabled="disabled" rows="10" cols="40"></textarea>

CoffeeScript

x=(s,c='')->return 0if !s[0]?;return x s[1..],c if s[0]is c;l=s.length;return x s[1...l],c if s[l-1]is c;i=s.lastIndexOf s[0];1+(x s[1...i],s[0])+x s[i+1..],c
y=(z)->z=z.split "";Math.min (x z),x z.reverse()

$('#in').on 'keyup keydown keypress', ->
 input = $('#in').val().split /\n/
 out = ''
 for stick in input
   out += y stick
   out += "\n"
 $('#out').val out
$('#in').keyup()