mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 06:46:18 -04:00
reorganize dir
Signed-off-by: Mia Steinkirch <mia.steinkirch@gmail.com>
This commit is contained in:
parent
1b6f705e7c
commit
a8e71c50db
276 changed files with 23954 additions and 0 deletions
54
other_resources/Top-Coder/.gitignore
vendored
Normal file
54
other_resources/Top-Coder/.gitignore
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
bin/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
|
||||
# Rope
|
||||
.ropeproject
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
*.pot
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
70
other_resources/Top-Coder/2013/tco2013_round3_3b_div1.py
Normal file
70
other_resources/Top-Coder/2013/tco2013_round3_3b_div1.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/python3
|
||||
# mari von steinkirch @2013
|
||||
# steinkirch at gmail
|
||||
|
||||
|
||||
|
||||
def findToneDiff(tones):
|
||||
tonesDiff = []
|
||||
n = len(tones)
|
||||
for i, tone in enumerate(tones):
|
||||
for j in range(i+1, len(tones)):
|
||||
sum_here = abs(tone - tones[j])
|
||||
tonesDiff.append([sum_here, i, j])
|
||||
return sorted(tonesDiff)
|
||||
|
||||
def findAllPossible(duration, tones, T):
|
||||
tonesDiff = findToneDiff(tones)
|
||||
sumsTone1 = [(song, i) for i, song in enumerate(duration) if song <= T]
|
||||
sumsTone2 = []
|
||||
for song in tonesDiff:
|
||||
sum_here = song[0] + duration[song[1]] + duration[song[2]]
|
||||
if sum_here <= T:
|
||||
sumsTone2.append((sum_here, song[1], song[2], 2))
|
||||
return sumsTone1, sumsTone2
|
||||
|
||||
|
||||
def findAllPossibleNext(sumsTone, T, n_music):
|
||||
sumsTone2 = []
|
||||
for i, song1 in enumerate(sumsTone):
|
||||
index1 = song1[1]
|
||||
for j in range(i+1, len(sumsTone)):
|
||||
song2 = sumsTone[j]
|
||||
index2 = song2[1]
|
||||
if index1 == index2:
|
||||
sum_here = song1[0] + song2[0]
|
||||
if sum_here < T:
|
||||
sumsTone2.append((sum_here, song2[1], song2[2], n_music))
|
||||
|
||||
|
||||
return sumsTone2
|
||||
|
||||
|
||||
def maxSongs(duration, tones, T):
|
||||
|
||||
if min(duration) >= T:
|
||||
return 0
|
||||
|
||||
sumsTone1, sumsTone = findAllPossible(duration, tones, T)
|
||||
if not sumsTone:
|
||||
return 1
|
||||
|
||||
while sumsTone:
|
||||
n_music = sumsTone[0][3]+1
|
||||
sumsTone = findAllPossibleNext(sumsTone, T, n_music)
|
||||
if not sumsTone:
|
||||
return n_music
|
||||
|
||||
|
||||
|
||||
def tests_250():
|
||||
print(maxSongs([3, 5, 4, 11], [2, 1, 3, 1], 17)) #3
|
||||
print(maxSongs([9, 11, 13, 17], [2, 1, 3, 4], 20)) #1
|
||||
print(maxSongs([100, 200, 300], [1,2,3], 99)) #0
|
||||
print(maxSongs([87,21,20,73,97,57,12,80,86,97,98,85,41,12,89,15,41,17,68,37,21,1,9,65,4,67,38,91,46,82,7,98,21,70,99,41,21,65,11,1,8,12,77,62,52,69,56,33,98,97], [88,27,89,2,96,32,4,93,89,50,58,70,15,48,31,2,27,20,31,3,23,86,69,12,59,61,85,67,77,34,29,3,75,42,50,37,56,45,51,68,89,17,4,47,9,14,29,59,43,3], 212))
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
tests_250()
|
||||
|
13
other_resources/Top-Coder/README.md
Normal file
13
other_resources/Top-Coder/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
### 🍬 [Top Coder](Solutions) for Fun or Profit
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
## License
|
||||
|
||||
When making a reference to my work, please use my [website](http://bt3gl.github.io/index.html).
|
||||
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />
|
||||
|
||||
This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/).
|
Loading…
Add table
Add a link
Reference in a new issue