This file contains hidden or 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
| package com.w3epic; | |
| import java.util.*; | |
| public class Combination<T> { | |
| // combinations = blank i.e. {} initially, currentLevel = 0 initially | |
| /* getCombinations(String symbols, int parent, List<Integer> combinations, int currentLevel, int targetLevel) | |
| * List<String> symbols: contains symbols like 1234 or abcd | |
| * List<String> parent: parent node which will be combined with the symbols, initially 0 | |
| * List<List<String>> combinations: its the data to be passed while calling, it'll carry the result, initially blank ArrayList(Integer) | |
| * int currentLevel: current level of tree i.e. current combination digit count, initially 0 |
This file contains hidden or 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
| public class Prime { | |
| public boolean isPrime (int input1) { | |
| if (1 == input1) return false; | |
| for (int i = 2; i <= Math.sqrt(input1); i++) { | |
| if (input1 % i == 0) { | |
| //System.out.println("1"); | |
| return false; | |
| } | |
| } |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <string.h> | |
| #include <math.h> | |
| #include <stdlib.h> | |
| #define TYPE char* | |
| /** | |
| * Generates array difference between two arrays of any type | |
| * author: Arpan Das |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #define TYPE char* | |
| unsigned long factorial(unsigned long f) { | |
| if (f == 0) return 1; | |
| return(f * factorial(f - 1)); | |
| } |
This file contains hidden or 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 function searches a 1D array within another 2D array | |
| author: Arpan Das | |
| date: 28-09-2018 | |
| char *** haystack - 2D string array | |
| char ** needle - 1D string array | |
| size_t hx_size - no of rows of haystack | |
| size_t hy_size - no of cols of haystack and no of elements of needle | |
| returns - 1 if found else 0 | |
| */ |
This file contains hidden or 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
| class LeapYear { | |
| /** | |
| * author: Arpan Das | |
| * date: 05-sept-2018 | |
| * int year - year | |
| * char calendarType - G = Gregorian calendar, J= Julian Calendar | |
| * returns boolean | |
| */ | |
| public static boolean isLeapYear(int year, char calendarType) { | |
| if (calendarType == 'J') { // Julian Calendar |
This file contains hidden or 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
| static void permute(List<String> symbols, List<String> permutations, int level) { | |
| if (level == symbols.size()) return; | |
| if (level == 0) { | |
| for (int i = 0; i < symbols.size(); i++) { | |
| permutations.add(symbols.get(i)); | |
| } | |
| permute(symbols, permutations, level + 1); | |
| } else { | |
| List<String> tempPerms = new ArrayList<>(); |
This file contains hidden or 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
| String n = sc.next(); | |
| Set<Integer> set = new HashSet<>(); // use set if you want unique else arraylist | |
| // method 1 | |
| for (int i = 0; i < n.length(); i++) { | |
| for (int j = i; j < n.length(); j++) { | |
| String s = n.substring(i, j + 1); | |
| set.add(Integer.parseInt(s)); | |
| } | |
| } |
This file contains hidden or 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
| import java.io.*; | |
| import java.util.*; | |
| public class MeanMedianMode { | |
| public static double getMean(int[] arr) { | |
| double mean = 0; | |
| for (int i = 0; i < arr.length; i++) | |
| mean += arr[i]; | |
| mean /= arr.length; |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <math.h> | |
| #include <malloc.h> | |
| // defining the function f(x) | |
| double f (double x) { | |
| //return log(x); | |
| return x*x; | |
| } |
OlderNewer