Jump to content

Numbers whose binary and ternary digit sums are prime: Difference between revisions

add tinybasic
(add gwbasic)
(add tinybasic)
Line 1,352:
[5, 6, 7, 10, 11, 12, 13, 17, 18, 19, 21, 25, 28, 31, 33, 35, 36, 37, 41, 47, 49, 55, 59, 61, 65, 67, 69, 73, 79, 82, 84, 87, 91, 93, 97, 103, 107, 109, 115, 117, 121, 127, 129, 131, 133, 137, 143, 145, 151, 155, 157, 162, 167, 171, 173, 179, 181, 185, 191, 193, 199]
</pre>
 
=={{header|Tiny BASIC}}==
This isn't a very interesting problem. The most illustrative part of this solution is that it only uses four variables; several have multiple purposes. Efficiency is important when the language has only 26 variable names in total.
 
<lang tinybasic> REM B digital base input to sumdig, also output of primality routine
REM N input to sumdig routine
REM P input to primality routine, output of sumdig routine
REM T temp variable in sumdig routine, loop var in prime routine
LET N = 1
20 LET N = N + 1
LET B = 2
GOSUB 200
GOSUB 100
IF B = 0 THEN GOTO 30
LET B = 3
GOSUB 200
GOSUB 100
IF B = 1 THEN PRINT N
30 IF N < 200 THEN GOTO 20
END
 
100 REM PRIMALITY BY TRIAL DIVISION
LET B = 0
IF P = 1 THEN RETURN
LET B = 1
IF P = 2 THEN RETURN
LET T = 2
110 IF (P/T)*T = P THEN LET B = 0
IF B = 0 THEN RETURN
LET T = T + 1
IF T*T <= P THEN GOTO 110
RETURN
 
200 REM digital sum of N in base B
LET T = N
LET P = 0
210 IF T = 0 THEN RETURN
LET P = P + T - (T/B)*B
LET T = T/B
GOTO 210 </lang>
 
=={{header|Wren}}==
781

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.