the problem's data are:
Analog clock is dived into 512 even sections, arrow/handle starts its movement at 0° and each tick/step moves it by 4.01°. Arrow/Handle can move only clockwise. What minimum ticks/steps count is needed for arrow/handle to visit all sections of the clock.
I'm trying to write a formula to calculate the count but can't quite wrap my head around it.
Is it possible to do it? If yes, how can I do it?
This site is for programmers, isn't it?
So we can hire our silicon friend to work for us ;)
Full circle is 360*60*60*4=5184000 units (unit is a quarter of angular second)
One step is 4*(4*3600+36) = 57744 units
One section is 4*360*3600/512 = 10125 units (we use quarters to make this value integer)
cntr = set()
an = 0
step = 57744
div = 10125
mod = 5184000
c = 0
while len(cntr) < 512:
sec = (an % mod) // div
cntr.add(sec)
an += step
c += 1
print(c)
>>804
unfortunately I can`t fully answer your question but the following may help:
Dividing the 512 Sections into degree gives you 1,4222° each.
Each round you cover 90 different section when starting between 0°-3.11° and 89° when starting between 3.12°-4.00°
For starting the rounds this gives you a change in starting degree of 0.9° every round except after the fourth, where it is only 0.89°(within the possible range of 0°-4° so all calculated mod 4).
So you have 0.9°->1.8°->2.7°->3.6°->0.49->1.39°...0.08°...
I hope this helps you devloping an algorithm
I want to count the neighbors and the neighbors neighbors of a turtle to kind of find out a way to calculate the eigenvector-centrality. Since I can´t get the NW:extensions to work and my prof neither. I thought of building a method myself. Since I don´t have that much time until the first round of presentation, I try my best to just count the neighbors and the neighbors neighbors of a turtle.
I decided to have a turtles-own, which counts all neighbors and then sum all the neighbors and neighbors neighbors. But I am stuck in my head and cant get it to work.
set Neighborscount count(link-neighbors)
Anyone has any ideas?
Also a final way to get the eigenvector-centrality to work would be very much appreciated.
First, my main recommendation is to get NW working. I'd be happy to help with that.
Barring that, the below assumes you're working with undirected networks. If that's not the cast, let me know.
The problem with the method that you describe is that it will count some neighbors-of-neighbors multiple times. Instead, you can get the agent-set of neighbors-of-neighbors, and then just count it:
to-report neighbors-of-neighbors
report turtle-set [ link-neighbors ] of link-neighbors
end
Then, [ count neighbors-of-neighbors ] of turtle 0 will give the number of neighbors of neighbors of turtle 0.
Now, a few points:
This will include the turtle itself, since a turtle is always a link neighbor of its link neighbors. If you don't want to include the turtle itself, you can just throw an other in there: [ count other neighbors-of-neighbors ] of turtle 0.
This won't include turtles that are link neighbors of turtle 0, but are not linked to any other neighbors of turtle 0. To add those in, you might consider a procedure like this:
to-report turtles-in-link-radius [ n ]
let result turtle-set self
repeat n [
set result (turtle-set result [ link-neighbors ] of result)
]
report result
end
This can then be used, for instance, like so: [ count turtle-in-link-radius 2 ] of turtle 0 to count all turtles at most 2 hops from turtle 0. This reporter has the same behavior as nw:turtles-in-radius, though it will be significantly slower.
Now, I first noted that your idea would count some turtles multiple times. Given that you're interested in something like eigenvector-centrality, maybe this is what you want. In that case you can do this: [ sum [ count link-neighbors ] of link-neighbors ] of turtle 0 to get it without having to bother with a turtles-own. That said, if you do use a turtles-own, you can actually calculate the eigenvector centrality itself:
turtles-own [
...
next-ec ;; helper variable for iteratively computing eigenvector-centrality
eigenvector-centrality
...
]
to calculate-eigenvector-centralities
ask turtles [
set eigenvector-centrality 1
]
repeat 100 [ ;; the higher this number, the more accurate the value. NW uses 100
ask turtles [
set next-ec sum [ eigenvector-centrality ] of link-neighbors
]
let max-ec max [ next-ec ] of turtles
ask turtles [
set eigenvector-centrality next-ec / max-ec ;; normalize
]
]
end
Call calculate-eigenvector-centralities to calculate all turtles eigenvector centralities. The turtles' eigenvector centralities will then be stored in eigenvector-centrality. Note that this code won't work for disconnected networks: each component has to be normalized independently, which is what NW does, but there's no easy way to do that in NetLogo without using NW.
Say we have a set of 3D (integer) coordinates from (0,0,0) to (100,100,100)
We want to visit each possible coordinate (100^3 possible coordinates to visit) without visiting each coordinate more than once.
The sum of the differences between each coordinate in adjacent steps cannot be more than 2 (I don't know if this is possible. If not, then minimized)
for example, the step from (0,2,1) to (2,0,0) has a total difference of 5 because |x1-x2|+|y1-y2|+|z1-z2| = 5
How do we generate such a sequence of coordinates?
for example, to start:
(0,0,0)
(0,0,1)
(0,1,0)
(1,0,0)
(1,0,1)
(0,0,2)
(0,1,1)
(0,2,0)
(1,1,0)
(2,0,0)
(3,0,0)
(2,0,1)
(1,0,2)
(0,0,3)
etc...
Anyone know an algorithm that will generate such a sequence to an arbitrary coordinate (x,y,z) where x=y=z or can prove that it is impossible for such and algorithm to exist? Thanks
Extra credit: Show how to generate such a sequence with x!=y!=z :D
One of the tricks (there are other approaches) is to do it one line [segment] at a time, one plane [square] at a time. Addressing the last part of the question, this approach works, even if the size of the volume visited is not the same in each dimension (ex: a 100 x 6 x 33 block).
In other words:
Start at (0,0,0),
move only on the Z axis till the end of the segment, i.e.
(0,0,1), (0,0,2), (0,0,3), ... (0,0,100),
Then move to the next line, i.e.
(0,1,100)
and come backward on the line, i.e.
(0,1,99), (0,1,98), (0,1,97), ... (0,1,0),
Next to the next line, going "forward"
And repeat till the whole "panel is painted", i.e ending at
... (0,100,99), (0,100,100),
Then move, finally, by 1, on the X axis, i.e.
(1,100,100)
and repeat on the other panel,but on this panel going "upward"
etc.
Essentially, each move is done on a single dimension, by exactly one. It is a bit as if you were "walking" from room to room in a 101 x 101 x 101 building where each room can lead to any room directly next to it on a given axis (i.e. not going joining diagonally).
Implementing this kind of of logic in a programming language is trivial! The only mildly challenging part is to deal with the "back-and-forth", i.e. the fact that sometimes, some of the changes in a given dimension are positive, and sometimes negative).
Edit: (Sid's question about doing the same diagonally):
Yes! that would be quite possible, since the problem states that we can have a [Manhattan] distance of two, which is what is required to go diagonally.
The path would be similar to the one listed above, i.e. doing lines, back-and-forth (only here lines of variable length), then moving to the next "panel", in the third dimension, and repeating, only going "upward" etc.
(0,0,0) (0,0,1)
(0,1,0) first diagonal, only 1 in lengh.
(0,2,0) "turn around"
(0,1,1) (0,0,2) second diagonal: 2 in length
(0,0,3) "turn around"
(0,1,2) (0,2,1) (0,3,0) third diagonal: 3 in length
(0,4,0) turn around
etc.
It is indeed possible to mix-and-match these approaches, both at the level of complete "panel", for example doing one diagonally and the next one horizontally, as well as within a given panel, for example starting diagonally, but when on the top line, proceeding with the horizontal pattern, simply stopping a bit earlier when looping on the "left" side, since part of that side has been handled with the diagonals.
Effectively this allows a rather big (but obviously finite) number of ways to "paint" the whole space. The key thing is to avoid leaving (too many) non painted adjacent area behind, for getting back to them may either bring us to a dead-end or may require a "jump" of more than 2.
Maybe you can generalize Gray Codes, which seem to solve a special case of the problem.
Seems trivial at first but once started, it is tricky! Especially the steps can be 1 or 2.
This is not an answer but more of a demostration of the first 10+ steps for a particular sequence which hopefully can help others to visualise. Sid, please let me know if the following is wrong:
s = No. of steps from the prev corrdinates
c1 = Condition 1 (x = y = z)
c2 = Condition 2 (x!= y!= z)
(x,y,z) s c1 c2
---------------
(0,0,0) * (start)
(0,0,1) 1
(0,1,0) 2
(1,0,0) 2
(1,0,1) 1
(1,1,0) 2
(1,1,1) 1 *
(2,1,1) 1
(2,0,1) 1 *
(2,0,0) 1
(2,1,0) 1 *
(2,2,0) 1
(2,2,1) 1
(2,2,2) 1 *
(2,3,2) 1
(2,3,3) 1
(3,3,3) 1 *
(3,3,1) 2
(3,2,1) 1 *
(3,2,0) 1 *
.
.
.