Skip to content

Instantly share code, notes, and snippets.

View Cyberster's full-sized avatar
😎
A programmer guy with a soldering iron!

Arpan Das Cyberster

😎
A programmer guy with a soldering iron!
View GitHub Profile
@Cyberster
Cyberster / Combination.java
Last active January 27, 2019 16:53
Generates all possible combinations from given symbols
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
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;
}
}
@Cyberster
Cyberster / array_element_difference.c
Last active September 24, 2018 14:19
Generates array difference between two arrays of any type
#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
@Cyberster
Cyberster / permutation.c
Created September 26, 2018 08:35
It generates permutations of array of strings (as symbols)
#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));
}
@Cyberster
Cyberster / 1D_Array_in_2D_Array_Search.c
Created September 28, 2018 06:10
This function searches a 1D string array within another 2D string array
/**
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
*/
@Cyberster
Cyberster / LeapYear.java
Created October 4, 2018 09:32
Method to get a year leap year or not for both Gregorian and Julian Calendar
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
@Cyberster
Cyberster / Permutations.java
Last active November 3, 2018 10:02
Permutations in java version2
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<>();
@Cyberster
Cyberster / AllSubStrings.java
Last active January 31, 2019 08:49
Get all possible substrings in java
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));
}
}
@Cyberster
Cyberster / MeanMedianMode.java
Last active January 21, 2021 22:30
Get mean, median, and mode from array of integers in java.
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;
@Cyberster
Cyberster / integrate.c
Created December 26, 2018 07:21
Integrate using simpson's 1/3rd rule in C
#include <stdio.h>
#include <math.h>
#include <malloc.h>
// defining the function f(x)
double f (double x) {
//return log(x);
return x*x;
}