Skip to content

Commit f67bfb3

Browse files
committed
daily bitwise hehe
1 parent 7c9f303 commit f67bfb3

File tree

6 files changed

+88
-5
lines changed

6 files changed

+88
-5
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: '[Updating markdown files]'
1+
name: "[Updating markdown files]"
22

33
on:
44
# Allows for munual runs of workflow
@@ -9,18 +9,18 @@ on:
99
branches:
1010
- main
1111
paths:
12-
- 'my-submissions/**'
12+
- "my-submissions/**"
1313

1414
permissions:
1515
contents: write
1616

1717
jobs:
1818
build:
1919
runs-on: ubuntu-latest
20-
20+
2121
steps:
2222
- name: Call and run markdown generator
2323
uses: Zanger67/WikiLeet@main
2424
with:
25-
# Insert your LeetCode username here!
26-
username: Zanger
25+
# Insert your LeetCode username here!
26+
username: Zanger

my-submissions/m2683 v1.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def doesValidArrayExist(self, derived: List[int]) -> bool:
3+
orig_prev = 0
4+
5+
for i, v in enumerate(derived) :
6+
orig_prev = v ^ orig_prev
7+
8+
if orig_prev == 0 :
9+
return True
10+
11+
orig_prev = 1
12+
13+
for i, v in enumerate(derived) :
14+
orig_prev = v ^ orig_prev
15+
16+
17+
return orig_prev == 1

my-submissions/m2683 v2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def doesValidArrayExist(self, derived: List[int]) -> bool:
3+
return not reduce(xor, derived)

my-submissions/m2683 v3.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bool doesValidArrayExist(int* derived, int derivedSize) {
2+
bool out = true;
3+
while (derivedSize > 0) {
4+
out ^= *derived;
5+
derivedSize -= 1;
6+
derived += 1;
7+
}
8+
return out;
9+
}

my-submissions/m2683 v3.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def doesValidArrayExist(self, derived: List[int]) -> bool:
3+
return not(derived.count(1) % 2)

my-submissions/m2683.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
0 = 0
2+
1 = 1
3+
2 = either 0 or 1
4+
5+
```
6+
orig[0] orig[1] orig[2] orig[3] .......
7+
| \\_____ | \\_____ | \\_____ | \\_____ |
8+
| \\ | \\ | \\ | \\ |
9+
der[0] der[1] der[2] der[3] .......
10+
11+
12+
der[i] = orig[i - 1] ^ orig[i]
13+
der[i] ^ orig[i - 1] = orig[i]
14+
15+
orig[i] = der[i] ^ orig[i - 1]
16+
```
17+
18+
Idea 1:
19+
I can see the possibility of there being multiple solutions
20+
or paths in a sense. The main issue at hand is that we don't
21+
know what the first index 0 value is in the original, thus
22+
we can't predict how it'll cascade. I think, right now, that
23+
the best option is to test both orig[0]=0 and orig[0] = 1
24+
SCRAPPED
25+
26+
Idea 2:
27+
The derived list can be interpreted as a mutation list that
28+
accumulates the changes. We can see if the end result for index
29+
0 is equal to the starting index we assigned maybe.
30+
31+
Basically, use the derived as an accumulating XOR then see if it
32+
matches the original assumed value we assigned it (0 or 1) and
33+
check for both cases of 0 and 1.
34+
35+
Version 2/3 Idea:
36+
37+
```
38+
orig_prev = v ^ orig_prev for v in derived
39+
==>
40+
final_orig_prev = starter ^ v for v in derived
41+
= derived[-1] ^ v for v in derived
42+
```
43+
44+
Use accumulate()
45+
46+
In the end it simplifies to just whether the xor of all derived
47+
values equals 0 or not, aka they all cancel each other out.
48+
This could also be calculated in just seeing if the number of
49+
ONES is odd.
50+
51+
**_It's bitwise math._**

0 commit comments

Comments
 (0)