File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ # For up to date code:
2+ # https://github.com/codereport/bqn-code/blob/main/leetcode/426-2.bqn
3+
4+ # Link: https://leetcode.com/problems/smallest-number-with-all-set-bits
5+
6+ u ⇐ •Import " /home/cph/bqn-test/test.bqn"
7+ fn ⇐ •Import " /home/cph/bqn-code/lib/fun.bqn"
8+
9+ GetLargestOutlier ← {
10+ pairs ← ⍷⌽ ¨ ⊸ ∾ (∾⋈ fn ._Tri ↕≠ 𝕩 )⊏ ¨ < 𝕩
11+ ⌈ ´ (+ ´ 𝕩 )⊸ ((⊑ ∘ ⊢=- ⟜ (+ ´ ))×⊢ ´ ∘ ⊢ )¨ pairs
12+ }
13+
14+ # Tests
15+ u .UnitTest (GetLargestOutlier 2 ‿3 ‿5 ‿10 ) ≡ 10
16+ u .UnitTest (GetLargestOutlier ¯2 ‿¯1 ‿¯3 ‿¯6 ‿4 ) ≡ 4
17+ u .UnitTest (GetLargestOutlier 1 ‿1 ‿1 ‿1 ‿1 ‿5 ‿5 ) ≡ 5
Original file line number Diff line number Diff line change 1+ # For up to date code:
2+ # https://github.com/codereport/bqn-code/blob/main/leetcode/427-1.bqn
3+
4+ # Link: https://leetcode.com/problems/transformed-array
5+
6+ u ⇐ •Import " /home/cph/bqn-test/test.bqn"
7+
8+ ConstructTransformedArray ← {𝕩 ⊏ ˜ (≠ 𝕩 )| 𝕩 +↕≠ 𝕩 } # Explicit
9+ ConstructTransformedArray2 ← (≠|↕ ∘ ≠ ⊸ + )⊸ ⊏ # Tacit
10+
11+ # Tests
12+ u .UnitTest (ConstructTransformedArray 3 ‿¯2 ‿1 ‿1 ) ≡ 1 ‿1 ‿1 ‿3
13+ u .UnitTest (ConstructTransformedArray ¯1 ‿4 ‿¯1 ) ≡ ¯1 ‿¯1 ‿4
14+ u .UnitTest (ConstructTransformedArray2 3 ‿¯2 ‿1 ‿1 ) ≡ 1 ‿1 ‿1 ‿3
15+ u .UnitTest (ConstructTransformedArray2 ¯1 ‿4 ‿¯1 ) ≡ ¯1 ‿¯1 ‿4
You can’t perform that action at this time.
0 commit comments