challenge - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: challenge (/thread-2882.html) |
challenge - Don Shepherd - 01-19-2015 03:06 PM How many integers (from 1 to 9999) are evenly divisible by the number of letters in their name? First one is 4 (divisible by f-o-u-r 4). Last one happens to be 9999 (divisible by n-i-n-e-t-h-o-u-s-a-n-d-n-i-n-e-h-u-n-d-r-e-d-n-i-n-e-t-y-n-i-n-e 33). For you HP50 fans, I expect to see a one-line RPL program! If Valentin is lurking, he just knows the answer without writing a program. I'll post a Tandy model 102 BASIC program in a couple of days. RE: challenge - Thomas Klemm - 01-19-2015 07:22 PM I've started with this in Python: Code: units = ['','one','two','three','four','five','six','seven','eight','nine'] But as we are only interested in the number of letters we can use these instead: Code: units_len = [0, 3, 3, 5, 4, 4, 3, 5, 5, 4] In my program zero is included thus you have to subtract 1 from the result. Not in RPL and not a one-liner, I know. Cheers Thomas RE: challenge - Don Shepherd - 01-19-2015 09:00 PM So Thomas, what is your number? RE: challenge - Gilles - 01-19-2015 09:08 PM RPL but not one-liner. Recursive approch. Code:
Count returns 359 (without AND) By the way, my english is bad but 9999 should it not be writen as : n-i-n-e-t-h-o-u-s-a-n-d-n-i-n-e-h-u-n-d-r-e-d-A-N-D-n-i-n-e-t-y-n-i-n-e ? (36 letters with an AND inside) RE: challenge - Thomas Klemm - 01-19-2015 09:12 PM 359 The forum prevented me from just posting this number: Quote: Please correct the following errors before continuing: RE: challenge - Thomas Klemm - 01-19-2015 09:19 PM (01-19-2015 09:08 PM)Gilles Wrote: "hundredand" Our results probably won't agree. From the example 9999 I assumed not to use and after hundred. Maybe Don can clarify this? Cheers Thomas RE: challenge - Gilles - 01-19-2015 09:37 PM (01-19-2015 09:19 PM)Thomas Klemm Wrote:(01-19-2015 09:08 PM)Gilles Wrote: "hundredand" I changed my program. I get 359 also ;D RE: challenge - Don Shepherd - 01-19-2015 10:24 PM (01-19-2015 09:19 PM)Thomas Klemm Wrote:(01-19-2015 09:08 PM)Gilles Wrote: "hundredand" Yes, in America at least, the word "and" is reserved for the decimal point. In other words, 4278.16 would be "four thousand two hundred seventy eight AND 16 hundredths." That's what we teach the kids. So, yes, 359, and if you include zero (which is evenly divisible by 4) in the tally, you get the model number of IBM's most famous and (probably) popular mainframe computer. Hmm, maybe that is the basis of how they named it. RE: challenge - Katie Wasserman - 01-19-2015 10:32 PM (01-19-2015 10:24 PM)Don Shepherd Wrote: Yes, in America at least, the word "and" is reserved for the decimal point. In other words, 4278.16 would be "four thousand two hundred seventy eight AND 16 hundredths." That's what we teach the kids. Perhaps, but it's not how most adults say it, at least in my experience. I think that "four thousand two hundred seventy eight POINT sixteen" or "four thousand two hundred seventy eight SPOT sixteen" or "four thousand two hundred seventy eight POINT (or SPOT or even DECIMAL) one six" is more much common. "SPOT" is very common among wall street-type people, not so much so with non-financial people. RE: challenge - Don Shepherd - 01-19-2015 10:52 PM (01-19-2015 10:32 PM)Katie Wasserman Wrote:(01-19-2015 10:24 PM)Don Shepherd Wrote: Yes, in America at least, the word "and" is reserved for the decimal point. In other words, 4278.16 would be "four thousand two hundred seventy eight AND 16 hundredths." That's what we teach the kids. Wow, I never heard of SPOT before. But then again, I've never visited Wall Street. Yes, POINT is very common. I teach my students to reserve the word AND for the decimal point, but when they get out in the real world, they hear everything, like "four double naught seven" for 4007. Here is some BASIC code for the Tandy 102, a nice little BASIC machine: Code:
RE: challenge - Gilles - 01-19-2015 10:55 PM A shorter, faster but less understandable version : Code:
RE: challenge - Hlib - 01-20-2015 06:10 PM (01-19-2015 03:06 PM)Don Shepherd Wrote: How many integers (from 1 to 9999) are evenly divisible by the number of letters in their name? I understand your irony :-) For such simple tasks a BASIC is more comfortable. First I wrote this program on CASIO-BASIC for FX-2.0 within an hour, while my algorithm on RPL did not finished yet. Code:
N=9999 K=359 time=350sec size=256b RE: challenge - Hlib - 01-21-2015 04:03 PM I don`t see RPL fonders. Were are you? Whether <Tim Vessman> will be able to answer us something to show advantages of RPL or "banana-products" like HP-NEXT? RE: challenge - Don Shepherd - 01-21-2015 04:14 PM (01-21-2015 04:03 PM)Hlib Wrote: I don`t see RPL fonders. Were are you? I think Giles entry above is an RPL program, although not a "one-liner". I'm always amazed at what people can do with RPL, I just never wanted to take the time to learn it. RE: challenge - Gilles - 01-21-2015 09:10 PM A shorter RPL version : Code:
RE: challenge - Don Shepherd - 01-21-2015 09:32 PM (01-21-2015 04:03 PM)Hlib Wrote: I don`t see RPL fonders. Were are you? Whether <Tim Vessman> will be able to answer us something to show advantages of RPL or "banana-products" like HP-NEXT? I would say that Gilles (below) has shown some advantages of RPL in this type of application. I personally like the straightforward and simple nature of BASIC, but I do appreciate RPL for it's power. RE: challenge - Gilles - 01-21-2015 10:07 PM (01-20-2015 06:10 PM)Hlib Wrote: I understand your irony :-) For such simple tasks a BASIC is more comfortable. First I wrote this program on CASIO-BASIC for FX-2.0 within an hour, while my algorithm on RPL did not finish yet. Why a new algorithm ? ;D Code:
By the way, it is curious that FRAC (0/0) returns 0 on the Casio RE: challenge - Hlib - 01-22-2015 10:10 AM (01-21-2015 10:07 PM)Gilles Wrote: Why a new algorithm ? ;D Thank you for this report. Command ...Isz N:(Frac (N/V)=0)+K→K:... on CASIO works as ...N+1→N:If N≠0:Then (Frac (N/V)=0)+K→K:IfEnd:... I do appreciate RPL for it's power too, but not in such primitive examples. EDIT: <primitive> examples RE: challenge - Hlib - 06-21-2018 02:43 PM Completing this old challenge Code:
Link for downloading file in hp-50g or go49g+ .apk emulator: even_1..9999.hp49 ( 0.93 KB ) RE: challenge - Paul Dale - 06-22-2018 12:38 AM What about numbers like 1360 thirteen hundred sixty ? Or 1664 sixteen hundred and sixty four ? - Pauli |