challenge
|
01-19-2015, 03:06 PM
Post: #1
|
|||
|
|||
challenge
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. |
|||
01-19-2015, 07:22 PM
(This post was last modified: 01-19-2015 07:23 PM by Thomas Klemm.)
Post: #2
|
|||
|
|||
RE: challenge
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 |
|||
01-19-2015, 09:00 PM
Post: #3
|
|||
|
|||
RE: challenge
So Thomas, what is your number?
|
|||
01-19-2015, 09:08 PM
(This post was last modified: 01-19-2015 09:47 PM by Gilles.)
Post: #4
|
|||
|
|||
RE: challenge
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) |
|||
01-19-2015, 09:12 PM
Post: #5
|
|||
|
|||
RE: challenge
359
The forum prevented me from just posting this number: Quote: Please correct the following errors before continuing: |
|||
01-19-2015, 09:19 PM
Post: #6
|
|||
|
|||
RE: challenge | |||
01-19-2015, 09:37 PM
Post: #7
|
|||
|
|||
RE: challenge | |||
01-19-2015, 10:24 PM
Post: #8
|
|||
|
|||
RE: challenge
(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. |
|||
01-19-2015, 10:32 PM
Post: #9
|
|||
|
|||
RE: challenge
(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. -katie |
|||
01-19-2015, 10:52 PM
Post: #10
|
|||
|
|||
RE: challenge
(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:
|
|||
01-19-2015, 10:55 PM
(This post was last modified: 01-19-2015 11:07 PM by Gilles.)
Post: #11
|
|||
|
|||
RE: challenge
A shorter, faster but less understandable version :
Code:
|
|||
01-20-2015, 06:10 PM
(This post was last modified: 05-23-2016 06:59 PM by Hlib.)
Post: #12
|
|||
|
|||
RE: challenge
(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 |
|||
01-21-2015, 04:03 PM
(This post was last modified: 01-21-2015 04:47 PM by Hlib.)
Post: #13
|
|||
|
|||
RE: challenge
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?
|
|||
01-21-2015, 04:14 PM
Post: #14
|
|||
|
|||
RE: challenge | |||
01-21-2015, 09:10 PM
Post: #15
|
|||
|
|||
RE: challenge
A shorter RPL version :
Code:
|
|||
01-21-2015, 09:32 PM
(This post was last modified: 01-21-2015 09:38 PM by Don Shepherd.)
Post: #16
|
|||
|
|||
RE: challenge
(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. |
|||
01-21-2015, 10:07 PM
(This post was last modified: 01-21-2015 10:17 PM by Gilles.)
Post: #17
|
|||
|
|||
RE: challenge
(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 |
|||
01-22-2015, 10:10 AM
(This post was last modified: 05-23-2016 07:55 PM by Hlib.)
Post: #18
|
|||
|
|||
RE: challenge
(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 |
|||
06-21-2018, 02:43 PM
(This post was last modified: 06-21-2018 04:44 PM by Hlib.)
Post: #19
|
|||
|
|||
RE: challenge
Completing this old challenge
Code:
Link for downloading file in hp-50g or go49g+ .apk emulator: even_1..9999.hp49 ( 0.93 KB ) |
|||
06-22-2018, 12:38 AM
Post: #20
|
|||
|
|||
RE: challenge
What about numbers like 1360 thirteen hundred sixty ? Or 1664 sixteen hundred and sixty four ?
- Pauli |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)