Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #59524 > unrolled thread
| Started by | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| First post | 2017-05-19 03:44 +0000 |
| Last post | 2017-05-19 01:24 -0400 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.forth
Rosetta: Increment a numerical string "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-19 03:44 +0000
Re: Rosetta: Increment a numerical string rickman <gnuarm@gmail.com> - 2017-05-19 00:16 -0400
Re: Rosetta: Increment a numerical string Julian Fondren <julian.fondren@gmail.com> - 2017-05-18 21:47 -0700
Re: Rosetta: Increment a numerical string rickman <gnuarm@gmail.com> - 2017-05-19 01:24 -0400
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Date | 2017-05-19 03:44 +0000 |
| Subject | Rosetta: Increment a numerical string |
| Message-ID | <oflpmm$13v1$1@gioia.aioe.org> |
"foo99bar".sub(/\d+/){|s| s.to_i + 1}
==>"foo100bar"
"foo99bar".sub(/\d+/){|s| 2**s.to_i }
==>"foo633825300114114700748351602688bar"
In Forth?
--
Goyim were born only to serve us. Without that, they have no place in the
world---only to serve the People of Israel.... They will work, they will plow,
they will reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef
https://web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx?id=191782
http://archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsdwjezqi.ogv
[toc] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2017-05-19 00:16 -0400 |
| Message-ID | <oflrbl$8ob$3@dont-email.me> |
| In reply to | #59524 |
On 5/18/2017 11:44 PM, Robert L. wrote:
> "foo99bar".sub(/\d+/){|s| s.to_i + 1}
> ==>"foo100bar"
>
> "foo99bar".sub(/\d+/){|s| 2**s.to_i }
> ==>"foo633825300114114700748351602688bar"
>
> In Forth?
If this is doing what I think it is doing, I wrote that in an Excel
formula... lol
=CONCATENATE(LEFT(M84,7),TEXT(1+NUMBERVALUE(MID(M84,8,3)),"000"),"A")
Turns "16N048-033A" into "16N048-034A"
Silly rabbit!
--
Rick C
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2017-05-18 21:47 -0700 |
| Message-ID | <ddcd9980-4646-4e90-aa96-78dc4b87ae28@googlegroups.com> |
| In reply to | #59525 |
On Thursday, May 18, 2017 at 11:16:02 PM UTC-5, rickman wrote:
> On 5/18/2017 11:44 PM, Robert L. wrote:
> > "foo99bar".sub(/\d+/){|s| s.to_i + 1}
> > ==>"foo100bar"
> >
> > "foo99bar".sub(/\d+/){|s| 2**s.to_i }
> > ==>"foo633825300114114700748351602688bar"
> >
> > In Forth?
>
> If this is doing what I think it is doing, I wrote that in an Excel
> formula... lol
>
> =CONCATENATE(LEFT(M84,7),TEXT(1+NUMBERVALUE(MID(M84,8,3)),"000"),"A")
>
> Turns "16N048-033A" into "16N048-034A"
>
Robert's code affects only the first sequence of consecutive digits in
the string. So it would turn "16N048-033A" into "17N048-033A".
The Rosetta Code task just says "numerical string", though, without
specifying how non-digits should be considered.
That Excel formula is awfully specific though. It's not any harder to
be that specific in Forth:
12 buffer: label
s" 16N048-033A" label place
: excel ( -- )
0. label 8 + 3 >number 2drop drop 1+
0 <# # # # #> label 8 + swap move ;
: go 10 0 do cr label count type excel loop ;
Outputs:
16N048-033A
16N048-034A
16N048-035A
16N048-036A
16N048-037A
16N048-038A
16N048-039A
16N048-040A
16N048-041A
16N048-042A
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2017-05-19 01:24 -0400 |
| Message-ID | <oflvc0$ir2$1@dont-email.me> |
| In reply to | #59527 |
On 5/19/2017 12:47 AM, Julian Fondren wrote:
> On Thursday, May 18, 2017 at 11:16:02 PM UTC-5, rickman wrote:
>> On 5/18/2017 11:44 PM, Robert L. wrote:
>>> "foo99bar".sub(/\d+/){|s| s.to_i + 1}
>>> ==>"foo100bar"
>>>
>>> "foo99bar".sub(/\d+/){|s| 2**s.to_i }
>>> ==>"foo633825300114114700748351602688bar"
>>>
>>> In Forth?
>>
>> If this is doing what I think it is doing, I wrote that in an Excel
>> formula... lol
>>
>> =CONCATENATE(LEFT(M84,7),TEXT(1+NUMBERVALUE(MID(M84,8,3)),"000"),"A")
>>
>> Turns "16N048-033A" into "16N048-034A"
>>
>
> Robert's code affects only the first sequence of consecutive digits in
> the string. So it would turn "16N048-033A" into "17N048-033A".
>
> The Rosetta Code task just says "numerical string", though, without
> specifying how non-digits should be considered.
>
> That Excel formula is awfully specific though. It's not any harder to
> be that specific in Forth:
>
> 12 buffer: label
> s" 16N048-033A" label place
>
> : excel ( -- )
> 0. label 8 + 3 >number 2drop drop 1+
> 0 <# # # # #> label 8 + swap move ;
>
> : go 10 0 do cr label count type excel loop ;
>
> Outputs:
>
> 16N048-033A
> 16N048-034A
> 16N048-035A
> 16N048-036A
> 16N048-037A
> 16N048-038A
> 16N048-039A
> 16N048-040A
> 16N048-041A
> 16N048-042A
Yeah, I wasn't trying to do the Rosetta task. This is something I wrote
some time ago to generate invoice numbers in a tracking spread sheet.
--
Rick C
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web