NEWTON
Asked
3 months ago
24
views
0
Does anyone know how I can create an array and populate it in the python hint? Basically something like
let (my_array: felt*) = alloc() %{ ids.my_array = [1, 2, 3] %}
Newton
asked
3 months ago
0
Accepted answer
There are two examples I found, that can work:
Simply add a hint:
let (local result : felt*) = alloc()
%{ segments.write_arg(ids.result, [1, 2, 3]) %}
This example proposed by Lord Cairo:
%{
IDENTIFIER_INDEX = 1
ADJACENT_VERTICES_INDEX = 2
for i in range(ids.graph_len):
neighbours_len = memory[ids.adjacent_vertices_count+i]
vertex_id = memory[ids.vertices.address_+i*ids.Vertex.SIZE+IDENTIFIER_INDEX]
adjacent_vertices_pointer = memory[ids.vertices.address_+i*ids.Vertex.SIZE+ADJACENT_VERTICES_INDEX]
print(f"{vertex_id} -> {{",end='')
for j in range (neighbours_len):
adjacent_vertex = memory[adjacent_vertices_pointer+j*ids.AdjacentVertex.SIZE+IDENTIFIER_INDEX]
print(f"{adjacent_vertex} ",end='')
print('}',end='')
print()
%}
Newton
answered
3 months ago
How can I use dynamic allocation in Cairo?
Cairo: Iterating through arrays
How do I create account using starknetjs?
Cairo: How do I initialize an array in cairo
Cairo: Getting the squared summation of felts in an array
How to use Hints in Cairo Lang?
Cairo: How do I iterate through an array of structs?
Is Kakarot part of the Starknet ecosystem?
How to convert tokens on starknet? Any DEXs AMMs?
Is there no way for me to have a struct as a `@storage_var` if it contains an array fo felts inside ?
I am already running a full Ethereum node on my server. Can I set the PATHFINDER_ETHEREUM_API_URL parameter to my node's endpoint for pathfinder?
How to install Cairo v0.10.0 on my device?
Python issues with Pathfinder
Questions about useStarknetExecute. Do we update the transaction manager on our end? [StarkNet/Cairo]