Hey everyone! The constraints of Hopscotch make for some really interesting challenges. Use that!

Background for idea

I came across Programming Puzzles and Code Golf StackExchange site the other day. And as I was solving a problem that had caught my eye, I remember the thrill of the Challenge Math and Brain Teaser Problems topic in the maths category here. So I thought, why don’t we have a programming puzzle topic here?

Post puzzles and answers here — anyone can join.

And post your thought processes! Remember to hide them in a details or a spoiler tag though, to let others come across their own solutions too.

and yep, it doesn’t have to be a complete answer. Trying is just as important! Elaborating on your thought processes so far may even bring you to some more ideas to try out. Post screenshots of your code, and talk about what you were thinking through.)

I unpublished it since I haven't completed the full idea, but here is the Fibonacci Sequence: https://c.gethopscotch.com/p/yu11rh5cq _{ (Yeah, I'm going to make an approximation bar for really large numbers! :D)}

This is a cool topic! I will try to do it, it is possible but if you code it in Python (or any other coding language) you can create lists inside variables. However, I don't use the new editor to code, it doesn't work. So, I haven't tried Self and all of the other new features, which means that it could work. I would like to try it, but the newer update won't load my drafts at all...

Wow, I thought that was great already (I think it looks awesome as well) and I see you are thinking about adding functionality for calculating an approximation for really big numbers that's amazing.

This is really cool! I love how you added the ability to choose a number from playing the project as well, I really didn't expect that. (For my ones, I just let there be a variable in the code that I could change so that was the basic minimum I set in the requirement of 'being able to specify the input n')

Yeah it is really handy what you can do in other languages!

And oh no that must be pretty frustrating (I would like to add, this doesn't have to be in the newest updates this idea was actually inspired by when Hopscotch didn't have a lot of functionalities like a long time ago!)

For MR.GAM3R

Very neat! I think that's really cool how you did it with just two variables current and previous. I remember when I first did it, I used a, b, c. That was totally unreadable XD so I just went back and changed it now:

(The initialisation here for nth fib number is a little dodgy...) I like how succinct yours is!

Edit: oh wait, in my picture, I think that should be repeat times(n-1), not n, according to the two starting numbers I defined in the problem.

And yep haha I'm really glad hearing you're interested in hanging around here (I love coming across topics here that make me feel like that )

And this is one idea I was thinking through (aside from the code I put in the previous details):

Here is something I was thinking through recently

I was interested in doing this with recursion in Hopscotch (even though it is an inefficient way of approaching Fibonacci's without a dictionary data type )

This is the pseudocode idea (thinking but not actually coding anything yet)

fibonacci(n):
if n = 1 then
return 0
else if n = 2 then
return 1
else
return (fibonacci(n-2) + fibonacci(n-1))

In Hopscotch, there are a few things you have to think about with recursion

The problem is, the variables (n-2)th fib number and (n-1)th fib number don't record as local variables for each time (each time the Fibonacci ability is run, they're both reset)

So I'm stuck there for now.

And again, this is just like the Challenges topic – anyone can submit a puzzle, and anyone can solve whichever they feel like (also inspiration from various other programming competitions)

Oh yeah, I think I forgot to mention, but the heart of this was also inspired by when Hopscotch first announced that it was Turing Complete on its blog – meaning that it can technically be used to solve any computer problem in the world. This made me go like woah so I was really inspired to try solving problems using just Hopscotch, leading to these ideas initially starting

25 divided by 2 is remainder 1
4 divided 9 is remainder 4
55 divided by 10 is remainder 5

Inputs: Someone looking at your program should be able to specify the number to divide into (the dividend), and the number to divide by (the divisor).

Outputs: The program should output the remainder when the dividend is divided by the divisor. (By the way, the result is called the quotient. And yep I just looked these up to check )

I'm really interested in seeing your Hopscotch code and hearing about your thought processes, so feel very welcome to share those!

These were some thoughts I had, even though I've done this before actually :)

The first time I did it, I ran on the idea that division is repeated subtraction. You keep subtracting the divisor from the number until the result is smaller than the divisor.

set number to dividend
set divisor
repeat until number < divisor
set number to number - divisor
end
set remainder to number
set text(remainder)

I have another idea using fractions. e.g. if you do 51 / 9, you get 5 and 6/9. If you multiply the fractional part by the divisor, 9, you will get the remainder.

set quotient to dividend/divisor
set floor_quotient to round(quotient - 0.5)
set fractional_remainder to (quotient - floor(quotient))
set remainder to (fractional_remainder * divisor)

Cool idea! I made one in JavaScript, here is some of the code:

var number = 11
//For boolean values (true or false), you can use 0 & 1.
var prime = true
// this is basically Repeat number times
for (i = 0; i < number; i++) {
If number % i = 0 {
prime = false
}
}
If prime {
// this is a prime number
} else {
// this is not a prime number
}