Author Topic: help my  (Read 19280 times)

0 Members and 1 Guest are viewing this topic.

Offline Kiara87

  • Forum Regular
  • Posts: 164
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #31 on: July 01, 2020, 08:34:39 pm »
So exactly 30 or 60

89 - 30 = 59 red
59 - 30 = 29 red

12 + 30 = 42 red
42 + 30 = 72 red

but this is head scratcher (see attachment)
  [ You are not allowed to view this attachment ]  

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #32 on: July 02, 2020, 01:08:58 am »
example
29 89

it is always distance 30
in this game the numbers reach 90
exaple
29 89        89+30=119-90=29  <---- when it exceeds 90   -do the minus 90

in practice always a distance 30 because if the sum exceeds 90 then it subtracts 90

88 +30= 118    118-90= 28

28+30 =58

58+30=88

28-30=88  because the numbers reach 90 


se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #33 on: July 02, 2020, 10:11:31 am »
Hi @Kiara87

So no 60's but new math on 30's. Why wasn't the 90 - 60 = 30 shaded in the screenshot I showed and blue circled, because don't check 90? only numbers less than 90?

OK this can be done now that I've leaned the new math 79 + 30 = 109 - 90 = 19 ha! ;-)

And we need to check down the whole column that one line in the data file makes.

We could make things easy on ourselves by loading a into an array with rows and columns just like the print out.

Starting at MID$(a, 5, 2) I think, every 2 digits is new number, 5 numbers make a row so the next row of numbers after 5 starts at 15 and the next starts at 25 and the next starts at 35... positions in the "a" string I am talking about.

How many rows in one line from the file? nRows = (len(a) - 4) /10 it's a constant for the DAT file we use, the first 4 digits are identifiers to line I suppose those should go in a separate array or just read off "a" when we need them.

DIM lineDAT(1 to 5, 1 to nRows) as INTEGER  'an  array to load from each line from DAT

rowCnt = 0 : x = 1 : y = 1
for i = 5 to len(a) step 2
    d = val(mid$(a, i, 2)) 'convert data item to iteger
    rowCnt = rowCnt + 1 ' increase column if at 6 start new row
    if rowCnt = 6 then x = 1 : y = y + 1
    lineDAT(x, y) = d
next

The above is NOT in code box because it is not tested in QB64.
 
That loads our line data array and it makes it easy to sweep through array and make red the items that are 30 from each other.

I would just print the array as white and then print the 30's red after a sweep the array check for 30's.

Before starting an 2D array for line data I would start an array for the file data and load whole file into array.
This is standard way to approach data from a file, load the file into an array in programs working memory it is way more efficient to process file data from some sort of array.

So next step is to do that, load the file data into an array of strings and we already know the amount of lines 480

Dim FileDAT(1 to 480) as STRING
Open File for input
for i = 1 to 480
   Get a line of data from file
   and set FileDAT(i) = to it
next i

'array loaded with data from file

' next use the the code we wrote to get a line number only this time we will get it from the array instead of the file

Let's see how far along you can get with that. Get the lines from the array and printout the screen of data.
Then we will work on scanning down the columns for 30's, the code above is start of that. We should also have to write a FUNCTION for your new math with 30s. ;-)

OK?

Oh, once we know what lineNum to get from key presses we just set a = LineDAT(lineNum) simple!
And now we can get any lineNum we want, we don't have to just go up and down the file for a data line.

   
« Last Edit: July 02, 2020, 10:20:19 am by bplus »

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #34 on: July 02, 2020, 10:52:26 am »
I also put the images that color all the numbers in green
I changed color I thought it was the fault of the color
on the other hand, even green makes tantrums
https://imgur.com/IHBBzi4
https://imgur.com/l8r0Zx0
https://imgur.com/gNsecam
https://imgur.com/OPApefR
I only tried with an if condition

with only one condition  if
it works

the problem if I put only one condition I only check two numbers
other problem is when he finds the condition he colors all the numbers

while I wanted to color only the two of the found condition

Code: QB64: [Select]
  1. OPTION _EXPLICIT 'for typo's   yep lineMun blah!
  2.  
  3. DIM a AS STRING, count AS INTEGER, lineNum AS INTEGER, Q$, num AS INTEGER
  4. 'count lines in file
  5. OPEN "lotto.dat" FOR INPUT AS #1
  6.     INPUT #1, a
  7.     'PRINT a
  8.     'INPUT " OK enter "; w$
  9.     IF LEN(_TRIM$(a)) THEN count = count + 1
  10. 'CLS: PRINT count '480 lines
  11. 'END
  12. 'CLS
  13.  
  14. LOCATE 1, 1
  15. PRINT "BARI"
  16. LOCATE 3, 1
  17. PRINT "CAGLIARI"
  18. LOCATE 5, 1
  19. PRINT "FIRENZE"
  20. LOCATE 7, 1
  21. PRINT "GENOVA"
  22. LOCATE 9, 1
  23. PRINT "MILANO"
  24. LOCATE 11, 1
  25. PRINT "NAPOLI"
  26. LOCATE 13, 1
  27. PRINT "PALERMO"
  28. LOCATE 15, 1
  29. PRINT "ROMA"
  30. LOCATE 17, 1
  31. PRINT "TORINO"
  32. LOCATE 19, 1
  33. PRINT "VENEZIA"
  34. LOCATE 21, 1
  35. PRINT "NAZIONALE"
  36.  
  37.  
  38. LOCATE 23, 1: COLOR 4
  39. PRINT " + to move on"
  40. LOCATE 23, 16: COLOR 3
  41. PRINT "- to back"
  42.  
  43. lineNum = 1
  44. GOSUB get_a
  45.  
  46.  
  47.     a$ = "12345678901234567890"
  48.     i = INSTR(a$, "12345678901234567890")
  49.     Q$ = INKEY$
  50.     IF Q$ = "+" THEN lineNum = lineNum + 1
  51.     IF lineNum > count THEN lineNum = 1
  52.  
  53.     IF Q$ = "-" THEN lineNum = lineNum - 1
  54.     IF lineNum < 1 THEN lineNum = count
  55.  
  56.     GOSUB get_a
  57.  
  58.  
  59.     LOCATE 1, 34
  60.     PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum)
  61.  
  62.     REM CONDIZIONE IF V OR F
  63.  
  64.      IF ABS(VAL(MID$(a$, 15, 2)) - VAL(MID$(a$, 45, 2))) = 30 THEN COLOR 10 ELSE COLOR 15
  65.  
  66.  
  67.     REM bari
  68.     LOCATE 1, 13
  69.     PRINT VAL(MID$(a, 5, 2))
  70.     LOCATE 1, 16
  71.     PRINT VAL(MID$(a, 7, 2))
  72.     LOCATE 1, 19
  73.     PRINT VAL(MID$(a, 9, 2))
  74.     LOCATE 1, 22
  75.     PRINT VAL(MID$(a, 11, 2))
  76.     LOCATE 1, 25
  77.     PRINT VAL(MID$(a, 13, 2))
  78.  
  79.     REM cagliari
  80.     LOCATE 3, 13
  81.     PRINT VAL(MID$(a, 15, 2))
  82.     LOCATE 3, 16
  83.     PRINT VAL(MID$(a, 17, 2))
  84.     LOCATE 3, 19
  85.     PRINT VAL(MID$(a, 19, 2))
  86.     LOCATE 3, 22
  87.     PRINT VAL(MID$(a, 21, 2))
  88.     LOCATE 3, 25
  89.     PRINT VAL(MID$(a, 23, 2))
  90.  
  91.     REM firenze
  92.     LOCATE 5, 13
  93.     PRINT VAL(MID$(a, 25, 2))
  94.     LOCATE 5, 16
  95.     PRINT VAL(MID$(a, 27, 2))
  96.     LOCATE 5, 19
  97.     PRINT VAL(MID$(a, 29, 2))
  98.     LOCATE 5, 22
  99.     PRINT VAL(MID$(a, 31, 2))
  100.     LOCATE 5, 25
  101.     PRINT VAL(MID$(a, 33, 2))
  102.  
  103.     REM genova
  104.     LOCATE 7, 13
  105.     PRINT VAL(MID$(a, 35, 2))
  106.     LOCATE 7, 16
  107.     PRINT VAL(MID$(a, 37, 2))
  108.     LOCATE 7, 19
  109.     PRINT VAL(MID$(a, 39, 2))
  110.     LOCATE 7, 22
  111.     PRINT VAL(MID$(a, 41, 2))
  112.     LOCATE 7, 25
  113.     PRINT VAL(MID$(a, 43, 2))
  114.  
  115.     REM milano
  116.     LOCATE 9, 13
  117.     PRINT VAL(MID$(a, 45, 2))
  118.     LOCATE 9, 16
  119.     PRINT VAL(MID$(a, 47, 2))
  120.     LOCATE 9, 19
  121.     PRINT VAL(MID$(a, 49, 2))
  122.     LOCATE 9, 22
  123.     PRINT VAL(MID$(a, 51, 2))
  124.     LOCATE 9, 25
  125.     PRINT VAL(MID$(a, 53, 2))
  126.  
  127.     REM napoli
  128.     LOCATE 11, 13
  129.     PRINT VAL(MID$(a, 55, 2))
  130.     LOCATE 11, 16
  131.     PRINT VAL(MID$(a, 57, 2))
  132.     LOCATE 11, 19
  133.     PRINT VAL(MID$(a, 59, 2))
  134.     LOCATE 11, 22
  135.     PRINT VAL(MID$(a, 61, 2))
  136.     LOCATE 11, 25
  137.     PRINT VAL(MID$(a, 63, 2))
  138.  
  139.     REM palermo
  140.     LOCATE 13, 13
  141.     PRINT VAL(MID$(a, 65, 2))
  142.     LOCATE 13, 16
  143.     PRINT VAL(MID$(a, 67, 2))
  144.     LOCATE 13, 19
  145.     PRINT VAL(MID$(a, 69, 2))
  146.     LOCATE 13, 22
  147.     PRINT VAL(MID$(a, 71, 2))
  148.     LOCATE 13, 25
  149.     PRINT VAL(MID$(a, 73, 2))
  150.  
  151.     REM roma
  152.     LOCATE 15, 13
  153.     PRINT VAL(MID$(a, 75, 2))
  154.     LOCATE 15, 16
  155.     PRINT VAL(MID$(a, 77, 2))
  156.     LOCATE 15, 19
  157.     PRINT VAL(MID$(a, 79, 2))
  158.     LOCATE 15, 22
  159.     PRINT VAL(MID$(a, 81, 2))
  160.     LOCATE 15, 25
  161.     PRINT VAL(MID$(a, 83, 2))
  162.  
  163.     REM torino
  164.     LOCATE 17, 13
  165.     PRINT VAL(MID$(a, 85, 2))
  166.     LOCATE 17, 16
  167.     PRINT VAL(MID$(a, 87, 2))
  168.     LOCATE 17, 19
  169.     PRINT VAL(MID$(a, 89, 2))
  170.     LOCATE 17, 22
  171.     PRINT VAL(MID$(a, 91, 2))
  172.     LOCATE 17, 25
  173.     PRINT VAL(MID$(a, 93, 2))
  174.  
  175.     REM venezia
  176.     LOCATE 19, 13
  177.     PRINT VAL(MID$(a, 95, 2))
  178.     LOCATE 19, 16
  179.     PRINT VAL(MID$(a, 97, 2))
  180.     LOCATE 19, 19
  181.     PRINT VAL(MID$(a, 99, 2))
  182.     LOCATE 19, 22
  183.     PRINT VAL(MID$(a, 101, 2))
  184.     LOCATE 19, 25
  185.     PRINT VAL(MID$(a, 103, 2))
  186.  
  187.     REM nazionale
  188.     LOCATE 21, 13
  189.     PRINT VAL(MID$(a, 105, 2))
  190.     LOCATE 21, 16
  191.     PRINT VAL(MID$(a, 107, 2))
  192.     LOCATE 21, 19
  193.     PRINT VAL(MID$(a, 109, 2))
  194.     LOCATE 21, 22
  195.     PRINT VAL(MID$(a, 111, 2))
  196.     LOCATE 21, 25
  197.     PRINT VAL(MID$(a, 113, 2))
  198.  
  199.     _LIMIT 30
  200.  
  201.  
  202. 'this sub retrieves a line number from file  the hard way
  203. get_a:
  204. num = 0
  205. OPEN "lotto.dat" FOR INPUT AS #1
  206.     INPUT #1, a
  207.     IF LEN(_TRIM$(a)) THEN num = num + 1
  208.     IF num = lineNum THEN EXIT WHILE 'a is set on line we want
  209.  
  210.  
  211.  
  212.  
  213.  
« Last Edit: July 02, 2020, 11:07:22 am by Kiara87 »
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #35 on: July 02, 2020, 11:28:11 am »
@Kiara87

Right, once you set color it won't unset unless you tell it to go back.
That's why I advise print the whole thing in white first and then go back and shade/color only the 30's.

Please read carefully my long post before your last. I will guide you to perfect app AND you will learn a little about arrays and subroutines, if you can hang in there. :) this is kind of accelerated learning of BASIC.

On a 2nd front, I am working on a 30's FUNCTION such that given 2 numbers, it will say if there is a 30 diff = -1 or NOT = 0

(-1 = True there is a diff (=difference) of 30, 0 = False there is not a difference of 30).

But I need a ruling on 90:

90 - 30 = 60 so shade 90 and 60 combo, right?

90 + 30 = 120 - 90 = 30 so shade 90 and 30 combo right?

Also no numbers should be 0, correct?
 
And 90 IS the maximum number, correct?



« Last Edit: July 02, 2020, 11:42:02 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #36 on: July 02, 2020, 12:41:05 pm »
@Kiara87

I have written a function to test 30 distance between 2 numbers from 1 to 90.

It returns -1 when the numbers are 30 apart and 0 if they are NOT.

Can you find 2 numbers when this returns the wrong answer?

Code: QB64: [Select]
  1. DEFINT A-Z
  2. _TITLE "Kiara87 diff30in90 function test" 'b+ 2020-07-02 this checks out for every example kiara87 has provided
  3.  
  4. ' interesting challenge numbers from 1 to 90 need to mark special if one number is 30 off the 2nd
  5.  
  6. 1 DO
  7.     CLS
  8.     INPUT "Please enter number (1 to 90) to check if 30 off (of 90) of another number "; n1
  9.     IF n1 > 90 THEN BEEP: GOTO 1
  10.     INPUT "Please enter 2nd number (1 to 90) for check "; n2
  11.     IF n2 > 90 THEN BEEP: GOTO 1
  12.     PRINT "diff30in90("; n1; ","; n2; ") FUNCTION returned:"; diff30in90(n1, n2)
  13.     _DELAY 4
  14. LOOP UNTIL n1 = 0 OR n2 = 0
  15.  
  16. FUNCTION diff30in90 (a, b) 'default integers a-z
  17.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  18.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  19.     IF hi - lo = 30 THEN
  20.         diff30in90 = -1
  21.     ELSE
  22.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  23.     END IF

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #37 on: July 02, 2020, 03:01:56 pm »
hello bplus

yes the program returns perfect when from -1 the answer is right
if return 0

the answer is wrong

so your instructions work

I had read in the post what you wrote but I didn't understand everything well because I don't speak English well
now I will try to do it as you said with array
I am a beginner who is learning

and I also thank you for being a good teacher

pity that I cannot understand the English language

I use the google translator

thank you very much bplus
Code: QB64: [Select]
  1. DEFINT A-Z
  2. _TITLE "Kiara87 diff30in90 function test" 'b+ 2020-07-02 this checks out for every example kiara87 has provided
  3.  
  4. ' interesting challenge numbers from 1 to 90 need to mark special if one number is 30 off the 2nd
  5.  
  6. 1 DO
  7.     CLS
  8.     INPUT "Please enter number (1 to 90) to check if 30 off (of 90) of another number "; n1
  9.     IF n1 > 90 THEN BEEP: GOTO 1
  10.     INPUT "Please enter 2nd number (1 to 90) for check "; n2
  11.     IF n2 > 90 THEN BEEP: GOTO 1
  12.     PRINT "diff30in90("; n1; ","; n2; ") FUNCTION returned:"; diff30in90(n1, n2)
  13.     _DELAY 4
  14. LOOP UNTIL n1 = 0 OR n2 = 0
  15.  
  16. FUNCTION diff30in90 (a, b) 'default integers a-z
  17.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  18.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  19.     IF hi - lo = 30 THEN
  20.         diff30in90 = -1
  21.     ELSE
  22.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  23.     END IF
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #38 on: July 02, 2020, 03:15:33 pm »
@Kiara87

Thanks for confirmation, certification and validation of my function. I have already proceeded as if I were correct. ;-))

Quote
pity that I cannot understand the English language
Well that makes 2 of us!

I am working ahead, so I can show you light at the end of the tunnel.

My current task is reducing all those locate and  print lines to simple formula, so we don't have to type so much. ;-)

To be good programmer hate to type repetitive stuff!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #39 on: July 02, 2020, 03:19:12 pm »
Did I leave enough help for loading the file into an array?

Should we talk more about arrays?

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #40 on: July 02, 2020, 04:01:10 pm »
Did I leave enough help for loading the file into an array?

Should we talk more about arrays?

I'm trying to understand how an array works but the tutorials are in English

I know a bit of instructions but the arrays I hadn't studied

did I understand that you don't speak English well?
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #41 on: July 02, 2020, 04:36:42 pm »
Quote
did I understand that you don't speak English well?

Yes, but I was making a joke because English is my only language.

If you tell me your language I will use Bing to translate some of my words to yours (hopefully) and I might learn something too.

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #42 on: July 02, 2020, 04:42:46 pm »
Yes, but I was making a joke because English is my only language.

If you tell me your language I will use Bing to translate some of my words to yours (hopefully) and I might learn something too.

I am Italian I speak and I can speak only Italian too much
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #43 on: July 02, 2020, 05:27:52 pm »
Code: QB64: [Select]
  1. _TITLE "#1 della lezione di matrice" 'Array lesson #1   b+ 2020-07-02
  2.  
  3. 'Riempire una matrice con numeri da 1 a 20
  4. 'Caricare un array con numeri da 1 a 20
  5. ' Fill = Riempire   Caricare = Load an array with numbers from 1 to 20
  6.  
  7. DIM ilMioArray(1 TO 20)
  8.  
  9. FOR i = 1 TO 20 ' i = indice
  10.     ilMioArray(i) = i
  11.  
  12. PRINT "visualizzare il mio array all'indietro     'show me the array backwards"
  13. FOR i = 20 TO 1 STEP -1
  14.     PRINT ilMioArray(i)
  15. PRINT "premere un tasto qualsiasi per continuare...  press any key to continue... "
  16.  
  17. PRINT "modificare il contenuto della mia matrice  'modify my array contents"
  18. FOR i = 20 TO 1 STEP -1
  19.     ilMioArray(i) = ilMioArray(i) ^ 2 + 1 ' al quadrato piu (+) 1   'squared plus 1
  20.  
  21. GOSUB visualizzare:
  22.  
  23. END ''''''''''''''''' don't go past here   'non andare passato qui
  24.  
  25. visualizzare:
  26. PRINT "visualizzare  'display"
  27. FOR i = 1 TO 20
  28.     PRINT "i ="; i; ", "; ilMioArray(i)
  29. PRINT "premere un tasto qualsiasi per continuare...  press any key to continue... "
  30.  
  31.  

The next step is loading a file into an array.
Il passaggio successivo consiste nel caricamento di un file in una matrice.

Want to give it a try?
Vuoi fare un tentativo?
« Last Edit: July 02, 2020, 05:33:45 pm by bplus »

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #44 on: July 02, 2020, 06:39:30 pm »
https://imgur.com/yW5dIS6
another question

those on the right in the image what are they?

an array would be a variable containing more content

only variable that can hold multiple values

contained in the same variable
miaArray(i) = i

can I contain how many contents? is there a limit?

later you said to load a file into an array

how can i upload it?

example variabile a 100
Code: QB64: [Select]
  1. _TITLE "#1 della lezione di matrice" 'Array lesson #1   b+ 2020-07-02
  2.  
  3. 'Riempire una matrice con numeri da 1 a 20
  4. 'Caricare un array con numeri da 1 a 20
  5. ' Fill = Riempire   Caricare = Load an array with numbers from 1 to 20
  6.  
  7. DIM ilMioArray(1 TO 20)
  8.  
  9. FOR i = 1 TO 20 ' i = indice
  10.     ilMioArray(i) = i
  11.  
  12. PRINT "visualizzare il mio array all'indietro     'show me the array backwards"
  13. FOR i = 20 TO 1 STEP -1
  14.     PRINT ilMioArray(i)
  15. PRINT "premere un tasto qualsiasi per continuare...  press any key to continue... "
  16.  
  17. PRINT "modificare il contenuto della mia matrice  'modify my array contents"
  18. FOR i = 20 TO 1 STEP -1
  19.     ilMioArray(i) = ilMioArray(i) ^ 2 + 1 ' al quadrato piu (+) 1   'squared plus 1
  20.  
  21. GOSUB visualizzare:
  22.  
  23. END ''''''''''''''''' don't go past here   'non andare passato qui
  24.  
  25. visualizzare:
  26. PRINT "visualizzare  'display"
  27. FOR i = 1 TO 20
  28.     PRINT "i ="; i; ", "; ilMioArray(i)
  29. PRINT "premere un tasto qualsiasi per continuare...  press any key to continue... "
  30.  
  31.  

The next step is loading a file into an array.
Il passaggio successivo consiste nel caricamento di un file in una matrice.

Want to give it a try?
Vuoi fare un tentativo?
« Last Edit: July 02, 2020, 06:47:03 pm by Kiara87 »
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione