NEWTON
Asked
1 month ago
17
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
1 month 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
1 month 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?
Issue with generating _abi.json file
Cairo: What is the difference between let and tempvar?
Nethermind's warp error: JavaScript heap out of memory
Any idea what this could be caused by?
What is the technical difference of Kakarot compare to Nethermind's Warp?
ApeWorX: Why am I getting an "account __execute__" error message?
Cairo: Getting the squared summation of felts in an array