FreeBASIC syntax challenge games
Re: FreeBASIC syntax challenge games
Where are these unresolved enigmas?
Re: FreeBASIC syntax challenge games
The one line solution for:
and tourist trap's :
http://www.freebasic.net/forum/viewtopi ... 84#p227584
Code: Select all
Type UDT
Public:
Dim As Integer array(20) = {15,12,8,5,3,19,18,6,10,2,13,9,1,20,0,14,7,17,4,11,16}
Private:
Declare Operator Let (Byref As UDT)
End Type
Dim As UDT u
For I As Integer = 0 To 20
Print u.array(I),
Next I
Print
Print
For I As Integer = 0 To 20
u.array(I) = 0
Print u.array(I),
Next I
Print
Print
'------------------------------------------------------------------------------------
'u = UDT() '' error 201: Illegal member access, UDT.operator.let
'u.Constructor()
'swap u,*(new udt) 'My attempt
'some other way
'------------------------------------------------------------------------------------
For I As Integer = 0 To 20
Print u.array(I),
Next I
Print
Sleep
http://www.freebasic.net/forum/viewtopi ... 84#p227584
Re: FreeBASIC syntax challenge games
I don't understand:dodicat wrote:The one line solution for:Code: Select all
Type UDT Public: Dim As Integer array(20) = {15,12,8,5,3,19,18,6,10,2,13,9,1,20,0,14,7,17,4,11,16} Private: Declare Operator Let (Byref As UDT) End Type Dim As UDT u For I As Integer = 0 To 20 Print u.array(I), Next I Print Print For I As Integer = 0 To 20 u.array(I) = 0 Print u.array(I), Next I Print Print '------------------------------------------------------------------------------------ 'u = UDT() '' error 201: Illegal member access, UDT.operator.let 'u.Constructor() 'swap u,*(new udt) 'My attempt 'some other way '------------------------------------------------------------------------------------ For I As Integer = 0 To 20 Print u.array(I), Next I Print Sleep
- My one line solution:
Code: Select all
'------------------------------------------------------------------------------------
'u = UDT() '' error 201: Illegal member access, UDT.operator.let
u.Constructor()
'------------------------------------------------------------------------------------
Code: Select all
'------------------------------------------------------------------------------------
'u = UDT() '' error 201: Illegal member access, UDT.operator.let
swap u,*(new udt) 'My attempt
'------------------------------------------------------------------------------------
Re: FreeBASIC syntax challenge games
Solution in one single instruction or one single keyword ?Tourist Trap wrote:Alternatively, for the puppies I've one enigma if you allow me to post it. It may be recreational.
Puppy Enigma
Find a way to print the low cased version of the first letter of a uppercased sentence in one single instruction (the whole program is one single instruction, but adding a pause with SLEEP is allowed).
The sentence could be:Program output:Code: Select all
HAPPY NEW YEAR PUPPIES!
Code: Select all
h
(anyway, I'm offside for this enigma !)
Re: FreeBASIC syntax challenge games
regarding the udt array, maybe I am mistaken, I thought there was another way not using new.
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: FreeBASIC syntax challenge games
Single instruction! You can use LCASE of course, even if not necessary.fxm wrote: Solution in one single instruction or one single keyword ?
(anyway, I'm offside for this enigma !)
This is quite easy indeed, just working from the static string directly (no dim required then) and extracting the material from it. Only parenthesis are delicate to handle, in both of the 2 solutions I have.
Re: FreeBASIC syntax challenge games
Could the above challenge be to find the shorter one code line:
The upper-cased sentence can start with spaces and / or non-alphabetic characters, and the goal is to process the first alphabetic character of the sentence!
For example:Output must be "h".
My own score = 57 !
As for me, to let you rest a little, I would still propose some enigmas but much easier than my lasts.
- Each gives only his score (length of the line in characters).
(string being referenced by 's')
The upper-cased sentence can start with spaces and / or non-alphabetic characters, and the goal is to process the first alphabetic character of the sentence!
For example:
Code: Select all
Dim As String s = " *** HAPPY NEW YEAR PUPPIES! *** "
My own score = 57 !
As for me, to let you rest a little, I would still propose some enigmas but much easier than my lasts.
Re: FreeBASIC syntax challenge games
I am not sure about the rules but:
So it is the string + 14 characters.
Code: Select all
?chr(asc("HAPPY NEW YEAR PUPPIES!")+32)
sleep
Re: FreeBASIC syntax challenge games
With your lower-casing method, I improve my score (with my rules) to 54 (including the string name 's')!
Re: FreeBASIC syntax challenge games
For the string by fxm (not a general string, but the one given):
If a general string is given, is it strictly Uppercase or Mixed case with random padding at each end (no alphabet characters in the padding)?
Code: Select all
?chr((" *** HAPPY NEW YEAR PUPPIES! *** ")[9]+32)
sleep
Re: FreeBASIC syntax challenge games
My rules:
- No alphabetic characters in the padding.
- Any character in the useful string, but always starting with an alphabetic character.
Mixed case in the useful string: my score = 57
Only upper case in the useful string: my score = 54
- No alphabetic characters in the padding.
- Any character in the useful string, but always starting with an alphabetic character.
Mixed case in the useful string: my score = 57
Only upper case in the useful string: my score = 54
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: FreeBASIC syntax challenge games
Yes those solutions are very excellent! I didn't know that ASC would retain the first element of a string, or that a string with parenthesis would be evaluated in order to allow deferencing!
That's why I thought of a little more tricky, but equivalent:
Sorry I missed the new rules, what is the sentence so ? "happy new year puppies" ?
That's why I thought of a little more tricky, but equivalent:
Code: Select all
? lCase ( chr( ((@"HELLO PUPPIES!")[0]) [0]) )
? lCase ( chr((cast(zstring ptr, @"HELLO PUPPIES!")[0])[0]) )
Re: FreeBASIC syntax challenge games
More simply:
Code: Select all
? lCase ( chr( s[0] ) )
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: FreeBASIC syntax challenge games
In a macro, the parenthesis version makes apparently more sense. It's important because it doesn't work otherwise.fxm wrote:More simply:Code: Select all
? lCase ( chr( s[0] ) )
Code: Select all
#define H(e) lcase( chr( (e)[0] ) )
? H("Hello Puppies!")
Re: FreeBASIC syntax challenge games
Code: Select all
' Rules for the string 's':
' - In the padding : no alphabetic characters
' - In the useful string part : any character but always starting with an alphabetic character
Dim As String s = " *** HAPPY NEW YEAR PUPPIES! *** "
?Lcase(Mid(s,Instr(s,Any"ABCDEFGHIJKLMNOPQRSTUVWXYZ"),1)) '' works with mixed case characters in the useful string part
?Chr(s[Instr(s,Any"ABCDEFGHIJKLMNOPQRSTUVWXYZ")-1]+32) '' works only with upper case characters in the useful string part
Sleep