Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .badges/problems.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"label": "problems",
"message": "1043",
"message": "1k",
"color": "FFA116"
}
114 changes: 55 additions & 59 deletions core/Core/Test/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -352,110 +352,110 @@
T.unlines
( ["fmt.Println(" <> quotedMarker <> ")"]
++ prelude
++ [ "cur" <> suffix <> " := time.Now().UnixNano() / 1_000_000",
"a" <> suffix <> " := " <> callExpr,
"now" <> suffix <> " := time.Now().UnixNano() / 1_000_000",
"fmt.Println(now" <> suffix <> " - cur" <> suffix <> ")",
"fmt.Println(toJson(a" <> suffix <> "))"
++ [ "openleetcode_timer_start_" <> suffix <> " := time.Now().UnixNano() / 1_000_000",
"openleetcode_result_" <> suffix <> " := " <> callExpr,
"openleetcode_timer_end_" <> suffix <> " := time.Now().UnixNano() / 1_000_000",
"fmt.Println(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> ")",
"fmt.Println(toJson(openleetcode_result_" <> suffix <> "))"
]
)
TypeScript ->
T.unlines
( ["console.log(" <> quotedMarker <> ");"]
++ prelude
++ [ "const _start" <> suffix <> " = Date.now();",
"const _a" <> suffix <> " = " <> callExpr <> ";",
"const _end" <> suffix <> " = Date.now();",
"console.log(String(_end" <> suffix <> " - _start" <> suffix <> "));",
"console.log(toJson(_a" <> suffix <> "));"
++ [ "const openleetcode_timer_start_" <> suffix <> " = Date.now();",
"const openleetcode_result_" <> suffix <> " = " <> callExpr <> ";",
"const openleetcode_timer_end_" <> suffix <> " = Date.now();",
"console.log(String(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> "));",
"console.log(toJson(openleetcode_result_" <> suffix <> "));"
]
)
Dart ->
T.unlines
( ["print(" <> quotedMarker <> ");"]
++ prelude
++ [ "final start" <> suffix <> " = Stopwatch()..start();",
"final a" <> suffix <> " = " <> callExpr <> ";",
"start" <> suffix <> ".stop();",
"print(start" <> suffix <> ".elapsedMilliseconds);",
"print(toJson(a" <> suffix <> "));"
++ [ "final openleetcode_timer_" <> suffix <> " = Stopwatch()..start();",
"final openleetcode_result_" <> suffix <> " = " <> callExpr <> ";",
"openleetcode_timer_" <> suffix <> ".stop();",
"print(openleetcode_timer_" <> suffix <> ".elapsedMilliseconds);",
"print(toJson(openleetcode_result_" <> suffix <> "));"
]
)
Cpp ->
T.unlines
( ["cout << " <> quotedMarker <> " << \"\\n\";"]
++ prelude
++ [ "auto start" <> suffix <> " = chrono::steady_clock::now();",
"auto a" <> suffix <> " = " <> callExpr <> ";",
"auto end" <> suffix <> " = chrono::steady_clock::now();",
"cout << chrono::duration_cast<chrono::milliseconds>(end" <> suffix <> " - start" <> suffix <> ").count() << \"\\n\";",
"cout << toJson(a" <> suffix <> ") << \"\\n\";"
++ [ "auto openleetcode_timer_start_" <> suffix <> " = chrono::steady_clock::now();",
"auto openleetcode_result_" <> suffix <> " = " <> callExpr <> ";",
"auto openleetcode_timer_end_" <> suffix <> " = chrono::steady_clock::now();",
"cout << chrono::duration_cast<chrono::milliseconds>(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> ").count() << \"\\n\";",
"cout << toJson(openleetcode_result_" <> suffix <> ") << \"\\n\";"
]
)
CSharp ->
T.unlines
( ["Console.WriteLine(" <> quotedMarker <> ");"]
++ prelude
++ [ "var sw" <> suffix <> " = Stopwatch.StartNew();",
"var a" <> suffix <> " = " <> callExpr <> ";",
"sw" <> suffix <> ".Stop();",
"Console.WriteLine(sw" <> suffix <> ".ElapsedMilliseconds);",
"Console.WriteLine(ToJson(a" <> suffix <> "));"
++ [ "var openleetcode_timer_" <> suffix <> " = Stopwatch.StartNew();",
"var openleetcode_result_" <> suffix <> " = " <> callExpr <> ";",
"openleetcode_timer_" <> suffix <> ".Stop();",
"Console.WriteLine(openleetcode_timer_" <> suffix <> ".ElapsedMilliseconds);",
"Console.WriteLine(ToJson(openleetcode_result_" <> suffix <> "));"
]
)
Java ->
T.unlines
( ["System.out.println(" <> quotedMarker <> ");"]
++ prelude
++ [ "long cur" <> suffix <> " = System.currentTimeMillis();",
"var a" <> suffix <> " = " <> callExpr <> ";",
"long now" <> suffix <> " = System.currentTimeMillis();",
"System.out.println(now" <> suffix <> " - cur" <> suffix <> ");",
"System.out.println(Json.toJson(a" <> suffix <> "));"
++ [ "long openleetcode_timer_start_" <> suffix <> " = System.currentTimeMillis();",
"var openleetcode_result_" <> suffix <> " = " <> callExpr <> ";",
"long openleetcode_timer_end_" <> suffix <> " = System.currentTimeMillis();",
"System.out.println(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> ");",
"System.out.println(Json.toJson(openleetcode_result_" <> suffix <> "));"
]
)
Kotlin ->
T.unlines
( ["println(" <> quotedMarker <> ")"]
++ prelude
++ [ "val cur" <> suffix <> " = System.currentTimeMillis()",
"val a" <> suffix <> " = " <> callExpr,
"val now" <> suffix <> " = System.currentTimeMillis()",
"println(now" <> suffix <> " - cur" <> suffix <> ")",
"println(Json.toJson(a" <> suffix <> "))"
++ [ "val openleetcode_timer_start_" <> suffix <> " = System.currentTimeMillis()",
"val openleetcode_result_" <> suffix <> " = " <> callExpr,
"val openleetcode_timer_end_" <> suffix <> " = System.currentTimeMillis()",
"println(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> ")",
"println(Json.toJson(openleetcode_result_" <> suffix <> "))"
]
)
Rust ->
T.unlines
( ["println!(\"" <> marker idx <> "\");"]
++ prelude
++ [ "let start" <> suffix <> " = Instant::now();",
"let result" <> suffix <> " = " <> callExpr <> ";",
"let duration" <> suffix <> " = start" <> suffix <> ".elapsed();",
"println!(\"{}\", duration" <> suffix <> ".as_millis());",
"println!(\"{}\", to_json(&result" <> suffix <> "));"
++ [ "let openleetcode_timer_start_" <> suffix <> " = Instant::now();",
"let openleetcode_result_" <> suffix <> " = " <> callExpr <> ";",
"let openleetcode_duration_" <> suffix <> " = openleetcode_timer_start_" <> suffix <> ".elapsed();",
"println!(\"{}\", openleetcode_duration_" <> suffix <> ".as_millis());",
"println!(\"{}\", to_json(&openleetcode_result_" <> suffix <> "));"
]
)
Ruby ->
T.unlines
( ["puts " <> quotedMarker]
++ prelude
++ [ "start" <> suffix <> " = (Time.now.to_f * 1000).to_i",
"a" <> suffix <> " = " <> callExpr,
"finish" <> suffix <> " = (Time.now.to_f * 1000).to_i",
"puts(finish" <> suffix <> " - start" <> suffix <> ")",
"puts to_json(a" <> suffix <> ")"
++ [ "openleetcode_timer_start_" <> suffix <> " = (Time.now.to_f * 1000).to_i",
"openleetcode_result_" <> suffix <> " = " <> callExpr,
"openleetcode_timer_end_" <> suffix <> " = (Time.now.to_f * 1000).to_i",
"puts(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> ")",
"puts to_json(openleetcode_result_" <> suffix <> ")"
]
)
Swift ->
T.unlines
( ["print(" <> quotedMarker <> ")"]
++ prelude
++ [ "let start" <> suffix <> " = Int(Date().timeIntervalSince1970 * 1000)",
"let result" <> suffix <> " = " <> callExpr,
"let end" <> suffix <> " = Int(Date().timeIntervalSince1970 * 1000)",
"print(end" <> suffix <> " - start" <> suffix <> ")",
"print(toJson(result" <> suffix <> "))"
++ [ "let openleetcode_timer_start_" <> suffix <> " = Int(Date().timeIntervalSince1970 * 1000)",
"let openleetcode_result_" <> suffix <> " = " <> callExpr,
"let openleetcode_timer_end_" <> suffix <> " = Int(Date().timeIntervalSince1970 * 1000)",
"print(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> ")",
"print(toJson(openleetcode_result_" <> suffix <> "))"
]
)
Default -> error "Unsupported"
Expand All @@ -466,17 +466,13 @@
T.unlines
( ["print(" <> quotedMarker <> ")"]
++ prelude
++ [ "_start_" <> suffix <> " = int(" <> pythonTimeExpr <> " * 1000)",
"_a_" <> suffix <> " = " <> callExpr,
"_end_" <> suffix <> " = int(" <> pythonTimeExpr <> " * 1000)",
"print(_end_" <> suffix <> " - _start_" <> suffix <> ")",
"print(to_json(_a_" <> suffix <> "))"
++ [ "openleetcode_timer_start_" <> suffix <> " = int(time.time() * 1000)",
"openleetcode_result_" <> suffix <> " = " <> callExpr,
"openleetcode_timer_end_" <> suffix <> " = int(time.time() * 1000)",
"print(openleetcode_timer_end_" <> suffix <> " - openleetcode_timer_start_" <> suffix <> ")",
"print(to_json(openleetcode_result_" <> suffix <> "))"
]
)
pythonTimeExpr =
case lang of
Python2 -> "_time.time()"
_ -> "time.time()"

parseMainBatchOutput :: [PreparedCase] -> Text -> IO (M.Map Int MainCaseOutput)
parseMainBatchOutput cases stdoutText =
Expand All @@ -485,7 +481,7 @@
parseMainSection _ section = do
let rawLines = T.lines section
revLines = reverse rawLines
resultLine = head revLines

Check warning on line 484 in core/Core/Test/Runner.hs

View workflow job for this annotation

GitHub Actions / Build (linux-arm64)

In the use of ‘head’

Check warning on line 484 in core/Core/Test/Runner.hs

View workflow job for this annotation

GitHub Actions / Build (linux-amd64)

In the use of ‘head’

Check warning on line 484 in core/Core/Test/Runner.hs

View workflow job for this annotation

GitHub Actions / Build (windows-amd64)

In the use of ‘head’

Check warning on line 484 in core/Core/Test/Runner.hs

View workflow job for this annotation

GitHub Actions / Build (darwin-arm64)

In the use of ‘head’

Check warning on line 484 in core/Core/Test/Runner.hs

View workflow job for this annotation

GitHub Actions / Build (darwin-amd64)

In the use of ‘head’
timeLine = revLines !! 1
stdoutLines = drop 2 revLines
ms = read (T.unpack (T.strip timeLine)) :: Int
Expand Down
7 changes: 5 additions & 2 deletions runtimes/python2/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import sys
import time as _time
import array
import time
import math
import heapq
import bisect
Expand All @@ -9,13 +10,15 @@
import re
import operator
import string
import datetime as _dt
import datetime
import collections
import json
import sortedcontainers
from functools import *
from collections import *
from heapq import *
from bisect import *
from sortedcontainers import SortedDict, SortedList, SortedSet

sys.setrecursionlimit(10**6)

Expand Down
8 changes: 5 additions & 3 deletions runtimes/python3/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
import array
import math
import heapq
import bisect
Expand All @@ -13,13 +14,14 @@
import decimal
import fractions
import statistics
import datetime as _dt
import datetime
import json
import sortedcontainers

from typing import *
from collections import *
from dataclasses import asdict, is_dataclass
from functools import cache, lru_cache
from dataclasses import *
from functools import *
from heapq import *
from bisect import *
from sortedcontainers import SortedDict, SortedList, SortedSet
Expand Down
8 changes: 4 additions & 4 deletions runtimes/rust/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pub struct Solution;
use std::time::Instant;
use std::rc::Rc;
use std::cell::RefCell;
use std::cmp::{max as _max, min as _min, Ordering as _Ordering, Reverse as _Reverse};
use std::cmp::*;
use std::collections::*;
use std::fs;
use itertools::Itertools as _Itertools;
use rand::prelude as _rand_prelude;
use regex::Regex as _Regex;
use itertools::Itertools as _;
use rand::prelude::*;
use regex::*;

${IMPORTS}

Expand Down
3 changes: 1 addition & 2 deletions runtimes/typescript/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "fs";
import * as __lodash_runtime from "lodash";
void __lodash_runtime;
import * as _ from "lodash";

type _TEST_INPUT_ = { val: any };
const _TEST_: Record<string, Record<string, _TEST_INPUT_>> = JSON.parse(
Expand Down
Loading
Loading