generated from fastai/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
359 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
make --dry-run --always-make --keep-going --print-directory | ||
make: Entering directory `/Users/rohitde/vscode/rohitfastpages' | ||
cat Makefile | ||
|
||
make: Leaving directory `/Users/rohitde/vscode/rohitfastpages' | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,356 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "java" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Remainder: 4\n", | ||
"Number: 1570\n", | ||
"Remainder: 0\n", | ||
"Number: 157\n", | ||
"Remainder: 7\n", | ||
"Number: 15\n", | ||
"Remainder: 5\n", | ||
"Number: 1\n", | ||
"Remainder: 1\n", | ||
"Number: 0\n", | ||
"15704\n", | ||
"0\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import java.util.*;\n", | ||
"import java.lang.*;\n", | ||
"\n", | ||
"public class Digits {\n", | ||
"\n", | ||
" private ArrayList<Integer> digitList;\n", | ||
"\n", | ||
" public Digits(int num){\n", | ||
"\n", | ||
" digitList = new ArrayList<Integer>();\n", | ||
"\n", | ||
" int remainderNum = 0;\n", | ||
"\n", | ||
" if(num != 0){\n", | ||
" while(num != 0){\n", | ||
"\n", | ||
" remainderNum = num % 10;\n", | ||
" System.out.println(\"Remainder: \"+ remainderNum);\n", | ||
" digitList.add(0,remainderNum);\n", | ||
" num = num / 10;\n", | ||
" System.out.println(\"Number: \" + num);\n", | ||
" \n", | ||
" }\n", | ||
" }else{\n", | ||
" digitList.add(num);\n", | ||
" }\n", | ||
"\n", | ||
" }\n", | ||
"\n", | ||
" public String toString(){\n", | ||
" \n", | ||
" String digitListPrint = \"\";\n", | ||
"\n", | ||
" for(int i = 0; i < digitList.size(); i++){\n", | ||
" digitListPrint+=digitList.get(i);\n", | ||
" } \n", | ||
" return digitListPrint;\n", | ||
" }\n", | ||
"\n", | ||
" public static void main(String[] args){\n", | ||
" Digits d1 = new Digits(15704);\n", | ||
" System.out.println(d1);\n", | ||
"\n", | ||
" Digits d2 = new Digits(0);\n", | ||
" System.out.println(d2);\n", | ||
"\n", | ||
" }\n", | ||
"\n", | ||
"}\n", | ||
"Digits.main(null);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "java" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"public interface StudyPractice{ // defintion of the method is given, not the implementation\n", | ||
" String getProblem();\n", | ||
"\n", | ||
" void nextProblem();\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "java" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"7 TIMES 3\n", | ||
"7 TIMES 4\n", | ||
"7 TIMES 5\n", | ||
"7 TIMES 6\n", | ||
"4 TIMES 13\n", | ||
"4 TIMES 13\n", | ||
"4 TIMES 15\n", | ||
"4 TIMES 16\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"public class MultPractice implements StudyPractice {\n", | ||
"\n", | ||
" private int firstInt = 0;\n", | ||
" private int secondInt = 0;\n", | ||
"\n", | ||
" public MultPractice(int firstInt, int secondInt){\n", | ||
" this.firstInt = firstInt;\n", | ||
" this.secondInt = secondInt;\n", | ||
" }\n", | ||
" \n", | ||
" public String getProblem(){\n", | ||
" return firstInt + \" TIMES \" + secondInt;\n", | ||
" }\n", | ||
"\n", | ||
" public void nextProblem(){\n", | ||
" secondInt+=1;\n", | ||
" }\n", | ||
"\n", | ||
" public static void main(String[] args){\n", | ||
" StudyPractice p1 = new MultPractice(7, 3);\n", | ||
" System.out.println(p1.getProblem());\n", | ||
"\n", | ||
" p1.nextProblem();\n", | ||
" System.out.println(p1.getProblem());\n", | ||
"\n", | ||
" p1.nextProblem();\n", | ||
" System.out.println(p1.getProblem()); \n", | ||
"\n", | ||
" p1.nextProblem();\n", | ||
" System.out.println(p1.getProblem());\n", | ||
"\n", | ||
"\n", | ||
" StudyPractice p2 = new MultPractice(4, 12);\n", | ||
" p2.nextProblem();\n", | ||
" \n", | ||
" System.out.println(p2.getProblem());\n", | ||
" System.out.println(p2.getProblem());\n", | ||
" p2.nextProblem();\n", | ||
" p2.nextProblem();\n", | ||
" System.out.println(p2.getProblem());\n", | ||
" p2.nextProblem();\n", | ||
" System.out.println(p2.getProblem());\n", | ||
" }\n", | ||
" \n", | ||
"\n", | ||
"}\n", | ||
"MultPractice.main(null);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "java" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"t ate late.\n", | ||
"2\n", | ||
"te late.\n", | ||
"4\n", | ||
"te.\n", | ||
"-1\n", | ||
"Last occurrence: 11\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"public class Phrase{\n", | ||
"\n", | ||
" private String currentPhrase = \"\";\n", | ||
"\n", | ||
" public Phrase(String p){\n", | ||
" currentPhrase = p;\n", | ||
" }\n", | ||
"\n", | ||
" public int findNthOccurrence(String str, int n){\n", | ||
" return 3;\n", | ||
" }\n", | ||
"\n", | ||
" public void replaceNthOccurrence(String str, int n, String repl){\n", | ||
" int indexOccurence = findNthOccurrence(str, n);\n", | ||
"\n", | ||
" if(indexOccurence != -1){\n", | ||
" String str1 = currentPhrase.substring(0, indexOccurence);\n", | ||
" String str2 = currentPhrase.substring(indexOccurence + str.length());\n", | ||
" currentPhrase = str1 + repl + str2;\n", | ||
" }\n", | ||
" }\n", | ||
"\n", | ||
" public int findLastOccurrence(String str){\n", | ||
" \n", | ||
" String newPhrase = new String(currentPhrase);\n", | ||
" int n = currentPhrase.indexOf(str);\n", | ||
" \n", | ||
" int lastIndex = 0;\n", | ||
"\n", | ||
" while(n != -1){\n", | ||
"\n", | ||
" newPhrase = newPhrase.substring(n+1);\n", | ||
" System.out.println(newPhrase);\n", | ||
" n = newPhrase.indexOf(str);\n", | ||
" System.out.println(n);\n", | ||
" }\n", | ||
"\n", | ||
" if(newPhrase.length() != 0){\n", | ||
" lastIndex = currentPhrase.length() - newPhrase.length() -1;\n", | ||
" System.out.println(\"Last occurrence: \" + lastIndex);\n", | ||
" return lastIndex;\n", | ||
" } else {\n", | ||
" System.out.println(\"Last occurrence: -1\");\n", | ||
" return -1;\n", | ||
" }\n", | ||
" }\n", | ||
"\n", | ||
"\n", | ||
" public String toString(){\n", | ||
" return \"Phrase: \" + currentPhrase;\n", | ||
" }\n", | ||
"\n", | ||
" public static void main(String[] args){\n", | ||
" Phrase phrase1 = new Phrase(\"A cat ate late.\");\n", | ||
" phrase1.replaceNthOccurrence(\"at\", 1, \"rane\");\n", | ||
" // System.out.println(new String(\"A cat ate late.\").length());\n", | ||
" Phrase phrase2 = new Phrase(\"A cat ate late.\");\n", | ||
" phrase2.findLastOccurrence(\"at\");\n", | ||
" }\n", | ||
"\n", | ||
"}\n", | ||
"Phrase.main(null);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "java" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"row: 2 column: 1\n", | ||
"row: 0 column: 0\n", | ||
"null\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"public class Position{\n", | ||
"\n", | ||
" // int[][] intArr = { { 15, 5, 9 ,10 }, { 12, 16, 11, 6 }, { 14, 8, 13, 7}};\n", | ||
"\n", | ||
" private int row = 0;\n", | ||
" private int col = 0;\n", | ||
"\n", | ||
"\n", | ||
" public Position(int r, int c){\n", | ||
" row = r;\n", | ||
" col = c;\n", | ||
" }\n", | ||
"\n", | ||
" public static Position findPosition(int num, int[][] intArr){\n", | ||
" for(int i = 0; i < intArr.length; i++){\n", | ||
" for(int g = 0; g < intArr[i].length; g++){\n", | ||
" if(intArr[i][g] == num){\n", | ||
" System.out.println(\"row: \" + i + \" column: \" + g);\n", | ||
" return new Position(i, g);\n", | ||
" }\n", | ||
"\n", | ||
" }\n", | ||
" }\n", | ||
" System.out.println(\"null\");\n", | ||
" return null;\n", | ||
" }\n", | ||
"\n", | ||
" public static Position[][] getSuccessorArray(int[][] intArr){\n", | ||
" Position[][] posArray = new Position[intArr.length][intArr[0].length];\n", | ||
" for(int i = 0; i < intArr.length; i++){\n", | ||
" for(int g = 0; g < intArr[i].length; g++){\n", | ||
" posArray[i][g] = findPosition(intArr[i][g] + 1, intArr);\n", | ||
" }\n", | ||
" } \n", | ||
" return posArray;\n", | ||
" }\n", | ||
"\n", | ||
"\n", | ||
" public static void main(String[] args){\n", | ||
" int[][] intArr = { { 15, 5, 9 ,10 }, { 12, 16, 11, 6 }, { 14, 8, 13, 7}};\n", | ||
" Position.findPosition(8, intArr);\n", | ||
" Position.findPosition(15, intArr);\n", | ||
" Position.findPosition(17, intArr);\n", | ||
" }\n", | ||
"\n", | ||
"}\n", | ||
"Position.main(null);" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Java", | ||
"language": "java", | ||
"name": "java" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "java", | ||
"file_extension": ".jshell", | ||
"mimetype": "text/x-java-source", | ||
"name": "Java", | ||
"pygments_lexer": "java", | ||
"version": "19.0.2+7-44" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |