Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
stephen-maina / hanoi.py
Created January 20, 2019 11:58
Tower of Hanoi
def solveHanoi(blockNumber, rodFrom, middleRod,rodTo):
if(blockNumber==1):
print("Plate {0} from {1} to {2}".format(blockNumber,rodFrom,rodTo));
return;
solveHanoi(blockNumber-1, rodFrom,rodTo,middleRod);
print("outside: Plate {0} from {1} to {2}".format(blockNumber,rodFrom,rodTo));
solveHanoi(blockNumber-1, middleRod,rodFrom ,rodTo);
@stephen-maina
stephen-maina / cyclicRotation.py
Created August 24, 2018 08:52
Codility Lesson 2
def solution(A, K):
outputArray=[0]*len(A);
for index in range(len(A)):
outputIndex=(index+K)%len(A);
outputArray[outputIndex]=A[index];
return outputArray;
@stephen-maina
stephen-maina / iterations.py
Created August 24, 2018 08:35
Codility Lesson 1
def solution(N):
# write your code in Python 3.6
binaryNumber=bin(N);
binaryGap=0;
data=str(binaryNumber);
finalList=[];
dataList=[];
#print(data);
for index in range(len(data)):
if(data[index]=="1" and "1" in dataList and "0" in dataList):
global type gf_resize from function_object
end type
forward prototypes
global function integer gf_resize (any variable_array, any constant_array)
end prototypes
global function integer gf_resize (any variable_array, any constant_array);/*
NAME:smaina
ISSUE:ZMES-317
global type gr_resize_objects from function_object
end type
forward prototypes
global function integer gr_resize_objects (any str_array_objects, integer workspace_width, integer workspace_height)
end prototypes
global function integer gr_resize_objects (any str_array_objects, integer workspace_width, integer workspace_height);
str_resize_objects objects []
str_constant constants []
st_variable resizables []
constants =constant_array
resizables = variable_array
integer index_c,index_r
/*
used to get all the graphical objects that are to remain at a relative similar position
as before resizing
*/
for index_c=1 to UpperBound(constants)
@stephen-maina
stephen-maina / elasticsearch java code snippets
Created June 15, 2015 06:50
elasticsearch java code snippets
private boolean deleteIndex(String indexName, String typeName, String id) {
if (isIndexExist(indexName)) {
System.out.println("INDEX EXISTS>>>DELETE INDEX");
return NodeOperation.INSTANCE.getClient().prepareDelete(indexName, typeName, id).execute().actionGet()
.isFound();
} else {
return false;
}
var compare=function(user,comp){
if(user===comp){
return "The result is a tie!";
}else if(user==="rock"){
if(comp==="scissors"){
return "rock wins";
}else{
return "paper wins";
}
}else if(user==="paper"){
// Check if the user is ready to play!
confirm("Are you ready to play?");
var age=prompt("What is your age");
if(age<13){
console.log("You can play this game but the developers take no responsibility for your actions ")
}else{
console.log("Welcome");
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
import java.util.Set;
import java.util.HashSet;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
Set<Integer> abs=new HashSet<Integer>();
for(int index=0;index<A.length;index++){
abs.add( Math.abs(A[index]));
}
return abs.size();