Skip to content

Instantly share code, notes, and snippets.

@arianvp
Created April 23, 2013 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arianvp/5442976 to your computer and use it in GitHub Desktop.
Save arianvp/5442976 to your computer and use it in GitHub Desktop.
module Main
( main
) where
import System.Environment (getArgs)
main :: IO ()
main = putStrLn . unlines . (map (unwords .reverse . words)) . lines =<< readFile . head =<< getArgs
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
FileReader fileReader = new FileReader(args[0]);
try {
BufferedReader reader = new BufferedReader(fileReader);
String line;
while ((line = reader.readLine()) != null) {
String[] words = line.split("\\s+");
for (int i = words.length - 1; i >= 0; --i) {
System.out.print(words[i] + " ");
}
System.out.println();
}
} finally {
fileReader.close();
}
}
}
$<.each{ |line| puts line.split(/\s+/).reverse.join(' ') }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment