This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mid_point(x,y) | |
| (x+y)/2.0 | |
| end | |
| def square_root(x,e) | |
| if x==1; | |
| guess=1 | |
| else | |
| lowest = 0 | |
| highest = x | |
| guess = mid_point(lowest,highest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mid_point(x,y) | |
| (x+y)/2.0 | |
| end | |
| def square_root(x,e) | |
| if x == 1 | |
| guess = 1 | |
| else | |
| lowest = 0 | |
| highest = x | |
| guess = mid_point(lowest,highest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def product_except?(d) | |
| e = [] | |
| startvalue = 0 | |
| endvalue = d.length | |
| product = d.inject(1){|first,n| first * n} | |
| result = [] | |
| while startvalue < endvalue | |
| result.push(product/ d[startvalue]) | |
| startvalue = startvalue + 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sort_mylist_asc(a): | |
| for my_number in range(len(a)-1,0,-1): | |
| for i in range(my_number): | |
| if a[i]>a[i+1]: | |
| temp = a[i] | |
| a[i] = a[i+1] | |
| a[i+1] = temp | |
| return a | |
| def sort_mylist_desc(a): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sort_mylist_asc(a): | |
| for my_number in range(len(a)-1,0,-1): | |
| for i in range(my_number): | |
| if a[i]>a[i+1]: | |
| temp = a[i] | |
| a[i] = a[i+1] | |
| a[i+1] = temp | |
| return a | |
| def second_places(a): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def camel_snake(input): | |
| output = [input[0].lower()] | |
| for c in input[1:]: | |
| if c in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'): | |
| output.append('_') | |
| output.append(c.lower()) | |
| else: | |
| output.append(c) | |
| return str.join('', output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #sort playlist | |
| def sort_music_asc(a): | |
| i = 0 | |
| m = a[i][1] | |
| for m in range(len(a)-1,0,-1): | |
| for i in range(m): | |
| if a[i][1]>a[i+1][1]: | |
| temp = a[i] | |
| a[i] = a[i+1] | |
| a[i+1] = temp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [[1,2,4,5],[6,7,8,9],[10,11,12,13],[14,15,16,17]] | |
| number = 17 | |
| def box_arr_num(a, number) | |
| length = a.length-1 | |
| number = number | |
| (0..a.length).each do |i| | |
| if a[i][a.length-1] >= number | |
| (0..a.length).each do |j| | |
| if a[i][j] == number | |
| return i, j |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def time_sort(time): | |
| i = 0 | |
| music = time[i][1] | |
| for music in range(len(time)-1,0,-1): | |
| for i in range(music): | |
| if time[i][1]>time[i+1][1]: | |
| clock = time[i] | |
| time[i] = time[i+1] | |
| time[i+1] = clock | |
| return time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def simultaneous_eqn(eqns): | |
| a = eqns[0] | |
| b = eqns[1] | |
| c = eqns[2] | |
| x = float((-b - c) / a) | |
| return x | |
| def two_unknown(eqns): |
OlderNewer