Best AI Apps Finder - coding test, run 24-25 September 2026 (UTC) Prompt pasted unchanged into each tool: Fix the bugs in this Python function so it meets the specification. Return only the corrected function. Specification: parse_duration(text) converts a duration string such as "1h 30m", "45m", "2h", "90s" or "1h 5m 10s" into a total number of seconds (int). Units are h, m and s. They may appear in any order, each unit at most once, with or without spaces between parts. Uppercase units are allowed. Raise ValueError for an empty string, an unknown unit, a repeated unit or a negative number. def parse_duration(text): units = {'h': 3600, 'm': 60, 's': 1} total = 0 for part in text.split(' '): num = int(part[:-1]) unit = part[-1] total += num * units[unit] return total ----- Hidden test harness (tests.py), run with Python 3 ----- import sys, importlib.util, traceback spec=importlib.util.spec_from_file_location("sol", sys.argv[1]); m=importlib.util.module_from_spec(spec); spec.loader.exec_module(m) f=m.parse_duration ok=[("1h 30m",5400),("45m",2700),("90s",90),("1h 5m 10s",3910),("1H 5M",3900),("1h30m",5400),("30m 1h",5400),(" 2h ",7200),("0s",0)] bad=["","5d","1h 1h","-5m","abc","h"] p=0; res=[] for a,e in ok: try: r=f(a); good=(r==e and isinstance(r,int)); res.append((a,r,good)) except Exception as ex: good=False; res.append((a,type(ex).__name__,False)) p+=good for a in bad: try: r=f(a); res.append((a,r,False)) except ValueError: p+=1; res.append((a,'ValueError',True)) except Exception as ex: res.append((a,type(ex).__name__,False)) for x in res: print(x) print(f"PASS {p}/{len(ok)+len(bad)}") The original buggy function passes 9/15. ----- ChatGPT (Plus, temporary chat): function as returned ----- def parse_duration(text): import re if not isinstance(text, str) or not text.strip(): raise ValueError("Duration cannot be empty") pattern = re.compile(r'(\d+)\s*([hms])', re.IGNORECASE) units = {'h': 3600, 'm': 60, 's': 1} total = 0 seen = set() pos = 0 for match in pattern.finditer(text): if text[pos:match.start()].strip(): raise ValueError("Invalid duration") num = int(match.group(1)) unit = match.group(2).lower() if unit in seen: raise ValueError("Repeated unit") seen.add(unit) total += num * units[unit] pos = match.end() if not seen or text[pos:].strip(): raise ValueError("Invalid duration") return total Result: PASS 15/15 ----- Perplexity (free): function as returned ----- def parse_duration(text): import re if not isinstance(text, str) or not text.strip(): raise ValueError("Duration string cannot be empty") units = {"h": 3600, "m": 60, "s": 1} pattern = re.compile(r"\s*(\d+)\s*([hmsHMS])\s*") total = 0 seen_units = set() position = 0 while position < len(text): match = pattern.match(text, position) if not match: raise ValueError("Invalid duration format") number, unit = match.groups() unit = unit.lower() if unit in seen_units: raise ValueError(f"Repeated unit: {unit}") seen_units.add(unit) total += int(number) * units[unit] position = match.end() return total Result: PASS 15/15 ----- Gemini (free, Flash): function as returned ----- import re def parse_duration(text): if not text or not text.strip(): raise ValueError("Empty string") units = {'h': 3600, 'm': 60, 's': 1} seen_units = set() total = 0 tokens = re.findall(r'(\d+|[a-zA-Z]+)', text) if len(tokens) % 2 != 0: raise ValueError("Invalid format") for i in range(0, len(tokens), 2): num_str, unit_str = tokens[i], tokens[i+1] if not num_str.isdigit(): raise ValueError(f"Invalid number: {num_str}") num = int(num_str) if num < 0: raise ValueError("Negative numbers are not allowed") unit = unit_str.lower() if unit not in units: raise ValueError(f"Unknown unit: {unit_str}") if unit in seen_units: raise ValueError(f"Repeated unit: {unit_str}") seen_units.add(unit) total += num * units[unit] return total Result: PASS 14/15 (fails "-5m": returns 300) ----- GitHub Copilot (web chat, Copilot Free, model Auto): logic as returned, re-indented by us ----- As displayed, the line "def parse_duration(text): import re" appeared as plain text outside the code block and the code block body started at column 0, so copying the code block alone does not run. We restored the indentation without changing any token. def parse_duration(text): import re if not text or not text.strip(): raise ValueError("empty duration") units = {'h': 3600, 'm': 60, 's': 1} pattern = re.compile(r'\s*(\d+)([hmsHMS])') total = 0 seen = set() pos = 0 while pos < len(text): match = pattern.match(text, pos) if not match: raise ValueError("invalid duration") num, unit = match.groups() unit = unit.lower() if unit in seen: raise ValueError("repeated unit") seen.add(unit) total += int(num) * units[unit] pos = match.end() return total Result: PASS 14/15 (fails " 2h ": trailing spaces raise ValueError)