diff --git a/26th Aug, 2019/File Operations/Task - 1/naima.rb b/26th Aug, 2019/File Operations/Task - 1/naima.rb new file mode 100644 index 0000000..b35ae47 --- /dev/null +++ b/26th Aug, 2019/File Operations/Task - 1/naima.rb @@ -0,0 +1,65 @@ +# We're aware of file compressing technique. In this task, we're going to compress text file. +# Compressing technique is goes like this below: +# -> aaamarr aamii = 3a1m1a2r 2a1m2i +# unluckily sometimes file size increases instead of decreasing. But still, let's honor this technique anyway. +# And we're going to write decompressor too. + +# Input Output Format: +# you're going to work with files. Take any article from internet and save it as yourname_input.txt file. +# your source code will be yourname.rb and the compressed output file will be yourname_compressed.txt and decompressed output will be yourname_decompressed.txt. +# your console should show a done message upon completion and show a verdict message showing File size is increased or decreased. + +# This one is case sensitive, please be aware of that. + +# you must through exceptions if file is not acceesible. + +def compressor(line) + temp = line[0] + i = 1 + cnt = 1 + result = "" + while i <= line.length + if temp == line[i] + cnt += 1 + else + result += String(cnt) + temp + temp = line[i] + cnt = 1 + end + i += 1 + end + return result +end + +def decompression(line) + result2 = "" + k = 0 + while k < line.length + no = Integer(line[k]) + chr = line[k+1] + i = 0 + while i < no + result2 += chr + i += 1 + end + k += 2 + end + return result2 +end + +str = File.read("naima_input.txt") +changed = compressor(str) +file = File.open("naima_compressed.txt","w+") +file.puts(changed) +final = decompression(changed) +file = File.open("naima_decompressed.txt","w+") +file.puts(final) +file.close +puts "Done" +if changed.length < final.length + puts "Decreased" +elsif changed.length == final.length + puts "Same" +else + puts "Increased" +end \ No newline at end of file diff --git a/26th Aug, 2019/File Operations/Task - 1/naima_compressed.txt b/26th Aug, 2019/File Operations/Task - 1/naima_compressed.txt new file mode 100644 index 0000000..69ca78f --- /dev/null +++ b/26th Aug, 2019/File Operations/Task - 1/naima_compressed.txt @@ -0,0 +1,12 @@ +1H1a1t1r1e1d1 1o1r1 1h1a1t1e1 1i1s1 1a1n1 1e1m1o1t1i1o1n1.1 1H1a1t1r1e1d1 1c1o1u1l1d1 1i1n1v1o1k1e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o1l1o1g1y1,1 1a1n1t1h1r1o1p1o1l1o1g1y1,1 1a1n1d1 1p1h1i1l1o1s1o1p1h1y1. diff --git a/26th Aug, 2019/File Operations/Task - 1/naima_decompressed.txt b/26th Aug, 2019/File Operations/Task - 1/naima_decompressed.txt new file mode 100644 index 0000000..a837655 --- /dev/null +++ b/26th Aug, 2019/File Operations/Task - 1/naima_decompressed.txt @@ -0,0 +1,12 @@ +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. diff --git a/26th Aug, 2019/File Operations/Task - 1/naima_input.txt b/26th Aug, 2019/File Operations/Task - 1/naima_input.txt new file mode 100644 index 0000000..5856776 --- /dev/null +++ b/26th Aug, 2019/File Operations/Task - 1/naima_input.txt @@ -0,0 +1,12 @@ +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. +Hatred or hate is an emotion. Hatred could invoke feelings of animosity, anger, or resentment, which can be directed against certain individuals, groups, entities, objects, behaviors, concepts, or ideas. Hatred is often associated with feelings of anger, disgust and a disposition towards the source of hostility. +Love is a complex set of emotions, behaviors, and beliefs associated with strong feelings of affection, protectiveness, warmth, and respect for another person. Love can also be used to apply to non-human animals, to principles, and to religious beliefs. For example, a person might say he or she loves his or her dog, loves freedom, or loves God. +Friendship is a relationship of mutual affection between people. Friendship is a stronger form of interpersonal bond than an association. Friendship has been studied in academic fields such as communication, sociology, social psychology, anthropology, and philosophy. \ No newline at end of file diff --git a/26th Aug, 2019/Hashes and Some Basic Tools/Task - 1/naima.rb b/26th Aug, 2019/Hashes and Some Basic Tools/Task - 1/naima.rb new file mode 100644 index 0000000..41b991a --- /dev/null +++ b/26th Aug, 2019/Hashes and Some Basic Tools/Task - 1/naima.rb @@ -0,0 +1,67 @@ +# Write a Ruby program that shows the current date and time at the beginning. Then takes a string of words and prints the word which has the maximum repeatations. Write code in two different ways, +# one is using STL hash another one using no STL (maybe bruteforce) and print which one is faster. + +require 'date' +current_time = DateTime.now +current_time.strftime "%d/%m/%Y %H:%M" +puts current_time +current_time.next_month.strftime "%d/%m/%Y %H:%M" + +def withSTL(words) + start = Float(Time.now) + counts = Hash.new(0) + for word in words + counts[word] += 1 + end + f_word = "" + counts.sort{|a,b| b[1]<=>a[1]}.each { |elem| + f_word = "#{elem[0]}" + break + } + e = Float(Float(Time.now) - start) + return f_word,e +end + +def withoutSTL(words) + start2 = Float(Time.now) + num = words.length + freq = Array.new(num,0) + i = 0 + w1 = "" + while i < num + w1 = words[i] + j = 0 + while j <= num + if w1 == words[j] && i != j + freq[i] = freq[i] + 1 + end + j = j + 1 + end + i = i + 1 + end + k = 0 + high = 0 + ind = 0 + while k < num + if freq[k] >= high + high = freq[k] + ind = k + end + k = k + 1 + end + e2 = Float(Float(Time.now) - start2) + return words[ind], e2 +end + +str = gets.chomp +word = str.split(/[\s,]+/) +w1_time = withSTL(word) +w2_time = withoutSTL(word) +puts "Champion: " + w1_time[0] +puts "Bruteforce took: " + String(w2_time[1].round(4)) + "ms" +puts "Hash took: " + String(w1_time[1].round(4)) + "ms" +if w1_time[1] < w2_time[1] + puts "verdict: Hash won" +else + puts "verdict: Bruteforce won" +end \ No newline at end of file