Skip to content

Instantly share code, notes, and snippets.

View 4toblerone's full-sized avatar

Sasa Trifunovic 4toblerone

View GitHub Profile
@4toblerone
4toblerone / Solution.java
Last active September 8, 2021 20:25
Solution to the next smallest number
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
/*
* Given a Long number N, write a function that calculates the highest number lower than N obtained by permute only one digit of N.
* If no permutation exists to return a lower value, return N.
* Example:
* N = 153
* permuteToPrevious(N) = 135
$("#upload_btn").click(function(){
var fileIn = $("#fileToUpload")[0];
if (fileIn.files === undefined || fileIn.files.length == 0) {
alert("Please select a file");
return;
}
var file = fileIn.files[0];
var fotka = new FormData()
class MathOpThree(object):
def sum(self, node):
if len(node.childrens) == 2:
print node.getTokenValue()
#node.setTokenValue(self.sum(node.childrens[0]).getTokenValue() + self.sum(node.childrens[1]).getTokenValue())
node.setTokenValue(self.doMathOperation(node.getTokenType(), self.sum(node.childrens[0]).getTokenValue(), self.sum(node.childrens[1]).getTokenValue()))
return node
def doMathOperation(self, mathOpString, tokenValue1, tokenValue2):
"""def composeAST(self):
tokenPosition = -1
for token in self.listOfTokens:
#tracks position of the current token we are inspecting
tokenPosition += 1
# if we are dealing with numbers and have two ASTNodes on the childrenStack
# we should form a mini/subtree because by the time we have two "children" nodes
# we must have at least one "parent" node , which is enough for mini/sub tree
if token.type == "NUMBER" and len(self.childrenStack) < 3 :
numberToken = ASTNode(token)
mathOpPlusMinus = 'PLUS', 'MINUS' , 1
mathOpTimesDivide = 'TIMES', 'DIVIDE' , 2
childrenStack = []
higherChildrenStack = []
parentStack = []
astlist = []
def composeASTWithList(self,util):
tokenPosition = 0
if tokenPosition == len(self.listOfTokens)-1 :
return None
else:
util.append(self.listOfTokens[tokenPosition+1])
util.append(self.listOfTokens[tokenPosition])
def composeASTWithList(self,util):
tokenPosition = 0
if tokenPosition == len(self.listOfTokens)-1 :
return None
else:
util.append(self.listOfTokens[tokenPosition+1])
util.append(self.listOfTokens[tokenPosition])
util.append([])
self.composeASTWithList(util[2])
@4toblerone
4toblerone / gist:3755552
Created September 20, 2012 12:14
Validator
package net.netm.portals.tapestry.kino.services.impl;
import net.netm.platform.auxiliary.backendbox.exception.BackendboxAccessException;
import net.netm.platform.auxiliary.backendbox.model.AvsPinResponse;
import net.netm.platform.auxiliary.backendbox.service.AvsService;
import net.netm.platform.client.tapestry.core.services.MsisdnSource;
import net.netm.portals.tapestry.kino.services.PinValidator;
public class PinValidatorImpl implements PinValidator {
@4toblerone
4toblerone / gist:3755398
Created September 20, 2012 11:34
Spock test
import net.netm.platform.auxiliary.backendbox.exception.BackendboxAccessException;
import net.netm.platform.auxiliary.backendbox.service.AvsService;
import net.netm.portals.tapestry.kino.services.PinValidator;
import net.netm.portals.tapestry.kino.services.impl.PinValidatorImpl
import spock.lang.Specification
class PinValidatorImplTest extends Specification{
'''
Created on Aug 6, 2012
@author: Sasa Trifunovic
I should write test(s) so i could be sure every one of theme is working
as i intended them to do!!!
'''