This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with open(input('izlazna datoteka: '), 'w') as izlaz: | |
| for p in enumerate(open(input('ulazna datoteka: ')), 1): | |
| print(*p, sep=': ', end='', file=izlaz) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def hanoi(n, sa, na): | |
| assert sa != na | |
| if n: | |
| pomoćni, = {1, 2, 3} - {sa, na} | |
| hanoi(n - 1, sa, pomoćni) | |
| print(f'{n}. disk {sa} -> {na}') | |
| hanoi(n - 1, pomoćni, na) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def ostaci(nazivnik): | |
| d = 1 | |
| while ...: | |
| yield d | |
| d = d * 10 % nazivnik | |
| def period(nazivnik): | |
| prva_pojava = {} | |
| for indeks, ostatak in enumerate(ostaci(nazivnik)): | |
| if ostatak in prva_pojava: return indeks - prva_pojava[ostatak] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ulaz = open('random.FASTA') | |
| ulaz = {linija.strip('>\n'): next(ulaz).strip() for linija in ulaz}.values() | |
| def podriječi(riječ): | |
| ukupna_duljina = len(riječ) | |
| for duljina in range(ukupna_duljina, 0, -1): | |
| for početak in range(ukupna_duljina - duljina + 1): | |
| yield riječ[početak : početak + duljina] | |
| def rješenje(ulaz): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abeceda = 'ab' | |
| def kod(riječ, abeceda=abeceda): | |
| rezultat = 0 | |
| for slovo in riječ: | |
| rezultat = rezultat * len(abeceda) + 1 + abeceda.index(slovo) | |
| return rezultat | |
| def dekod(kod, abeceda=abeceda): | |
| b = len(abeceda) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """RAM-interpreter""" | |
| progtext = '''\ | |
| 0. dec r2, 3 | |
| 1. inc r0 | |
| 2. goto 0 | |
| 3. dec r1, 3 | |
| 4. dec r1, 8 | |
| 5. inc r0 | |
| 6. inc r0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools, itertools | |
| ceste = set('ABCDE') | |
| rb_ceste = sorted(ceste).index | |
| putovi = {odakle + kamo for odakle in ceste - {'C'} | |
| for kamo in ceste - {'E', odakle}} | |
| def kružno(put): | |
| odakle, kamo = put | |
| return sorted([rb_ceste(odakle) * 2, rb_ceste(kamo) * 2 + 1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import dataclasses | |
| @dataclasses.dataclass | |
| class Between: | |
| down: ... | |
| up: ... | |
| def __set_name__(self, cls, name): self.name = name | |
| def __get__(self, instance, owner): return vars(instance)[self.name] | |
| def __set__(self, instance, value): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import itertools, tkinter, weakref | |
| from tkinter import ttk | |
| def is_coord(index): | |
| return isinstance(index, tuple) and len(index) == 2 | |
| def rangify(coord): | |
| if isinstance(coord, slice): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://www.catonmat.net/blog/generate-random-json-data-structures/ | |
| from random import choice, randrange, random, choices | |
| def random_JSON(max_depth): | |
| types = [number, string, boolean] + [array, object]*bool(max_depth) | |
| return choice(types)(max_depth) | |
| def number(_, max_num=1<<32): | |
| num = random() * max_num if randrange(2) else randrange(max_num) |