← 返回首页
pytorch #game
import torch
puzzles = [
# Original Puzzles
{
'initial': torch.tensor([[1, 2], [3, 4]]),
'target': torch.tensor([1, 2, 3, 4]),
'solution': ['view -1'] # Flatten the tensor
},
{
'initial': torch.tensor([1, 2, 3, 4]),
'target': torch.tensor([[1, 2], [3, 4]]),
'solution': ['view 2 2'] # Reshape to 2x2
},
{
'initial': torch.tensor([[1, 2, 3], [4, 5, 6]]),
'target': torch.tensor([[1, 4], [2, 5], [3, 6]]),
'solution': ['transpose 0 1'] # Transpose the tensor
},
# Additional Puzzles
{
'initial': torch.tensor([1, 2, 3, 4]),
'target': torch.tensor([[1, 2, 3, 4]]),
'solution': ['unsqueeze 0'] # Add a new dimension at position 0
},
{
'initial': torch.tensor([[1, 2, 3, 4]]),
'target': torch.tensor([1, 2, 3, 4]),
'solution': ['squeeze 0'] # Remove the dimension at position 0
},
{
'initial': torch.tensor([[1, 2], [3, 4], [5, 6]]),
'target': torch.tensor([1, 3, 5, 2, 4, 6]),
'solution': ['permute 1 0', 'view -1'] # Permute and flatten
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6]),
'target': torch.tensor([[1, 2, 3], [4, 5, 6]]),
'solution': ['view 2 3'] # Reshape to 2x3
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6]),
'target': torch.tensor([[1], [2], [3], [4], [5], [6]]),
'solution': ['view -1 1'] # Reshape to 6x1
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6]),
'target': torch.tensor([[1, 4], [2, 5], [3, 6]]),
'solution': ['view 2 3', 'transpose 0 1'] # Reshape to 2x3 and transpose to 3x2
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]),
'target': torch.tensor([[1, 5], [2, 6], [3, 7], [4, 8]]),
'solution': ['view 2 4', 'transpose 0 1'] # Reshape to 2x4 and transpose to 4x2
},
{
'initial': torch.tensor([[1, 2], [3, 4], [5, 6], [7, 8]]),
'target': torch.tensor([1, 3, 5, 7, 2, 4, 6, 8]),
'solution': ['permute 1 0', 'view -1'] # Permute and flatten
},
{
'initial': torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]),
'target': torch.tensor([1, 5, 2, 6, 3, 7, 4, 8]),
'solution': ['transpose 0 1', 'view -1'] # Transpose and flatten
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]),
'target': torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]),
'solution': ['view 2 4'] # Reshape to 2x4
},
{
'initial': torch.tensor([[1], [2], [3], [4]]),
'target': torch.tensor([1, 2, 3, 4]),
'solution': ['squeeze 1'] # Remove the second dimension
},
{
'initial': torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
'target': torch.tensor([[1, 5], [2, 6], [3, 7], [4, 8]]),
'solution': ['permute 1 0 2', 'view -1 2'] # Permute and reshape
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]),
'target': torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
'solution': ['view 2 2 2'] # Reshape to 2x2x2
},
{
'initial': torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
'target': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]),
'solution': ['view -1'] # Flatten the tensor
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]),
'target': torch.tensor([[1], [2], [3], [4], [5], [6], [7], [8]]),
'solution': ['view 8 1'] # Reshape to 8x1
},
{
'initial': torch.tensor([[1, 2], [3, 4], [5, 6], [7, 8]]),
'target': torch.tensor([1, 3, 5, 7, 2, 4, 6, 8]),
'solution': ['view 2 4', 'permute 1 0'] # Reshape and permute
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
'target': torch.tensor([[1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12]]),
'solution': ['view 2 6', 'transpose 0 1'] # Reshape to 2x6 and transpose to 6x2
},
{
'initial': torch.tensor([[1, 2, 3], [4, 5, 6]]),
'target': torch.tensor([1, 4, 2, 5, 3, 6]),
'solution': ['transpose 0 1', 'view -1'] # Transpose and flatten
},
{
'initial': torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]),
'target': torch.tensor([1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12]),
'solution': ['permute 1 0', 'view -1'] # Permute and flatten
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
'target': torch.tensor([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]),
'solution': ['view 2 2 3'] # Reshape to 2x2x3
},
{
'initial': torch.tensor([1, 2, 3, 4]),
'target': torch.tensor([[[1, 2], [3, 4]]]),
'solution': ['view 1 2 2'] # Reshape to 1x2x2
},
{
'initial': torch.tensor([[[1, 2], [3, 4]]]),
'target': torch.tensor([1, 2, 3, 4]),
'solution': ['squeeze 0'] # Remove the first dimension
},
{
'initial': torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]),
'target': torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]),
'solution': ['view 2 4'] # Reshape to 2x4
},
{
'initial': torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]),
'target': torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
'solution': ['view 2 2 2'] # Reshape to 2x2x2
},
{
'initial': torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
'target': torch.tensor([[1, 2], [3, 4], [5, 6], [7, 8]]),
'solution': ['view -1 2'] # Reshape to 4x2
},
{
'initial': torch.tensor([1, 2, 3, 4]),
'target': torch.tensor([1, 2, 3, 4, 1, 2, 3, 4]),
'solution': ['view 2 4'] # Reshape to 2x4 (Alternatively, use repeat)
},
{
'initial': torch.tensor([1, 2, 3, 4]),
'target': torch.tensor([[1, 1], [2, 2], [3, 3], [4, 4]]),
'solution': ['unsqueeze 1', 'repeat 1 2'] # Add dimension and repeat
},
{
'initial': torch.tensor([[1, 2], [3, 4]]),
'target': torch.tensor([1, 2, 3, 4, 1, 2, 3, 4]),
'solution': ['view -1', 'repeat 2'] # Flatten and repeat
},
{
'initial': torch.tensor([[1, 2, 3], [4, 5, 6]]),
'target': torch.tensor([[[1, 4], [2, 5], [3, 6]]]),
'solution': ['transpose 0 1', 'unsqueeze 0'] # Transpose and add dimension
},
]