Skip to content

Instantly share code, notes, and snippets.

View latticetower's full-sized avatar

Tanya Malygina latticetower

View GitHub Profile
@latticetower
latticetower / gist:349fd1477ed2ebc51a34
Last active December 23, 2015 21:49
# The following code solves this problem: http://rosalind.info/problems/glob/ # * it takes data from the input file, in FASTA format (as the problem states). Input file name may be given as a parameter to script # * it writes the result to file named 'output.txt' # * Additionally, it writes to console result && backtracing log # ruby version: 1.…
# The following code solves this problem: http://rosalind.info/problems/glob/
# * it takes data from the input file, in FASTA format (as the problem states). Input file name may be given as a parameter to script
# * it writes the result to file named 'output.txt'
# * Additionally, it writes to console result && backtracing log
# P.S. - Yeees, I know, my english is awful. Please, feel free to review it too =)
#
# ruby version: 1.9.3
# version 1 - doesn't show backtracing
# version 2 - shows some optimal alignment
# version 3 - shows all possible backtracings recursively
require 'rsa' # using rsa gem: http://rsa.rubyforge.org/index.html
# core library has some methods for modular arithmetics, but rsa gem has some additional methods.
# I've tried to use them to find plaintext
# -----------
#known constants
# -------------
E = 29
M_POWER = 3
@latticetower
latticetower / gist:bc0864eaae5d1ad798aa
Last active January 8, 2016 14:51
problem 1 solution
# ruby 1.9.3
# ----------------
# Constants
# ----------------
ASSOCIATED_BRACKETS = {'[' => ']', '(' => ')', '{' => '}'}
# it's just a hash of pairs (just for convinience).
# little bit of ruby Hash class documentation applied to that hash object:
# ASSOCIATED_BRACKETS.keys - returns opening brackets as Array
# ASSOCIATED_BRACKETS.has_key?(obj) - checks if obj is contained between keys in hash
@latticetower
latticetower / problem4_benchmarker.rb
Last active December 24, 2015 20:09
hw 5 problem 4 solution (Algorithms and datastructures course)
# hw 5 problem 4 solution (Algorithms and datastructures course)
# Problem is stated as follows: as input we get array of n elements a[0].. a[n - 1]
# !!!!!!!!!!!!!! in this code elements numerated from zero index
# must find a way to process it and find l and r indices such that (r - l + 1)*min(a[i], i in [l, r]) is maximized
#
# ruby 1.9.3
require './problem4_functions'
#!~/bin/ruby
require 'ostruct'
require "rubyvis"
require './plotter_utility.rb'
#------------
#
#------------
@latticetower
latticetower / hw7_search_problem.rb
Created October 16, 2013 19:13
hw7 problem 3 (incomplete: works when k<m, k<n, k>1)
# ruby 1.9.3
puts "Print first array elements (divided by spaces):"
a = gets().split(' ').map{|x| x.to_i }.sort #presorted array N1
puts "Print second array elements (divided by spaces):"
b = gets().split(' ').map{|x| x.to_i }.sort #presorted array N2
puts "print k value u wanna get"
k = gets().to_i
@latticetower
latticetower / xmatrix.rb
Last active December 27, 2015 09:18
Unix & script languages, hw3 problem 1
=begin
xmatrix should meet the following conditions:
1. there must be class for 3*3 matrices.
2. There must be class for 3dimentional vectors
3. there must be ancestor of matrix class, describing matrix of rotation near z axis
4. Should overload operations:
- matrix addition
- multiplication by number
- multiplication by vector
- multiplication by matrix
@latticetower
latticetower / xfiles.rb
Last active December 27, 2015 09:18
Unix & script languages, hw3 problem 2
=begin
XFiles should meet the following conditions:
1. there must be class for student with his marks. with the following properties:
- print self with ther format shown as '<Student Full Name>: <mark1> <mark2> ... <markN>'
- should be able to calculate median (mean) mark.
- should be able to add new marks
- construct Student by his full name
2. There also should be class for simple file-based database, which should meet the following conditions:
- class should be initialized by filename, when gets filename - load all information from file specified, thus creating a set (array) of Student objects.
- should have possibility to add, remove students, to output all students to file.
@latticetower
latticetower / xdictionary.rb
Created November 4, 2013 13:25
Unix & script languages, hw3 problem 3
=begin
xDictionary should meet the following conditions:
1. must be ancestor of Hash class (ruby analogue to Dictionary class in python)
2. hash values should be accessible via d["key"] and d.key, space characters in key name should be replaced by '_' symbol
3. while initialization, class should accept frozen array with forbidden keys. In case when user tries to add element with
some value from forbidden keys array, DeniedKeyException should be raised
4. There should also be ability to call dictionary\hash elements by their index, in order of appearance in dictionary.
=end
module XDictionaries
class DeniedKeyException < Exception; def initialize(str); super(str || "Denied key exception raised"); end; end
@latticetower
latticetower / example1.rb
Created November 18, 2013 21:28
д.з. скриптовые языки (декораторы, задание 2)
require 'ruby_decorators'
class TimeMachine < RubyDecorator
def call(this, *args, &blk)
start_time = Process.times
puts "#{'%.4f' % (start_time.stime + start_time.utime)}ms #{this.name}"
this.call(*args, &blk)
end_time = Process.times
puts " +#{ '%.9f' % (end_time.stime + end_time.utime - start_time.utime - start_time.stime).abs }ms"
end