Last active
October 7, 2018 18:03
-
-
Save sirinath/ae7549c5f9635c9c597cda990468f88b to your computer and use it in GitHub Desktop.
RunGopher Programming Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: beakerx | |
channels: | |
- conda-forge | |
dependencies: | |
- ipywidgets | |
- beakerx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Path: C:\\Users\\HP\\Documents\\BeakerX\\\n", | |
"File: RunGopherProgrammingChallenge.txt\n", | |
"hat\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"aht, ath, hat, hta, " | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"abc\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"abc, acb, bac, bca, " | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Zu6\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"6Zu, 6uZ, Z6u, Zu6, " | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"Done!" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"package com.rungopher.challenge;\n", | |
"\n", | |
"import java.nio.file.Files;\n", | |
"import java.nio.file.Path;\n", | |
"import java.nio.file.Paths;\n", | |
"import java.nio.charset.Charset;\n", | |
"\n", | |
"import java.io.IOException;\n", | |
"\n", | |
"import java.util.List;\n", | |
"import java.util.Arrays;\n", | |
"\n", | |
"String[] args = new String[] {\"C:\\\\Users\\\\HP\\\\Documents\\\\BeakerX\\\\RunGopherProgrammingChallenge.txt\"};\n", | |
"String arg0 = null;\n", | |
"\n", | |
"if (args.length == 1) {\n", | |
" arg0 = args[0];\n", | |
"} else {\n", | |
" throw new RuntimeException(\"Malformed argument: \" + arg0 + \", expecting file name with path.\");\n", | |
"}\n", | |
"\n", | |
"int slash = arg0.lastIndexOf(\"\\\\\");\n", | |
"int argLen = arg0.length();\n", | |
"\n", | |
"String file = null;\n", | |
"String path = \"\";\n", | |
"\n", | |
"if (slash < 0) {\n", | |
" file = arg0;\n", | |
"} else {\n", | |
" if (slash + 1 < argLen) {\n", | |
" path = arg0.substring(0, slash + 1);\n", | |
" file = arg0.substring(slash + 1);\n", | |
" } else {\n", | |
" throw new RuntimeException(\"Malformed argument: \" + arg0 + \", expecting file name with path.\");\n", | |
" }\n", | |
"}\n", | |
"\n", | |
"System.err.println(\"Path: \" + path);\n", | |
"System.err.println(\"File: \" + file);\n", | |
"\n", | |
"List<String> lines = Files.readAllLines(Paths.get(path, file), Charset.forName(\"UTF-8\"));\n", | |
" \n", | |
"for (String line : lines) {\n", | |
" System.err.println(line);\n", | |
" \n", | |
" char[] chars = line.toCharArray();\n", | |
" \n", | |
" Arrays.sort(chars);\n", | |
" \n", | |
" char[] cpyc = chars.clone();\n", | |
" \n", | |
" System.out.print(new String(chars));\n", | |
" System.out.print(\", \");\n", | |
" \n", | |
" int n = chars.length - 1;\n", | |
" int m = n - 1;\n", | |
" for (int i = m; i >= 0; i--) {\n", | |
" System.arraycopy(cpyc, 0, chars, 0, cpyc.length);\n", | |
" \n", | |
" for (int j = i; j <= m; j++) {\n", | |
" char tmp = chars[j + 1];\n", | |
" chars[j + 1] = chars[j];\n", | |
" chars[j] = tmp;\n", | |
"\n", | |
" System.out.print(new String(chars));\n", | |
" System.out.print(\", \");\n", | |
" }\n", | |
" \n", | |
" char tmp = chars[j + 1];\n", | |
" chars[j + 1] = chars[j];\n", | |
" chars[j] = tmp;\n", | |
" \n", | |
" for (int j = i + 1; j <= m; j++) {\n", | |
" char tmp = chars[j + 1];\n", | |
" chars[j + 1] = chars[j];\n", | |
" chars[j] = tmp;\n", | |
"\n", | |
" System.out.print(new String(chars));\n", | |
" System.out.print(\", \");\n", | |
" }\n", | |
" }\n", | |
"}\n", | |
"\n", | |
"\n", | |
"return \"Done!\";" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Java", | |
"language": "java", | |
"name": "java" | |
}, | |
"language_info": { | |
"codemirror_mode": "text/x-java", | |
"file_extension": ".java", | |
"mimetype": "", | |
"name": "Java", | |
"nbconverter_exporter": "", | |
"version": "1.8.0_152-release" | |
}, | |
"toc": { | |
"base_numbering": 1, | |
"nav_menu": {}, | |
"number_sections": false, | |
"sideBar": false, | |
"skip_h1_title": false, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": false, | |
"toc_window_display": false | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hat | |
abc | |
Zu6 | |
come | |
eight |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment