Skip to content

Instantly share code, notes, and snippets.

@epson121
epson121 / ostablo.cpp
Last active September 24, 2015 15:07
Binarno stablo -> polja
#include <iostream>
using namespace std;
struct cvor
{
int oznaka;
int PrvoDijete;
int SljedeciBrat;
};
@epson121
epson121 / binarno_stablo.cpp
Last active September 24, 2015 16:47
binarno stablo -> pokazivaci
#include <iostream>
using namespace std;
struct cvor
{
int oznaka;
int PrvoDijete;
int SljedeciBrat;
bool koristeno;
};
'''
Write code that will print ten astrisks (*) like the following:
* * * * * * * * * *
'''
print("first");
for i in range (10):
print ("*", end = " ");
'''
Write code that will print the following:
#First enter rails console:
$rails console
#Then just type:
ActiveRecord::Migration.drop_table(:users)
Where :users is the table name.
'''
Caesar cipher with a swap by 3
2 implementations
'''
def c(s)
s.split("").map{|s|(65+(s.ord+16)%26).chr}.join()
end
def c2(s)
@epson121
epson121 / rot_13.rb
Last active December 11, 2015 10:28
'''
Rot13 implementation in ruby
21.01.2013.
'''
def a(s)
s.tr("A-MN-Z","N-ZA-M")
end
p a("ASDDSAZZZ")
@epson121
epson121 / tree_traversal.cpp
Last active December 14, 2015 03:09
tree traversal algorithms
/*
* Simple tree traversal algorithms (preorder, inorder and postorder)
* on a small binary tree with 5 nodes.
*
*/
#include <iostream>
#include <cstdlib>
using namespace std;
@epson121
epson121 / bs_tree_size.cpp
Created February 23, 2013 10:49
BS-tree size solved with and without additional memory.
/*
* BS-tree size solved with and without additional memory.
*
*/
#include <iostream>
#include <cstdlib>
using namespace std;
@epson121
epson121 / Palantir.java
Last active December 14, 2015 21:59
Variable-Base Expression Evaluation http://www.palantir.com/challenge/
/*
You've woken up one day to find that everyone suddenly expresses numbers in different number bases. You're seeing prices in octal and phone numbers in hexadecimal. It's a numerical Tower of Babel! For your own sanity, you decide to program a simple mathematical expression evaluator that can handle numbers in different number bases. It should support addition, subtraction, and multiplication, should respect order of operations, and should handle number bases between 2 and 16.
While your language of choice may directly support expression evaluation, please create your own.
The input on stdin is a mathematical expression on a single line. Number constants are expressed like "123_4", which is "123" in base 4, which is 27 in base 10. Some digits in the higher bases will be represented with uppercase letters. Numbers within the expression will always be non-negative integers. The operators will be +, -, and *. Whitespace should be ignored.
Your program should emit to stdout a single base-10 number with no und
@epson121
epson121 / gen.rb
Created August 31, 2013 22:24
Calculation for civil engineering task of vehicle performance. (in Croatian)
res = []
8.times do
res << [rand(7..10), rand(3..4), rand(3..6), rand(2..4)]
end
14.times do
res << [rand(11..20), rand(5..7), rand(3..4), rand(3..4)]
end
2.times do