star_string = "*"
10.times do
puts star_string
star_string = star_string + "*"
end
I hope you can understand it. The program creates a string called “star_string”. Then it loops 10 times. Each time it loops it prints (puts) out star_string, and adds another * to the string. That way star_string gets longer and longer.
I’m also going to show you how this is done in C++. If you don’t want to learn C++ you don’t need to look at this. But C like languages are so common it’s worth at least gaining some familiarity with the syntax.
#include
#include
using namespace std;
int main() {
string star_string = “*”;
for(int n=0;n<10;n++) {
cout << star_string << endl;
star_string = star_string + "*";
}
}
[/sourcecode]
Can you modify the program so it prints more than one triangle, like this?
[sourcecode language="html"]
*
**
***
****
*****
******
*******
********
*********
**********
*
**
***
****
*****
******
*******
********
*********
**********
[/sourcecode]
Post your solution in the comments sections below. Everytime someone posts a solution, I'll try to post a new example and problem the next day.
The part 2 is now HERE.
I’ve been inspired by the QR codes made of cookies, paint tins etc. and decided to make a QR code from money.
It scans pretty well with the QR code reader on my iPhone, which is called imaginatively enough “Scan” by QR Code City.
I generated the QR code using an online service here.
I then annotated that image to make it easier to lookup different pixel values. Once that was one I started laying the coins out of a sheet of paper. I have to say if I were to do this again I’d get a A1 printer and print a template with markers just smaller than the coins. It would make life a lot easier.
My my reckoning the image is worth 3 pounds 13 pence. Next up a QR code made of chickens… or air… or ennui…
Hello Hackaday people, the post you are looking for is here
I found this watch at a market in Somerset. I find it utterly fascinating in that it’s a rather advanced piece of kit, certainly compared to what you could buy 10 years ago, while also being completely ridiculous.
It’s called a Montres Carlo 30420.
The scrolling text is quite impressive, and indicates to me a rather complex ASIC, or possibly even a small microcontroller. The battery life is also pretty good, it’s been running for months now using a CR2025.
You can see that they’ve decided to mount the LED backlight directly behind the screen, so it lights up a single spot. It’s also a multi colour LED, which flashes in various colours, because that’s cool.
Here are some internal pictures:
You can see that the Solar cell only has one terminal connected… I wonder if that can possibly work….
I always find it a shame that the ICs are buried in epoxy, I always have the urge to find out what’s under there. Perhaps I need an acid bath and a microscope…
My name is Nava Whiteford. I’ve worked for a few sequencing companies. I have equity in a few sequencing companies based on my previous employment (I try to be unbiased in my posts). You can contact me at: [email protected]