def problem42(): """Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?""" dictionary = dict((c, n) for (n, c) in enumerate(string.ascii_uppercase, 1)) words = data.openfile("words.txt").read().replace('"', '').split(",") return ilen(word for word in words if is_triangle(sum(dictionary[c] for c in word)))
def page(): dataset = openfile('./test/donneeshospitalieres.csv') data_quotidien = getDataQuotidien(dataset) moyennes_sexe = getMoyennesParSex(dataset) return render_template('page.html', donnees=data_quotidien, donnees2=moyennes_sexe)
def problem22(): """What is the total of all the name scores in the file?""" contents = data.openfile("names.txt").read() names = sorted(name.strip('"') for name in contents.split(",")) dictionary = dict( (c, n) for (n, c) in enumerate(string.ascii_uppercase, 1)) return sum(i * sum(dictionary[c] for c in name) for (i, name) in enumerate(names, 1))
key_idx_length = [tmp_array[0]] for i in xrange(1,scanned_length): if scanned_input_data[i] == scanned_input_data[i-1]: key_idx_length[-1] += tmp_array[i] else: key_idx_length.append(tmp_array[i]) #6.2: offset for each key in the whole index offset = [0 for i in key_idx_length] for i in xrange(1,len(key_idx_length)): offset[i] = offset[i-1] + key_idx_length[i-1] return key_idx_length,offset ''' if __name__ == '__main__': path = 'data.txt' #file path attr_dict,attr_values,attr_value_NO = data.openfile(path) print attr_dict['worker_class'], attr_value_NO[0] total_row = len(attr_values[0]) input_data = numpy.array(attr_values[0]) print input_data length = input_data.shape[0] rid = numpy.arange(0,length) #step1 sort radix_sort.radix_sort(input_data,rid) print input_data f1 = open('input_data.txt', 'w') f1.write(str(list(input_data))) f2 = open("rid.txt", 'w') f2.write(str(list(rid)))
key_idx_length = [tmp_array[0]] for i in xrange(1, scanned_length): if scanned_input_data[i] == scanned_input_data[i - 1]: key_idx_length[-1] += tmp_array[i] else: key_idx_length.append(tmp_array[i]) #6.2: offset for each key in the whole index offset = [0 for i in key_idx_length] for i in xrange(1, len(key_idx_length)): offset[i] = offset[i - 1] + key_idx_length[i - 1] return key_idx_length, offset if __name__ == '__main__': path = 'data.txt' #file path attr_dict, attr_values, attr_value_NO = data.openfile(path) total_row = len(attr_values[0]) input_data = numpy.array(attr_values[0][0:93]) length = input_data.shape[0] rid = numpy.arange(0, length) print input_data #step1 sort radix_sort.radix_sort(input_data, rid) print 'rid:\n', rid literal = numpy.zeros(length, dtype='uint32') chunk_id = numpy.zeros(length, dtype='int64') stream = cuda.stream() d_rid = cuda.to_device(rid, stream) d_chunk_id = cuda.to_device(chunk_id, stream) d_literal = cuda.to_device(literal, stream) #step2 produce chunk_id and literal
def problem22(): """What is the total of all the name scores in the file?""" contents = data.openfile("names.txt").read() names = sorted(name.strip('"') for name in contents.split(",")) dictionary = dict((c, n) for (n, c) in enumerate(string.ascii_uppercase, 1)) return sum(i*sum(dictionary[c] for c in name) for (i, name) in enumerate(names, 1))