Other April fools quite difficult and a bit unfair quiz

Erel

B4X founder
Staff member
Licensed User
Longtime User
PI7jrPEBiD.gif


code:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private Button1 As B4XView
    Private TextField1 As B4XView
    Private TextField2 As B4XView
    Private lblResult As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim r As Reflector
#region Secret
 '3 lines here...................................
#end region

End Sub


Sub Button1_Click
    Dim FirstNumber As Int = TextField1.Text
    Dim SecondNumber As Int = TextField2.Text
    lblResult.Text = SumInts (Array(FirstNumber, SecondNumber))
End Sub

Sub SumInts (Ints As List) As Int
    Dim sum As Int = 0
    For Each i As Int In Ints
        sum = sum + i
    Next
    Return sum
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
    #region Secret
    Do While True
        If IsNumber(lblResult.Text) Then
            If 10<lblResult.Text Then
                Dim Val1 As Int = Min(TextField1.Text,TextField2.Text)
                Dim Val2 As Int = Max(TextField1.Text,TextField2.Text)
            
                Val2=(Val2 Mod 10)-Floor(Val2/10)
                lblResult.Text=(Val1+Val2)
            End If
        End If
        Sleep(0)
    Loop
    #end region

ezgif.com-video-to-gif.gif
 

Attachments

  • test.zip
    2.4 KB · Views: 142
Last edited:
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I have no idea how to do it with code, but it seems to me...
...that some reflector magic is modifying the second element in the input array to SumInts so that it's mod 11.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Hmm! It seems to be doing something naughty with reflection but I don't think its related to intercepting the click event as the second example logs the output of SumInts directly in the click event so it seems to be modifying either the parameter list values or the return value of Sub SumInts somehow. Moreover it's doing it permanently with only three lines of code run once only.

I don't think it's Mod 11 as the second example has no numeric values in the TextFields.

I wrote the jReflection library but have no idea what's going on here o_O I shall ponder further after a fortifying lunch.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I don't think it's Mod 11 as the second example has no numeric values in the TextFields.
check the content of the result label
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I only know that Erel, instead of giving us a present for Easter 😄, gave us something to rack our brains.
For now I have too much headache to think about it, I prefer to wait for your solution.
(It could be anything, even intercept and replace the function)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
For now I have too much headache to think about it, I prefer to wait for your solution.
That's the correct approach. As I wrote, it is an unfair quiz. It is unfair because it manipulates something in the underlying Java type system.

Nice solution @Star-Dust but this is not what I did. As you can see in the second example, it is not related to the UI.

Two hints:
1. The first hidden line is:
B4X:
Dim cache() As Object = r.GetStaticField("java.lang.Integer$IntegerCache", "cache")

2. More outputs:
B4X:
Log(SumInts(Array(1, 14)))    '4
Log(SumInts(Array(10, 2)))    '12
Log(SumInts(Array(8, 3)))    '11
Log(SumInts(Array(14, 2)))    '5
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
In that case I'd like to adjust my guess to...
...all integers are mod 11. (Made via IntegerCache, which I have no clue to what it is. Probably some sort of cache for integers. :) )
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
In that case I'd like to adjust my guess to...
...all integers are mod 11. (Made via IntegerCache, which I have no clue to what it is. Probably some sort of cache for integers. :) )
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
.all integers are mod 11.
Could be so
This seems to give the 'expected' results when logged as in the second example but messes up the numeric characters in the UI so it is not the whole answer. It's too many lines as well :(
B4X:
    #region Secret
    Dim r As Reflector 
    Dim cache() As Object = r.GetStaticField("java.lang.Integer$IntegerCache", "cache")
    For i = 0 To cache.Length -1
        Dim j As Int = cache(i) Mod 11
        cache(i) = j
    Next 
    #end region
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Could be so
This seems to give the 'expected' results when logged as in the second example but messes up the numeric characters in the UI so it is not the whole answer. It's too many lines as well :(
B4X:
    #region Secret
    Dim r As Reflector
    Dim cache() As Object = r.GetStaticField("java.lang.Integer$IntegerCache", "cache")
    For i = 0 To cache.Length -1
        Dim j As Int = cache(i) Mod 11
        cache(i) = j
    Next
    #end region
1617283275087.png
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Changing just a subset of integer values outside of the character values range seems to fix the UI problem. Still too many lines of code though!
B4X:
    #region Secret
    Dim r As Reflector  
    Dim cache() As Object = r.GetStaticField("java.lang.Integer$IntegerCache", "cache")
    For i = 107 To 148 'cache.Length -1
        Dim j As Int = cache(i) Mod 11
        cache(i) = j
    Next  
    #end region
 
Upvote 0
Top