This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!

Richard Gonzales

Greenhorn
+ Follow
since Sep 08, 2017
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
13
Given in last 30 days
5
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Richard Gonzales

Junilu Lacar wrote:Here's what I currently have. Made a few changes from the last time you tried it so the unlocked combination is also entered.



Sweet! I like it. Thanks for that! I'll try it again when I have some time and I'll compare with yours
I'm always looking to learn from others.

[Moderator edit: please don't quote entire posts, especially if they're long. Quote only the parts that are relevant to your reply]
1 week ago

Junilu Lacar wrote:I wrote a solution on repl.it -- you can run it here: https://quicklocksolver.jlacar.repl.run/

The unlock code has been hardcoded to 5714 for this solution but you can try different starting combinations to see the different instruction sets. I tested it a little bit and it seemed to be working correctly. To exit the loop, enter -1 when prompted for a combination.

The solution I wrote was 77 lines (including whitespace)



That was very kind of you to do. Yep! this is also exactly what I was thinking as well. I'll try and redo it just for fun
1 week ago

Paul Clapham wrote:I still don't understand the instructions. Is the program supposed to take the lock settings and the unlock combination and output the instructions for unlocking the lock? Or is the user supposed to input the instructions and the program will tell them whether they unlocked the lock or not?

Your original post said

Given the actual numbers and the combination to unlock, print instructions to unlock the lock using the minimum number of twists.



That sounds like the first option, which is not all that difficult. But it seems to me you've programmed some version of the second option... I think... although I didn't go through all of that code to try and understand it. That's a lot more difficult.



I didn't understand it either. The student just asked me to help them code the instructions and to capture users input so that it can change each ring individually. Initially, I was just going to have the user enter a combo to open the lock combo. It was my first time working with a student together as a non student myself lol.
1 week ago

Junilu Lacar wrote:That code seems to assume that the user enters a string that is "once" or "twice" -- that's totally the opposite of what the program is supposed to do.

The correct logic is (in pseudocode):

if (twists == 1) then display "once"
else if (twists == 2) then display "twice"
else display twists + " times"



Yeah, what I figured was that if the string contains "once" then int twist = 1;
if the string contains "twice" then int twist = 2;

twist being the number of times we twist each ring.
So if the current setting is 1000 and unlock is 3000
then an instruction would be Ring 1: twist up twice.
1 week ago

Junilu Lacar wrote:What's the purpose of this method?

Do you realize this method will return true if the string you pass in was "brrrring" or "suffering" or "Pringles" or "Ringwald" or "The bell is Ringing"?



You're right. I should consider the length also.
1 week ago

Junilu Lacar wrote:I don't understand what your code is doing nor how it's supposed to be the solution to the given problem. I think your interpretation of the problem way off.

As I interpret the given problem, the program should print out instructions on how to open a combination lock with the fewest twists, given the lock's current state (the numbers shown) and the unlock combination. So if the lock is currently showing 1729 and its unlock combination is 5714, then the output should be something like this (assuming the rings are numbered from 1 to 4 starting from the left):

Ring 1: 4 twists up
Ring 2: 0 twists
Ring 3: 1 twist down
Ring 4: 5 twists up (or down)

Total twists needed to unlock: 10

Your program takes user input but it interprets the input as a ring number. Why? I would think that if there were to be any user input at all, it would be to ask the user to enter either the current setting (with a fixed unlock combo) or to enter both current setting and the unlock combo. There's no need for the user to enter ring numbers.



Also, I understand now. Based off of the current setting we can just print instructions on the screen indicating how many twists it takes for each ring to get to the unlock combination.
1 week ago

Junilu Lacar wrote:If the program must display "once" instead of "1 time" and "twice" instead of "2 times" then you'll have a few more lines of logic to account for those two special cases.



Yes,
1 week ago

Junilu Lacar wrote:I don't understand what your code is doing nor how it's supposed to be the solution to the given problem. I think your interpretation of the problem way off.

As I interpret the given problem, the program should print out instructions on how to open a combination lock with the fewest twists, given the lock's current state (the numbers shown) and the unlock combination. So if the lock is currently showing 1729 and its unlock combination is 5714, then the output should be something like this (assuming the rings are numbered from 1 to 4 starting from the left):

Ring 1: 4 twists up
Ring 2: 0 twists
Ring 3: 1 twist down
Ring 4: 5 twists up (or down)

Total twists needed to unlock: 10

Your program takes user input but it interprets the input as a ring number. Why? I would think that if there were to be any user input at all, it would be to ask the user to enter either the current setting (with a fixed unlock combo) or to enter both current setting and the unlock combo. There's no need for the user to enter ring numbers.



This was a students work that I helped. I worked on it based on the students directions. I agree with you, it would have been less tedious to enter the current setting and unlock combo.
1 week ago
This question has already been coded. But I want to ask what would you guys do different? As in what methods would you use to tackle this problem and if there's better solutions than this.

A bicycle combination lock has four rings with numbers 0 through 9.
Given the actual numbers and the combination to unlock, print instructions
to unlock the lock using the minimum number of twists. A "twist up" increases
the number value of a ring, and a "twist down" decreases it. For example, if
the actual number shown is 1729 and the desired combination is 5714, write your
instructions in java like this:

Ring 1: Twist up 4 times
Ring 1: Twist up once
Ring 3: Twist down once
Ring 3: Twist down twice
1 week ago

Carey Brown wrote:

Richard Gonzales wrote:What I assume I'm going to do is just create a GUI first and then start coding the logic.


No, that's exactly backwards. Make the business logic and wrap it in a console interface. This is the easiest way to debug the logic without the complexities of a GUI. Then when the logic is all debugged strip away the console UI and replace it with a GUI.



Thanks for the input!
I'll do that instead
1 month ago
Hey guys,

I would like to make a task scheduler/calendar/reminder for myself.

For example, I would like to make a GUI where I can choose the times I want to complete something by.

Let's say I have to buy eggs by 2 days so I set that up in my GUI.

What I assume I'm going to do is just create a GUI first and then start coding the logic.

I'll do the logic first then the GUI.

However, I don't know how I would save my data.
For example, when I start up the app again (let's say one day later) I still want to see the reminders I posted a week ago and the times etc.
How would I go about this?
1 month ago

Campbell Ritchie wrote:Your linear search method is incorrect; you should return the index not the value found.

Simply looking at your methods: the main method is far too long. It should ideally contain one statement. That method needs breaking up into smaller methods. You might get as many as ten methods out of it.
Please remove the commented‑out code, which simply makes the code harder to read. Also remove comments which don't tell us anything that isn't obvious from looking at the code.
Calling a List newArray is a sure‑fire recipe for confusion.
Why have you got so many static members in your class? If you don't know why they are static, then making them static is a mistake. And making things static to shut up a compiler error is also a mistake.
You have some bad formatting: put some spaces in lines 107‑8 for example.
Lines 104‑108 bring me out in spots; I remember when I had to write that sort of code to fill an array, and am glad I don't have to any more, now I can write myRandom.ints(...).toArray()
You have the [] in the wrong place for array declarations. Never mind what you see in old books, the type of your array is int[], so you should write int[] numbers rather than int numbers[].
I prefer to call nanoTime twice before timing anything and once afterwards. That allows me to correct for how long it takes to get the time from the computer. It makes the arithmetic harder; it becomes something like after − start2 × 2 + start1. I am not sure how much that actually contributes to accuracy. The binary search may be faster than getting the time; I am not sure. I am also not convinced that you should time the loop which includes getting a random number. That will affect the time for your binary search. Remember that a binary search of a 1000‑element array takes approx. 10 iterations at worst. Put the timing inside the loop and add up the durations. Alternative. Create an array of keys to search and iterate that array seeking a different key each iteration of the loop.
How do you know you have the worst cases? Is seeking a non‑existent key really the worst case? It might be for linear search, but is that so for binary search too? Why is the worst case number 1? You should repeat the searches as many times as you did for the others.



Thanks so much for your thoughts. I will consider them as it helps a lot to make me a better programmer. I love all of the information you've provided.

Thanks again.
1 year ago

Pete Letkeman wrote:

Pete Letkeman wrote:You could start the app on device A and the stop watch time would be synchronized on device B and this was each app was correct to within five seconds...however network traffic may interfere.


Staring around 35 minutes or so into the video and going for about ten minutes
Here is a write up about this https://bradablog.appspot.com/?p=207
This may help give you a few ideas/hints on how you could do things,




Yeah! I want to do something similar to this.
Hopefully by now it got a bit easier to implement.
Awesome, this will definitely help!

Thanks again
1 year ago

Pete Letkeman wrote:Here are a few things to keep in mind:

  • Know your environment, are you making this for Android Wear, Android Auto, Android TV, Android Phone, etc.
  • Know the oldest version of the Android environment that you are going to support.
        The older the environment the more compatible devices, but the programming for Android 2.3 is different then Android 7.1
  • There are many tutorials for Android found here https://developer.android.com/ along with API documentations and samples.
  • There are now two officially Google supported languages for Android development, Java and Kotlin (https://kotlinlang.org).
        You can have both Java and Kotlin in the same project working side by site inside of Android Studio 3.x without any problems.
        I find it very handy to use the Kotlin data class even if everything else is Java.
  • Android services run in the background and would be helpful for this, see https://developer.android.com/guide/components/services.html
  • SQLite, https://developer.android.com/training/data-storage/sqlite.html, can be used to save your data locally on the Android device.
  • Notifications, https://developer.android.com/guide/topics/ui/notifiers/notifications.html, may be needed.
  • Playing media, https://developer.android.com/guide/topics/media/mediaplayer.html, may be needed.


  • thank you, for your response.
    Excellent, I'll definitely look into this.
    I think the hardest part would be syncing phones together so that they can ring simultaneously.
    1 year ago
    Hey Guys,

    I plan to make an android application where a user can set up an alarm to ring at a specific time that can connect with other users so that their alarms can ring simultaneously.

    I would like to know what I should specifically study when it comes to connecting a user with another user so that their alarms ring at the same time and in order for both alarms to stop ringing then a button should be pressed on the screen from both phones.

    I am new to android programming but not to Java so any advice on where to look at would be great.

    Any links or references would be a great help.
    1 year ago