Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1185 - Cub2
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Explicație = '''Atenție! Pentru acest test se rezolvă doar cerința 2).''' <code>4</code> – becuri inscripționate cu numere prime pe fața 1: <code>2, 3, 17, 19</code> <code>3</code> – becuri inscripționate cu numere prime pe fața 2: <code>3, 5, 23</code> <code>4</code> – becuri inscripționate cu numere prime pe fața 3: <code>5, 7, 13, 23</code> <code>3</code> – becuri inscripționate cu numere prime pe fața 4: <code>7, 11, 19</code> <syntaxhighlight lang="python" line="1"> def generate_spiral_layer(n, start_val): """ Generate a spiral layer of size n x n starting from start_val """ layer = [[0] * n for _ in range(n)] num = start_val for layer_idx in range((n + 1) // 2): for i in range(layer_idx, n - layer_idx): layer[layer_idx][i] = num num += 1 for i in range(layer_idx + 1, n - layer_idx): layer[i][n - layer_idx - 1] = num num += 1 for i in range(n - layer_idx - 2, layer_idx - 1, -1): layer[n - layer_idx - 1][i] = num num += 1 for i in range(n - layer_idx - 2, layer_idx, -1): layer[i][layer_idx] = num num += 1 return layer def generate_cube(N): """ Generate a cube of size N x N x N filled in spiral order """ cube = [[[0] * N for _ in range(N)] for _ in range(N)] num = 1 for z in range(N): layer = generate_spiral_layer(N, num) for y in range(N): for x in range(N): cube[z][y][x] = layer[y][x] num += N * N return cube def find_coordinates(cube, V): """ Find coordinates (x, y, z) of the value V in the cube """ N = len(cube) for z in range(N): for y in range(N): for x in range(N): if cube[z][y][x] == V: return (x + 1, y + 1, z + 1) return None def count_lights_on_faces(cube): """ Count the number of lights on each face of the cube """ N = len(cube) counts = {'front': 0, 'back': 0, 'left': 0, 'right': 0, 'top': 0, 'bottom': 0} # Counting lights on each face for z in range(N): counts['top'] += N counts['bottom'] += N for y in range(N): counts['front'] += N counts['back'] += N for x in range(N): counts['left'] += N counts['right'] += N return counts # Example Usage N = 3 V = 7 # Example value to find coordinates for cube = generate_cube(N) coordinates = find_coordinates(cube, V) face_counts = count_lights_on_faces(cube) print(f"Coordinates of the light with number {V}: {coordinates}") print(f"Number of lights on each face: {face_counts}") </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width