Datasets:

inputs
stringlengths
50
14k
targets
stringlengths
4
655k
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
import datetime def days(date, month, year): x = datetime.datetime(year, month, date) y = datetime.datetime(2437, 3, 24) delta = y-x t = delta.days if year < 1752 or (year == 1752 and month < 9) or (year == 1752 and month == 9 and date < 14): t -= 11 if year < 1752 : y = year //4 * 4 + 4 for i in range(y, 1752, 4): if i % 100 == 0 and i % 400 != 0: t+=1 return t
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
my_year = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} def is_leap(year): return [0,1,0,1,0,1,1,1][(year%4==0)+(year%100==0)+(year%400==0)+4*(year < 1752)] def day_of_year(d, m, y=2437): return sum(my_year[i] for i in range(1, m)) + d + is_leap(y)*(m > 2) def days(d, m, y, d0=24, m0=3, y0=2437): A = day_of_year(d0, m0) # current year B = sum(map(is_leap, range(y+1, y0))) + 365*(y0 - y) # years between y and y0 C = 11*(y < 1752 or y == 1752 and day_of_year(d, m) < 246) # < 03.09.1752 D = is_leap(y) - day_of_year(d, m, y) # desired year return A + B - C + D
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
# Let's do this without the builtin date library # and without looking up formulas in wikipedia def is_leap_year(year): if year % 4 != 0: return False # year is divisible by 4. # If the year is in the Gregorian calendar, that's it if year <= 1752: return True # Julian calendar rule return (year % 100 != 0) or (year % 400 == 0) # Day number of the first day of the month, minus one. # Doesn't count leap years. DOM = { 1: 0, 2: 31, 3: 59, 4: 90, 5: 120, 6: 151, 7: 181, 8: 212, 9: 243, 10: 273, 11: 304, 12: 334, } def is_julian_period(date, month, year): if year > 1752: return True if year < 1752: return False # year == 1752 if month < 9: return False if month > 9: return True return date >= 14 # This could be rewritten as a one-liner (see wikipedia) but I'm not sure that I can derive the formula. def normalized_day(date, month, year): """Number of days between given date and an arbitrary origin. normalized_day(1, 1, 0) == 1 """ orig_year = 0 days = date + DOM[month] + (year - orig_year) * 365 # Leap year adjustment for the current year if is_leap_year(year) and month >= 3: days += 1 # Leap year adjustment for the intervening years # It could be done without a loop (count 4-year intervals, # subtract centuries, re-add 400-years) but it would be less # readable given the Gregorian stuff. for y in range(orig_year, year, 4): if is_leap_year(y): days += 1 # Gregorian->Julian transition adjustment if is_julian_period(date, month, year): days -= 11 return days def days(date, month, year): return normalized_day(24, 3, 2437) - normalized_day(date, month, year)
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
def days(date, month, year): ## create function to calculate day value def day_calc(date, month, year): count = 0 #find days in years for i in range (0,year): if i < 1752: if i % 4 == 0: count += 366 else: count += 365 elif i == 1752: count += 366-11 else: if i % 400 == 0: count += 366 elif i % 100 == 0: count += 365 elif i % 4 == 0: count += 366 else: count += 365 #dictionary of days passed at a month end months = {0:0,1:31,2:59,3:90,4:120,5:151,6:181,7:212,8:243,9:273,10:304,11:334,12:365} #find days in month if year % 400 == 0: count += months[month-1] if month > 2: count += 1 elif year % 100 == 0: count += months[month-1] elif year % 4 == 0: count += months[month-1] if month > 2: count += 1 else: count += months[month-1] #add days in month, check if it was in Sept 1752 when 11 days were skipped if year == 1752 and month == 9 and date > 13: count += date -11 else: count += date return count cdate = 24 cmonth = 3 cyear = 2437 return day_calc(cdate, cmonth, cyear) - day_calc(date, month, year) print(days(31,1,2436))
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
from datetime import * def julian(day,month,year): dayy=(year-1)*365+(year-1)//4 daym=sum([0,31,29 if year%4==0 else 28,31,30,31,30,31,31,30,31,30,31][:month]) return dayy+daym+day ref =date(2437,3,24) greg=date(1752,9,14) days2greg=(ref-greg).days jgreg=julian(3,9,1752) def days(day, month, year): if year>1752 or (year==1752 and month>9) or (year==1752 and month==9 and day>13): return (ref-date(year,month,day)).days else: return jgreg-julian(day,month,year)+days2greg
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
def days(date, month, year): current_year = 2437 current_month = 3 current_date = 24 current_days = (24+28+31) days = 0 y_days = 0 print((date,month,year)) def leap_year(year): condition = False if year > 1752: if year % 400 == 0: condition = True elif year % 100 == 0: condition = False elif year % 4 == 0: condition = True else: if year % 4 == 0: condition = True return condition month_30 = {1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31} month_30_leap = {1:31,2:29,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31} if year > 1752: if leap_year(year) == True: #if its a leap year for m in range(1,month): days += month_30_leap[m] days += date for y in range(year, current_year): if leap_year(y) == True: y_days += 366 else: y_days += 365 days = current_days - days + y_days print("this one - 1") return days else: for m in range(1,month): days += month_30[m] days += date for y in range(year, current_year): if leap_year(y) == True: y_days += 366 else: y_days += 365 days = current_days - days + y_days print("this one = 2") return days else: if year % 4 == 0: for m in range(1,month): days += month_30_leap[m] if year == 1752 and month > 9: days -= 11 if year == 1752 and month == 9: for d in range(1,date+1): if 3 > d or d > 13: print(d) days += 1 else: days += date for y in range(year, current_year): if leap_year(y) == True: if y == 1752: y_days += 366-11 else: y_days += 366 else: y_days += 365 days = current_days - days + y_days print("this one - 3") return days else: for m in range(1,month): days += month_30[m] days += date for y in range(year, current_year): if leap_year(y) == True: if y == 1752: y_days += 366-11 else: y_days += 366 else: y_days += 365 days = current_days - days + y_days print("this one - 4") return days
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
def leap(year): if year < 1753: if year % 4 == 0: return True else: if year % 4 == 0: if year % 100 != 0 or year % 400 == 0: return True elif year % 100 == 0: return False else: return False def days(date, month, year): the_date = [24, 3, 2437] Leap_year = {1: 31, 2: 29, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} Non_leap_year = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} point_date = [date, month, year] reverse_date = [year, month, date] days_from_beginning = the_date[0] for i in range(1, the_date[1]): days_from_beginning += Non_leap_year[i] def to_year_end(list, dict): days_to_end = dict[list[1]] - list[0] for i in range(list[1] + 1, 13): days_to_end += dict[i] return days_to_end if year == the_date[2] and month == the_date[1]: result = the_date[0] - date return result elif year == the_date[2] and month < the_date[1]: result = days_from_beginning - date for i in range(1, month): result -= Non_leap_year[i] return result else: result = days_from_beginning if reverse_date < [1752, 9, 14]: result -= 11 if leap(year): result += to_year_end(point_date, Leap_year) else: result += to_year_end(point_date, Non_leap_year) for y in range(year + 1, the_date[2]): if leap(y): result += 366 else: result += 365 return result
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
def days(date, month, year): def leap_year(y): if y % 4 == 0: if y>1752 and y%100==0: if y%400==0: return True else: return False return True def days_in_years(y): n=0 for num in range(1,y): if leap_year(num): n+=1 return ((y-1)*365+n) if y<=1752 else ((y-2)*365+n+354) def days_in_month(m,y): n=0 list_31 = [1,3,5,7,8,10,12] list_30 = [4,6,9,11] for num in range(1,m): if num in list_31: n+=31 elif num in list_30: n+=30 elif leap_year(y): n+=29 else: n+=28 if y == 1752 and m > 9: n-=11 return n def days_in_days(d,m,y): if y==1752 and m==9 and d>2: return d-11 return d current_days = days_in_days(24,3,2437)+days_in_month(3,2437)+days_in_years(2437) return current_days - (days_in_days(date,month,year) + days_in_month(month,year)+days_in_years(year) )
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
def days(date, month, year): daysaway = 0 monthdays = 0 leapyear = 0 monthsinyear = [31,28,31,30,31,30,31,31,30,31,30,31] daysaway += 24- date if year < 2437: daysaway += (2437 - year) * 365 if month < 3: if month == 1: daysaway += monthsinyear[0] + monthsinyear[1] else: daysaway += monthsinyear[1] elif month > 3: for i in range(3,month): monthdays -= monthsinyear[i-1] daysaway += monthdays if year < 1752 or (year == 1752 and month < 9) or (year == 1752 and month == 9 and date < 3): daysaway -= 11 for i in range(year,2438): if i <= 1752 and i % 4 == 0: leapyear += 1 if i==year and month > 2: leapyear -=1 elif i > 1752: if i % 400 == 0 or (i % 4 == 0 and i % 100 != 0): leapyear += 1 if i==year and month > 2: leapyear -=1 daysaway += leapyear return daysaway
The date is March 24, 2437 and the the Earth has been nearly completely destroyed by the actions of its inhabitants. Our last hope in this disaster lies in a shabby time machine built from old toasters and used microwave parts. The World Time Agency requires you to travel back in time to prevent disaster. You are ordered to "remove" certain babies from the timeline. Historical newspapers and records provide the Date, Month, and Year for each mission. Unfortunately the time machine takes input only as the number of days to travel back in time. It is your job to calculate how many days you will need to travel back from today's date (March 24, 2437) for each mission. For example, if a historical newspaper says a dangerous baby was born on: Date = 21, Month = 3, Year = 2437 Then your function must compute that it was 3 Days ago. Another example would be that a baby born on Date = 24, Month = 3, Year = 2436 would have been born 365 days ago. You will not have time travel past the year 0. Note that while this is a fairly simple task, it is complicated by the fact that newspapers used the Julian calendar instead of the current Gregorian calendar prior to September 14, 1752. In 1752, it was declared that Sep 2, 1752 was proceeded immediately by September 14, 1752, entirely omitting September 3-13. Furthermore, the rules for leap years changed on that date. After 1752, leap years are on any year divisible by four, except for years which are divisible by 100. An exception to that exception is that years divisible by 400 are always leap years. For example, 1803, 1900, 2001, 2019, and 2100 are not leap years, but 1804, 2000 and 2020 are leap years. However in the Julian calander prior to and including 1752, leap years were on every year divisible by 4, without the exception of years divisible by 100. The years 1752, 1700, 1600, and 0 were all leap years. Good luck agent, the world depends on you! Note: It is not required, but if you find it helpful to visualize the switch from the Julian to the Gregorian calendar, please see these links: Please observe that much of September 1752 is missing here: https://www.timeanddate.com/calendar/?year=1752&country=1 Please observe that 1700 is a leap year here: https://www.timeanddate.com/calendar/?year=1700&country=1
from datetime import date '''Datetime assumes "the current Gregorian calendar always was, and always will be, in effect."''' GREG_START = date(1752, 9, 14) GREG_SKIP = 11 CURR_DATE = date(2437, 3, 24) def days(day, month, year): try: target_date = date(year, month, day) distance = (CURR_DATE - target_date).days except ValueError: # Gregorian/Julian conflict target_date = date(year, month, day-1) distance = (CURR_DATE - target_date).days - 1 if target_date < GREG_START: distance -= GREG_SKIP distance += len([cent for cent in range((year-1)//100 + 1, GREG_START.year//100 + 1) if cent % 4]) return distance
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
def recaman(n): series, last = {0}, 0 for i in range(1, n+1): test = last - i last = last + i if test < 0 or test in series else test series.add(last) return last
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
inseq, seq = {0}, [0] for n in range(1, 10 ** 6): x = seq[-1] - n if x < 0 or x in inseq: x += 2*n seq.append(x) inseq.add(x) recaman = seq.__getitem__
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
def recaman(n): s = set() prev = 0 curr = 0 for i in range(1, n + 1): curr = prev - i if curr <= 0 or curr in s: curr = prev + i s.add(curr) prev = curr return curr
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
buf = [0] def recaman(n): while len(buf)<=n: x = buf[-1]; v = x-len(buf) buf.append(v if 0<=v and v not in buf else x+len(buf)) return buf[n]
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
def recaman(n): seq = [0] seen = {0} for i in range(1, n+1): x = seq[-1] - i if x < 0 or x in seen: x = seq[-1] + i seq.append(x) seen.add(x) return seq[-1]
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
RECA = [0] seen = {0} last = 0 for n in range(1, 30000): new = last - n if new <= 0 or new in seen: new = last + n RECA.append(new) seen.add(new) last = new del seen def recaman(n): return RECA[n]
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
def recaman(n): k, r, s = 0, 0, 0 S = {0} while n != 0: r = k + 1 if s - r < 0 or s - r in S: s += r else: s -= r k += 1 n -= 1 S.add(s) return s
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
def recaman(n): a, i = 0, 0 k = {0} while i<=n: x = [a+i,a-i][(a-i) > 0 and a-i not in k] k.add(x) a = x i += 1 return x
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
def recaman(n): seq={0} cur=0 for i in range(1,n+1): cur+=[i,-i][cur-i not in seq and cur-i>0] seq.add(cur) return cur
Return the `n`th term of the Recamán's sequence. ``` a(0) = 0; a(n-1) - n, if this value is positive and not yet in the sequence / a(n) < \ a(n-1) + n, otherwise ``` ___ A video about Recamán's sequence by Numberphile: https://www.youtube.com/watch?v=FGC5TdIiT9U
R=[0] for i in range(1,30000): if R[i-1]-i>0 and R[i-1]-i not in R: R.append( R[i-1]-i ) else: R.append( R[i-1]+i ) def recaman(n): return R[n]
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
from itertools import cycle,chain def max_hexagon_beam(n,seq): h = 2*n-1 seq = cycle(seq) sums = [ [0]*h for _ in range(3)] # [horz, diagUp, diagDown] for r in range(h): for c,v in zip(list(range(n+r if r<n else h+n-1-r)),seq): idxs = (r, c+max(0,r-n+1), c+max(0,n-1-r)) for i,j in enumerate(idxs): sums[i][j] += v return max(chain.from_iterable(sums))
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
def max_hexagon_beam(n: int, seq: tuple): """Compute maximum sum along "beams" of an hexagon _-'-_ _-'-_ o--- +i .' '.' '. | |0,-1,1 |1,-1,0 | ' _-'-_ _-'-_ _-'-_ +j .' '.' '.' '. |-1,0,1 | q,r,s | 1,0,-1| +s +q '-_ _-'-_ _-'-_ _-' '-_ _-' '.' '.' '.' 'o' |-1,1,0 | 0,1,-1| | '-_ _-'-_ _-' ' '.' '.' +r hex->grid: i = r+n-1 j = q+n-1+min(r,0) grid->hex: r = i+1-n q = j+1-n-min(r,0) s = -q-r beams: 1-n-min(r,0) <= q,s <= n-1-max(r,0) etc. """ i = 0 grid = [] length = len(seq) for r in range(1-n, n): grid.append([]) for q in range(1-n-min(r,0), n-max(r,0)): grid[r+n-1].append(seq[i % length]) i += 1 return max(( max(sum(grid[r+n-1][q+n-1+min(r,0)] for r in range(1-n-min(q,0), n-max(q,0))) for q in range(1-n, n)), max(sum(grid[r+n-1][-s-r+n-1+min(r,0)] for s in range(1-n-min(r,0), n-max(r,0))) for r in range(1-n, n)), max(sum(grid[-q-s+n-1][q+n-1+min(-q-s,0)] for q in range(1-n-min(s,0), n-max(s,0))) for s in range(1-n, n)), ))
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
from itertools import chain, cycle from collections import defaultdict def max_hexagon_beam(n: int, seq: tuple): sums = {c: [0] * (2 * n - 1) for c in "qrs"} it = cycle(seq) for q in range(-n + 1, n): for r in range(max(-n, -q - n) + 1, min(n, -q + n)): s = -q - r v = next(it) sums['q'][q + n - 1] += v sums['r'][r + n - 1] += v sums['s'][s + n - 1] += v return max(chain.from_iterable(list(sums.values())))
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
from itertools import cycle, zip_longest def max_hexagon_beam(n, seq): seq = cycle(seq) hexagon = [[next(seq) for _ in range(2*n-abs(r)-1)] for r in range(1-n,n)] x = list(zip_longest(*([0]*i+r for i, r in enumerate(hexagon, 1-n)), fillvalue=0)) y = list(zip_longest(*([0]*-i+r for i, r in enumerate(hexagon, 1-n)), fillvalue=0)) return max(map(sum, hexagon + x + y))
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
from itertools import cycle def max_hexagon_beam(n: int,seq: tuple): l=n*2-1 #the number of rows of the hexagon ll =[l-abs(n-i-1) for i in range(l)] #the lengths of each row c=cycle(seq) hex = [[next(c) for i in range(j)] for j in ll] # the hexagon sums = [sum(i)for i in hex] # the straight lines for index, i in enumerate(ll): start_row = [0, index%n + 1][index>=n] hex_row=[] hex_row2=[] for j in range(i): y=j+start_row #the y-axis or the row used x=index-[0, y%n + 1][y>=n] # the x-axis or the position in the row. hex_row.append(hex[y][x]) # the line going right-up hex_row2.append(hex[y][-1-x]) # the line going right-down sums +=[sum(hex_row), sum(hex_row2)] sums.sort() return sums[-1] # I also considered extending the hexagon with edges of zeros so the x and y would have less possibility to go out of the list.
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
import numpy as np from collections import deque def max_hexagon_beam(n: int,seq: tuple): max_len = n*2-1 mat = [0]*max_len**2 hexag_1 = np.zeros((max_len, max_len)) hexag_2 = np.zeros((max_len, max_len)) for i in range(0, len(mat)): mat[i] = seq[i%(len(seq))] for i in range(n): hexag_1[i][0:n+i] = mat[0:n+i] rot = deque(hexag_1[i]) rot.rotate(n-i-1) hexag_2[i] = np.array(rot) mat[0:n+i] = [] j=1 for i in range(n, max_len): hexag_1[i][j:] = mat[0:max_len-j] rot = deque(hexag_1[i]) rot.rotate(n-i-1) hexag_2[i] = np.array(rot) mat[0:max_len-j] = [] j+=1 horiz = hexag_1.sum(axis=1) diag_1 = hexag_1.sum(axis=0) diag_2 = hexag_2.sum(axis=0) a = [max(horiz), max(diag_1), max(diag_2)] return max(a)
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
from itertools import cycle def max_hexagon_beam(n: int, seq: tuple): q = cycle(seq) sx, sy, sz = [0] * (2 * n - 1), [0] * (2 * n - 1), [0] * (2 * n - 1) for z in range(-(n - 1), n): xp = -(n-1) if z >= 0 else -(n - 1) - z xk = n-1 if z <= 0 else n - 1 - z for x in range(xp, xk + 1): y = -(z + x) v = next(q) sx[x + n - 1] += v sy[y + n - 1] += v sz[z + n - 1] += v return max(sz + sy + sx)
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
from itertools import cycle,chain def printhex(b): for x in b: st=' '.join(map(str,x)) print(f'{st:^{2*len(b)-1}}') def d1sum(b,n,l): d1_sum = [] for i in range(l): dsum=0 if i+n <= l: k=1 for x in range(n+i): if x <n: dsum+=b[x][i] else: dsum+=b[x][i-k] k+=1 else: k=1 for x in range(i-n+1,l): if x <n: dsum+=b[x][i] else: dsum+=b[x][i-k] k+=1 d1_sum.append(dsum) return d1_sum def d2sum(b,n,l): d2_sum = [] for i in range(l): dsum=0 if i+n <= l: k=1 for x in range(n+i): if x <n: dsum+=b[x][-1-i] else: dsum+=b[x][-1-i+k] k+=1 else: k=1 for x in range(i-n+1,l): if x <n: dsum+=b[x][-1-i] else: dsum+=b[x][-1-i+k] k+=1 d2_sum.append(dsum) return d2_sum def max_hexagon_beam(n: int,seq: tuple): print((n,seq)) l = 2*n-1 b = [] hb_sum = [] itr = cycle(seq) for i in range(l): tmp = [] if i+n <=l: k = i+n else: k = l-(i-n+1) for j in range(k): tmp.append(next(itr)) b.append(tmp) hb_sum.append(sum(tmp)) #printhex(b) d1_sum = d1sum(b,n,l) d2_sum = d2sum(b,n,l) return(max(chain(hb_sum,d1_sum,d2_sum)))
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
def max_hexagon_beam(n: int,ll: tuple): # n = 5 # l1 = [4,3,8,7,5,1] l1 = list(ll) tn = (n * ((2*n)-1)) + (((2*n)-n-1)**2) mid = (2*n-1) nest = [0 for i in range(mid)] for i in range (0, n): nest[n-i-1] = mid-i nest[n+i-1] = mid-i xv = l1[:tn%len(l1)] l2 = [l1*(tn//len(l1))+xv] cnt = 0 a0 = [[]]*len(nest) a1 = [[0] * mid] * mid a2 = [[0] * mid] * mid for st in range (0, len(nest)): a0[st] = l2[0][cnt:cnt+nest[st]] cnt += nest[st] for st in range (0,n): a1[st] = a0[st] + [0]*(mid-nest[st]) a1[mid-1-st] = [0]*(mid-nest[st]) + a0[mid-st-1] a2[st] = [0]*(mid-nest[st]) + a0[st] a2[mid-1-st] = a0[mid-st-1] + [0]*(mid-nest[st]) sm0 = [0]*mid sm1 = [0]*mid sm2 = [0]*mid for i in range (0, mid): for j in range (0, mid): sm1[j] += a1[i][j] sm2[j] += a2[i][j] for i in range (0, mid): sm0[i] = sum(a0[i]) return (max(sm0+sm1+sm2))
In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq. In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification. Input Your function will receive two arguments: n : the length of each side of the hexagonal grid, where 2 <= n < 100 seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.). Output Your function should return the largest beam value as an integer. Test Example In our test example, we have the following arguments: n = 4 seq = [2, 4, 6, 8] Below is the hexagonal grid determined by our example arguments; the sequence repeats itself from left to right, then top to bottom. 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 4 6 8 2 The three diagrams below illustrate the "beams" in the hexagonal grid above. In the grid on the left, the horizontal beams are highlighted by their likewise colors, and the value of each beam is given to its right. In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa). In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa). 2 4 6 8 -> 20 2 4 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 4 6 -> 30 4 6 8 2 4 6 4 6 8 2 4 6 8 2 4 6 8 2 4 -> 34 8 2 4 6 8 2 4 8 2 4 6 8 2 4 6 8 2 4 6 8 -> 34 6 8 2 4 6 8 6 8 2 4 6 8 2 4 6 8 2 -> 22 2 4 6 8 2 2 4 6 8 2 4 6 8 2 -> 20 4 6 8 2 4 6 8 2 The maximum beam value in our example is 34. Test Specifications All inputs will be valid Full Test Suite: 12 fixed tests and 100 random tests For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section] If you enjoyed this kata, be sure to check out my other katas
def fila_left(n, fila): """Asigna al array con las filas de la grid el array de filas a la izqda""" output = [None] * (2 * n - 1) column = 0 while column <= n - 1: output[column] = [fila[row][0] for row in range(n + column)] for row in range(n + column): fila[row].pop(0) column += 1 while column <= 2 * n - 2: output[column] = [fila[row][0] for row in range(column - n + 1, 2 * n - 1)] for row in range(column - n + 1, 2 * n - 1): fila[row].pop(0) column += 1 return output def max_hexagon_beam(n: int, seq: tuple): celdas = 3 * n ** 2 - 3 * n + 1 elementos = [n + i for i in range(n)] + [2 * n - 2 - i for i in range(n - 1)] filas = len(elementos) grid = [] for i in range(celdas): grid.append(seq[i % len(seq)]) # Analizamos filas fila = [None] * filas usados = 0 for i in range(filas): fila[i] = grid[usados:usados + elementos[i]] usados += elementos[i] maximo = max(sum(fila[i]) for i in range(filas)) # Analizamos filas a la izquierda por dos veces fila2 = fila_left(n, fila) fila2 = [row[::-1] for row in fila2] maximo_left = max(sum(fila2[i]) for i in range(filas)) fila3 = fila_left(n, fila2) fila3 = [row[::-1] for row in fila3] maximo_right = max(sum(fila3[i]) for i in range(filas)) return max(maximo, maximo_left, maximo_right)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from numpy import prod def find_difference(a, b): return abs(prod(a) - prod(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): return abs((a[1]*a[2]*a[0])-b[1]*b[2]*b[0])
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from operator import mul from functools import reduce def find_difference(a, b): return abs(reduce(mul, a) - reduce(mul, b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): return abs(a[0] * a[1] * a[2] - b[0] * b[1] * b[2])
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): A = B = 1 for i, j in zip(a, b): A *= i B *= j return abs(A - B)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
find_difference = lambda a,b,p=__import__("numpy").prod: abs(p(a)-p(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
find_difference = lambda (a, b, c), (x, y, z): abs(a * b * c - x * y * z)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): a_volume = a[0] * a[1] * a[2] b_volume = b[0] * b[1] * b[2] return abs(a_volume - b_volume)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): return abs(p(a) - p(b)) def p(a): temp = 1 for i in a: temp *= i return temp
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
import numpy as np def find_difference(a, b): return abs(np.multiply.reduce(a) - np.multiply.reduce(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): aVol = a[0] * a[1] * a[2] bVol = b[0] * b[1] * b[2] return abs(aVol - bVol)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce find_difference = lambda a,b: abs(reduce(lambda x, y:x*y, a) - reduce(lambda x, y:x*y, b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce from operator import mul,sub def find_difference(*cs): return abs(sub(*(reduce(mul,c) for c in cs)))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
find_difference=lambda*a:abs(sum((-1)**i*x*y*z for i,(x,y,z)in enumerate(a)))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): # Your code here! p = 1 q = 1 for nums in a: p *= nums for nums in b: q *= nums return abs(p - q)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from numpy import prod find_difference = lambda a, b: abs(prod(a) - prod(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): t1 = 1 t2 = 1 for num in a: t1 *= num for num in b: t2 *= num return abs(t1 - t2)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce from operator import mul def find_difference(a, b): return abs(reduce(mul, a) - reduce(mul, b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from operator import mul, sub from typing import List def find_difference(a: List[int], b: List[int]) -> int: """ Find the difference of the cuboids' volumes regardless of which is bigger based on two lists of integers `a` and `b` which representing the dimentions of cuboids `a` and `b`. """ return abs(sub(*list(map(lambda x, y, z: x * y * z, *zip(a, b)))))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): value_a = a[0]*a[1]*a[2] value_b = b[0]*b[1]*b[2] return value_a-value_b if value_a >= value_b else value_b-value_a
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): def mul(li): car=1 for i in li: car*=i return car return abs(mul(a)-mul(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce def find_difference(a, b): volume = lambda a,b:a*b return abs(reduce(volume, a) - reduce(volume, b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): # Your code here! A=1 B=1 for i in range(len(a)): A=A*a[i] B=B*b[i] return A-B if(A>B) else B-A
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): c=a[0]*a[1]*a[2] d=b[0]*b[1]*b[2] return abs(c-d)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): x = a[0] * a[1] * a[2] y = b[0] * b[1] * b[2] z = x - y if z > 0: return z else: return -z # Your code here!
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): x = y = 1 for i in a: x *= i for j in b: y *= j return abs(x-y)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): Va = a[1]*a[2]*a[0] Vb = b[1]*b[2]*b[0] diff = Va - Vb return diff if diff > 0 else -diff
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): resa = a[0] resb = b[0] for i in a[1:]: resa = resa * i for i in b[1:]: resb = resb * i return abs(resa - resb)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from typing import List def find_difference(a: List[int], b: List[int]) -> int: mult3 = lambda x: x[0]*x[1]*x[2] return abs( mult3(a)-mult3(b) )
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce def find_difference(a, b): prod = lambda x, y: x * y return abs(reduce(prod, a) - reduce(prod, b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): aCube = a[0]*a[1]*a[2] bCube = b[0]*b[1]*b[2] return abs(aCube - bCube)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): res1 = 1 res2 = 1 for n in a: res1 *= n for n in b: res2 *= n return abs(res1 - res2)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce as r from operator import mul def find_difference(a, b): return abs(r(mul,a,1)-r(mul,b,1))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from numpy import prod def find_difference(a, b): x , y = prod(a) , prod(b) if x > y: return x - y else: return y - x
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
import math def find_difference(a, b): def prod(arr): proc =1 for i in arr: proc *=i return proc return abs(prod(a) - prod(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): aa=a[0]*a[1]*a[2] bb=b[0]*b[1]*b[2] return max(aa,bb)-min(aa,bb)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
import numpy def find_difference(a, b): return abs(numpy.prod(b) - numpy.prod(a))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
import numpy as np def find_difference(a, b): return np.prod(a)-np.prod(b) if np.prod(a)>np.prod(b) else np.prod(b)-np.prod(a)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): # Your code here! cube1 = a[0] * a[1] * a[2] cube2 = b[0] * b[1] * b[2] result = cube1 - cube2 if cube1 - cube2 < 0: result = cube2 - cube1 return result
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): a_rez = 1; b_rez = 1; for x in a: a_rez = a_rez * x; for y in b: b_rez = b_rez * y; return abs(a_rez - b_rez);
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
find_difference = lambda a, b: a[0]*a[1]*a[2] - b[0]*b[1]*b[2] if (a[0]*a[1]*a[2] - b[0]*b[1]*b[2]) > 0 else b[0]*b[1]*b[2] - a[0]*a[1]*a[2]
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): mx = max(a[0] * a[1] * a[2], b[0]* b[1] * b[2] ) mn = min(a[0] * a[1] * a[2], b[0]* b[1] * b[2] ) return mx - mn
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
import functools as ft def find_difference(a, b): return abs(ft.reduce((lambda x, y: x * y), a) - ft.reduce((lambda x, y: x * y), b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
find_difference = lambda a, b: a[0]*a[1]*a[2] - b[0]*b[1]*b[2] if a[0]*a[1]*a[2] > b[0]*b[1]*b[2] else b[0]*b[1]*b[2] - a[0]*a[1]*a[2]
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
import numpy as np def find_difference(a, b): return max(np.prod(a)-np.prod(b),np.prod(b)-np.prod(a))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce def find_difference(a: list, b: list) -> int: return abs(reduce(lambda x, y: x * y, a) - reduce(lambda x, y: x * y, b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): cube_a = cube_b = 1 for x in a: cube_a *= x for x in b: cube_b *= x return abs(cube_a - cube_b)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): s1 = a[0] * a[1] * a[2] s = b[0] * b[1] * b[2] return abs(s - s1)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): x = 1 y = 1 for i in a: x = x * i for i in b: y = y * i result = abs(x-y) return result
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): result=1 result2=1 for i in a: result = result * i for j in b: result2 = result2 * j return abs(result-result2)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): total_a = 1 total_b = 1 for i in a: total_a *= i for c in b: total_b *= c return abs(total_a - total_b)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): x = 1 y = 1 for i in range(len(a)): x = x * a[i] for j in range(len(b)): y = y * b[j] if x >= y: return (x-y) else: return (y-x)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): vol_a = a[0] * a[1] * a[2] vol_b = b[0] * b[1] * b[2] return vol_a - vol_b if vol_a > vol_b else vol_b - vol_a
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): mul_a, mul_b = 1, 1 for num_a, num_b in zip(a, b): mul_a *= num_a mul_b *= num_b return abs(mul_a - mul_b)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): c = (a[0] * a[1] * a[2]) - (b[0] * b[1] * b[2]) if c < 0: return c * (-1) else: return c # Your code here!
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): volA = 1 volB = 1 for x,y in zip(a,b): volA = volA * x volB = volB * y return abs(volA-volB)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from functools import reduce def find_difference(a, b): from functools import reduce vol = lambda _: reduce(lambda x,y:x*y,_) return abs(vol(a)-vol(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): sq1 = (a[0]*a[1]*a[2]) sq2 = (b[0]*b[1]*b[2]) if sq1 >sq2: return sq1-sq2 else: return sq2-sq1
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from numpy import prod def find_difference(a, b): v1 = prod(a) v2 = prod(b) return abs(v1-v2)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): count1 = 1 count2 = 1 for i in a: if i < 0: return abs(i) else: count1 *=i for j in b: if j < 0: return abs(j) else: count2 *=j output = count1 - count2 if output < 0: return abs(output) return output
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): c=1 d=1 for i in a: c*=i for i in b: d*=i return max(c-d, d-c)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(v, w): a, b, c, d, e, f = v[0], v[1], v[2], w[0], w[1], w[2] return a*b*c-d*e*f if a*b*c > d*e*f else d*e*f-a*b*c
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def v(arr): return arr[0]*arr[1]*arr[2] def find_difference(a, b): return abs(v(a)-v(b))
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): av, bv = 1, 1 for i in a: av *= i for i in b: bv *= i return av - bv if av >= bv else bv - av
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): x = y = 1 for i,j in zip(a,b): x *= i y *= j return abs(x-y)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): a = a[0]*a[1]*a[2] b = b[0]*b[1]*b[2] if a>b: d = a - b return d else: d = b-a return d
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): m = 1 n = 1 for x in range(len(a)) : m *= a[x] n *= b[x] return abs(m - n)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
def find_difference(a, b): vola = 1 for x in a: vola *= x volb = 1 for x in b: volb *= x return abs(vola-volb)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
import math def find_difference(a, b): v1 = a[0] * a[1] * a[2] v2 = b[0] * b[1] * b[2] return math.abs(v1 - v2)
In this simple exercise, you will create a program that will take two lists of integers, ```a``` and ```b```. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids ```a``` and ```b```. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ```([2, 2, 3], [5, 4, 1])```, the volume of ```a``` is 12 and the volume of ```b``` is 20. Therefore, the function should return ```8```. Your function will be tested with pre-made examples as well as random ones. **If you can, try writing it in one line of code.**
from operator import mul, abs from functools import reduce def find_difference(a, b): return abs(reduce(mul,a) - reduce(mul,b))