Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » counting numbers
- zeez113
- New Scratcher
1 post
counting numbers
I am using scratch. I acquire two values from the user and have to find the numbers divisible by 2 & 3 between those values . How can I count those numbers without using arrays ( just by using basic operations) ?
here is the project :
https://scratch.mit.edu/projects/63845720/#editor
here is the project :
https://scratch.mit.edu/projects/63845720/#editor
- deck26
- Scratcher
1000+ posts
counting numbers
If you're just counting them you don't need to actually find them.
eg for divisible by 2, look at the different combinations (start odd or even, end odd or even) and you should be able to work out how to count the number of even values. Do this with a small range just to get the pattern.
Similarly for divisible by 3. There are now 9 combinations (start mod 3 = 0, 1, 2 and end mod 3 = 0, 1 ,2) but you should still be able to work something out. If the range is 0 mod 3 you can just divide the range by 3 (eg you have range of 27 there are 9 numbers divisible by 3 and it doesn't matter whether it is 1 to 27 or 221 to 247 or whatever).
eg for divisible by 2, look at the different combinations (start odd or even, end odd or even) and you should be able to work out how to count the number of even values. Do this with a small range just to get the pattern.
Similarly for divisible by 3. There are now 9 combinations (start mod 3 = 0, 1, 2 and end mod 3 = 0, 1 ,2) but you should still be able to work something out. If the range is 0 mod 3 you can just divide the range by 3 (eg you have range of 27 there are 9 numbers divisible by 3 and it doesn't matter whether it is 1 to 27 or 221 to 247 or whatever).
- deck26
- Scratcher
1000+ posts
counting numbers
Not sure you understood the question but certainly no need to necropost. use this block:((The Number) mod (2, 3 etc.))
- Rangnarok
- Scratcher
29 posts
counting numbers
when green flag clickedThat's to make it say the numbers, but all the numbers would appear in the list.
delete (all) of [numbers divisible]
ask [a?] and wait
set [a] to (answer)
ask [b?] and wait
set [b] to (answer)
set [count] to (a)
repeat until <(count) = (b)>
if <<((count) mod (2)) = [0]> or <((count) mod (3)) = [0]>> then
add (count) to [numbers divisible]
end
change [count] by (1)
end
set [what to say] to []
repeat (length of [numbers divisible] :: list)
set [what to say] to (join ((join(what to say) (item (1 of [numbers divisible] :: list))) [,])
end
say (what to say)
Last edited by Rangnarok (Feb. 12, 2022 18:11:26)
when green flag clicked
forever
play [Minecraft]
play [Hollow Knight]
play [Undertale]
play [Deltarune]
play [TLoZ BotW]
play [TLoZ TotK]
play [It Takes Two]
play [Geometry Dash]
play [Terraria]
code [Scratch]
code [C#]
end
when [russia] > [ukraine]
if <[russia] invades [ukraine] ?> then
repeat until <([state] of[russia]) = [peace]>
̶p̶e̶n̶ foot down
replace item [state] of [putin] with [snitch]
globally [protest]
end
end
RUUUUNNN ITS THE EVIL KUMQUATS
You didnt need to scroll all the way down here btw…
- Discussion Forums
- » Help with Scripts
- » counting numbers