Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2916371

Browse files
committed
two beta,one 6 kyu
1 parent 2075695 commit 2916371

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

β€Ž[6 kyu]Run-length encoding.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def run_length_encoding(s):
2+
if len(s) == 0:
3+
return []
4+
res = []
5+
char = s[0]
6+
count = 1
7+
for c in s[1:]:
8+
if char == c:
9+
count += 1
10+
else:
11+
res.append([count,str(char)])
12+
char = c
13+
count = 1
14+
res.append([count,str(char)])
15+
return res
16+
17+
18+
19+
print(run_length_encoding('hello world'))
20+
# [[1,'h'],[1,'e'],[2,'l'],

β€Ž[beta]Josephus Survivor.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def josephus_survivor(n,k):
2+
circle = [i for i in range(1,n+1)]
3+
index = -1
4+
while circle.count(0) != n-1:
5+
steps = k
6+
while steps > 0:
7+
if index + 1 > n-1:
8+
index = 0
9+
steps -= 1
10+
elif circle[index+1] == 0:
11+
index += 1
12+
else:
13+
index += 1
14+
steps -= 1
15+
circle[index] = 0
16+
print(circle,index)
17+
for num in circle:
18+
if num != 0:
19+
return num
20+
print(josephus_survivor(14,2))
21+
22+
#[1,2,3,4,5,6,7] - initial sequence 3
23+
#[1,2,4,5,6,7] => 3 is counted out 6
24+
#[1,2,4,5,7] => 6 is counted out 9 2
25+
#[1,4,5,7] => 2 is counted out 12 5
26+
#[1,4,5] => 7 is counted out 15
27+
#[1,4] => 5 is counted out
28+
#[4] => 1 is the last element - the survivor!

β€Ž[beta]Playing with digits.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def dig_pow(n, p):
2+
total = sum([(int(d)**power) for power,d in enumerate([d for d in str(n)],p)])
3+
return -1 if total%n != 0 else int(total/n)
4+
5+
print(dig_pow(46288, 3))

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /