initial unoptimized(SLOOWWWW) ruby implementation