[Snark] Ruby Longest word in english is 34 characters

Graham Cooper submissions at badcode.rocks
Fri Oct 26 00:48:57 UTC 2018


I wrote all of the code then realized that I couldn't handle multiple words
on one line...so that functionality does not exist and the test was changed
appropriately.

== License ==

This code was created by me, Graham Cooper and I place it under CCO.

== Editor Notes ==

This submission fails the final test, and also your working directory must 
be empty for it to run properly.

== piglatin.rb ==

#!/usr/bin/ruby

word = ARGV[0]

def get_number_files
  Dir.entries(".").select { |f| f != "." && f != ".." && f != "piglatin.rb" && f != "test.sh" && f != "dothing.sh" }.sort
end

def ay_end
  f0 = File.new("%02d" % (get_number_files.last.to_i + 1), "w")
  f0.write("a")
  f0.close
  f1 = File.new("%02d" % (get_number_files.last.to_i + 1), "w")
  f1.write("y")
  f1.close
end

def move_letter_last(place)
  File.rename("%02d" % place, "%02d" % (get_number_files.last.to_i + 1))
end

# Longest word in english is 34 characters, (Supercalifragilisticexpialidocious)

f0 = File.new("00", "w")
f0.write(ARGV[0][0]) if word.length > 0
f0.close

(1..34).each do |num|
  if word.length > get_number_files.last.to_i + 1
    file = File.new("%02d" % num, "w")
    file.write(ARGV[0][num])
    file.close
  end
end

first_letter_vowel = false
first_letter_x = false
first_letter_y = false
first_letter_c = false
first_letter_q = false
first_letter_s = false
first_letter_cons = false
first_letter_t = false

already_moved = false

File.open("00", "r") do |file|
  file.each_line do |line|
    if line == "A" || line == "E" || line == "I" || line == "O" || line == "U" || line == "a" || line == "e" || line == "i" || line == "o" || line == "u" 
      first_letter_vowel = true 
    elsif line == "x" || line == "X"
      first_letter_x = true
    elsif line == "y" || line == "Y"
      first_letter_y = true
    elsif line == "c" || line == "C"
      first_letter_c = true
      first_letter_cons
    elsif line == "s" || line == "S"
      first_letter_s = true
      first_letter_cons = true
    elsif line == "q" || line == "Q"
      first_letter_q = true
      first_letter_cons = true
    elsif line == "t" || line == "T"
      first_letter_t = true
      first_letter_cons = true
    else
      first_letter_cons = true
      move_letter_last(0)
      ay_end
      already_moved = true
    end
  end
end

first_two_sc = false
second_q_first_cons = false
second_h_first_t = false

if word.length > 1 && !already_moved
  File.open("01", "r") do |file|
    file.each_line do |line|
      if (line == "r" || line == "R") && first_letter_x
        ay_end
      elsif (line == "t" || line == "T") && first_letter_y
        ay_end
      elsif (line == "u" || line == "U") && first_letter_q
        move_letter_last(0)
        move_letter_last(1)
        ay_end
      elsif (line == "q" || line == "Q") && first_letter_cons
        second_q_first_cons = true  
      elsif (line == "h" || line == "H") && first_letter_c
        move_letter_last(0)
        move_letter_last(1)
        ay_end
      elsif (line == "h" || line == "H") && first_letter_t
        second_h_first_t = true
      elsif (line == "c" || line == "c") && first_letter_s
        first_two_sc = true 
      elsif first_letter_y
        move_letter_last(0)
        ay_end
      elsif first_letter_x
        move_letter_last(0)
        ay_end
      elsif first_letter_q
        move_letter_last(0)
        ay_end
      elsif first_letter_t
        move_letter_last(0)
        ay_end
      else
        ay_end
      end
    end
  end   
elsif first_letter_vowel
  ay_end
end

if word.length > 2 && (first_two_sc || second_q_first_cons || second_h_first_t)
  File.open("02", "r") do |file|
    file.each_line do |line|
      if (line == "h" || line == "H") && first_two_sc
        move_letter_last(0)
        move_letter_last(1)
        move_letter_last(2)
        ay_end
      elsif (line == "u" || line == "U") && second_q_first_cons
        move_letter_last(0)
        move_letter_last(1)
        move_letter_last(2)
        ay_end
      elsif (line == "r" || line == "R") && second_h_first_t
        move_letter_last(0)
        move_letter_last(1)
        move_letter_last(2)
        ay_end
      elsif second_h_first_t
        move_letter_last(0)
        move_letter_last(1)
        ay_end
      else
        move_letter_last(0)
        ay_end
      end
    end
  end
end

get_number_files.each do |file|
  print File.read(file)
  File.delete(file)
end
puts ""


More information about the Snark mailing list